Skip to content

Commit

Permalink
Remove VotesERC20 imports from AzoriusTxBuilder, deal with all downst…
Browse files Browse the repository at this point in the history
…ream effects
  • Loading branch information
adamgall committed May 6, 2024
1 parent 9d402b3 commit 1f0e490
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/hooks/DAO/useBuildDAOTx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback } from 'react';
import { usePublicClient } from 'wagmi';
import { TxBuilderFactory } from '../../models/TxBuilderFactory';
import { useFractal } from '../../providers/App/AppProvider';
import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider';
Expand Down Expand Up @@ -27,6 +28,7 @@ const useBuildDAOTx = () => {
governance,
governanceContracts: { erc721LinearVotingContractAddress },
} = useFractal();
const publicClient = usePublicClient();

const buildDao = useCallback(
async (
Expand All @@ -36,7 +38,7 @@ const useBuildDAOTx = () => {
) => {
let azoriusContracts: AzoriusContracts | undefined;

if (!user.address || !signerOrProvider || !baseContracts) {
if (!user.address || !signerOrProvider || !baseContracts || !publicClient) {
return;
}
const {
Expand Down Expand Up @@ -102,6 +104,7 @@ const useBuildDAOTx = () => {

const txBuilderFactory = new TxBuilderFactory(
signerOrProvider,
publicClient,
buildrerBaseContracts,
azoriusContracts,
daoData,
Expand Down Expand Up @@ -148,6 +151,7 @@ const useBuildDAOTx = () => {
[
user.address,
signerOrProvider,
publicClient,
baseContracts,
erc721LinearVotingContractAddress,
dao,
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/DAO/useDeployAzorius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { getAddress, isHex } from 'viem';
import { usePublicClient } from 'wagmi';
import { DAO_ROUTES } from '../../constants/routes';
import { TxBuilderFactory } from '../../models/TxBuilderFactory';
import { useFractal } from '../../providers/App/AppProvider';
Expand Down Expand Up @@ -32,13 +33,15 @@ const useDeployAzorius = () => {
const { t } = useTranslation(['transaction', 'proposalMetadata']);
const { submitProposal } = useSubmitProposal();
const { canUserCreateProposal } = useCanUserCreateProposal();
const publicClient = usePublicClient();

const deployAzorius = useCallback(
async (
daoData: AzoriusERC20DAO | AzoriusERC721DAO,
shouldSetName?: boolean,
shouldSetSnapshot?: boolean,
) => {
if (!daoAddress || !canUserCreateProposal || !safe || !baseContracts) {
if (!daoAddress || !canUserCreateProposal || !safe || !baseContracts || !publicClient) {
return;
}
const {
Expand Down Expand Up @@ -81,6 +84,7 @@ const useDeployAzorius = () => {

const txBuilderFactory = new TxBuilderFactory(
signerOrProvider,
publicClient,
builderBaseContracts,
azoriusContracts,
daoData,
Expand Down Expand Up @@ -135,6 +139,7 @@ const useDeployAzorius = () => {
},
[
signerOrProvider,
publicClient,
baseContracts,
t,
canUserCreateProposal,
Expand Down
33 changes: 23 additions & 10 deletions src/models/AzoriusTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
LinearERC20Voting__factory,
LinearERC721Voting,
LinearERC721Voting__factory,
VotesERC20,
VotesERC20__factory,
} from '@fractal-framework/fractal-contracts';
import {
getCreate2Address,
Expand All @@ -20,12 +18,15 @@ import {
isAddress,
isHex,
encodeFunctionData,
GetContractReturnType,
PublicClient,
getContract,
} from 'viem';
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, getRandomBytes } from '../helpers';
import { buildContractCall, buildContractCallViem, getRandomBytes } from '../helpers';
import {
BaseContracts,
SafeTransaction,
Expand Down Expand Up @@ -55,7 +56,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
public azoriusContract: Azorius | undefined;
public linearVotingContract: LinearERC20Voting | undefined;
public linearERC721VotingContract: LinearERC721Voting | undefined;
public votesTokenContract: VotesERC20 | undefined;
public votesTokenContract: GetContractReturnType<typeof VotesERC20Abi> | undefined;

private votesERC20WrapperMasterCopyAddress: string;
private votesERC20MasterCopyAddress: string;
Expand All @@ -67,6 +68,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder {

constructor(
signerOrProvider: any,
publicClient: PublicClient,
baseContracts: BaseContracts,
azoriusContracts: AzoriusContracts,
daoData: AzoriusERC20DAO | AzoriusERC721DAO,
Expand All @@ -78,6 +80,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
) {
super(
signerOrProvider,
publicClient,
baseContracts,
azoriusContracts,
daoData,
Expand Down Expand Up @@ -245,9 +248,14 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
}

public buildApproveClaimAllocation() {
if (!this.votesTokenContract) {
return;
}

const azoriusGovernanceDaoData = this.daoData as AzoriusERC20DAO;
return buildContractCall(
this.votesTokenContract!,
return buildContractCallViem(
VotesERC20Abi,
this.votesTokenContract.address,
'approve',
[this.predictedTokenClaimAddress, azoriusGovernanceDaoData.parentAllocationAmount],
0,
Expand Down Expand Up @@ -547,6 +555,10 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
}

private setContracts() {
if (!this.predictedTokenAddress) {
return;
}

const daoData = this.daoData as AzoriusGovernanceDAO;
this.azoriusContract = Azorius__factory.connect(
this.predictedAzoriusAddress!,
Expand All @@ -557,10 +569,11 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
this.predictedStrategyAddress!,
this.signerOrProvider,
);
this.votesTokenContract = VotesERC20__factory.connect(
this.predictedTokenAddress!,
this.signerOrProvider,
);
this.votesTokenContract = getContract({
abi: VotesERC20Abi,
address: this.predictedTokenAddress,
client: this.publicClient,
});
} else if (daoData.votingStrategyType === VotingStrategyType.LINEAR_ERC721) {
this.linearERC721VotingContract = LinearERC721Voting__factory.connect(
this.predictedStrategyAddress!,
Expand Down
4 changes: 4 additions & 0 deletions src/models/BaseTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ethers } from 'ethers';
import { PublicClient } from 'viem';
import {
BaseContracts,
AzoriusContracts,
Expand All @@ -10,6 +11,7 @@ import {

export class BaseTxBuilder {
protected readonly signerOrProvider: ethers.Signer | any;
protected readonly publicClient: PublicClient;
protected readonly baseContracts: BaseContracts;
protected readonly azoriusContracts: AzoriusContracts | undefined;
protected readonly daoData: SafeMultisigDAO | AzoriusERC20DAO | AzoriusERC721DAO | SubDAO;
Expand All @@ -18,13 +20,15 @@ export class BaseTxBuilder {

constructor(
signerOrProvider: ethers.Signer | any,
publicClient: PublicClient,
baseContracts: BaseContracts,
azoriusContracts: AzoriusContracts | undefined,
daoData: SafeMultisigDAO | AzoriusERC20DAO | AzoriusERC721DAO | SubDAO,
parentAddress?: string,
parentTokenAddress?: string,
) {
this.signerOrProvider = signerOrProvider;
this.publicClient = publicClient;
this.baseContracts = baseContracts;
this.daoData = daoData;
this.azoriusContracts = azoriusContracts;
Expand Down
10 changes: 8 additions & 2 deletions src/models/DaoTxBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { zeroAddress } from 'viem';
import { PublicClient, zeroAddress } from 'viem';
import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall, encodeMultiSend } from '../helpers';
import {
Expand Down Expand Up @@ -34,6 +34,7 @@ export class DaoTxBuilder extends BaseTxBuilder {

constructor(
signerOrProvider: ethers.Signer | any,
publicClient: PublicClient,
baseContracts: BaseContracts,
azoriusContracts: AzoriusContracts | undefined,
daoData: SafeMultisigDAO | AzoriusERC20DAO | AzoriusERC721DAO,
Expand All @@ -48,6 +49,7 @@ export class DaoTxBuilder extends BaseTxBuilder {
) {
super(
signerOrProvider,
publicClient,
baseContracts,
azoriusContracts,
daoData,
Expand Down Expand Up @@ -131,9 +133,13 @@ export class DaoTxBuilder extends BaseTxBuilder {
// If subDAO and parentAllocation, deploy claim module
let tokenClaimTx: SafeTransaction | undefined;
const parentAllocation = (this.daoData as AzoriusERC20DAO).parentAllocationAmount;

if (this.parentTokenAddress && parentAllocation && parentAllocation !== 0n) {
tokenClaimTx = azoriusTxBuilder.buildDeployTokenClaim();
const tokenApprovalTx = azoriusTxBuilder.buildApproveClaimAllocation();
if (!tokenApprovalTx) {
throw new Error('buildApproveClaimAllocation returned undefined');
}
tokenClaimTx = azoriusTxBuilder.buildDeployTokenClaim();
this.internalTxs.push(tokenApprovalTx);
}

Expand Down
3 changes: 3 additions & 0 deletions src/models/FreezeGuardTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
encodeAbiParameters,
parseAbiParameters,
isHex,
PublicClient,
} from 'viem';
import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall } from '../helpers';
Expand Down Expand Up @@ -62,6 +63,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder {

constructor(
signerOrProvider: any,
publicClient: PublicClient,
baseContracts: BaseContracts,
daoData: SubDAO,
safeContract: GnosisSafeL2,
Expand All @@ -76,6 +78,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder {
) {
super(
signerOrProvider,
publicClient,
baseContracts,
azoriusContracts,
daoData,
Expand Down
7 changes: 6 additions & 1 deletion src/models/TxBuilderFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { getAddress } from 'viem';
import { PublicClient, getAddress } from 'viem';
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 @@ -34,6 +34,7 @@ export class TxBuilderFactory extends BaseTxBuilder {

constructor(
signerOrProvider: ethers.Signer | any,
publicClient: PublicClient,
baseContracts: BaseContracts,
azoriusContracts: AzoriusContracts | undefined,
daoData: SafeMultisigDAO | AzoriusERC20DAO | AzoriusERC721DAO | SubDAO,
Expand All @@ -45,6 +46,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
) {
super(
signerOrProvider,
publicClient,
baseContracts,
azoriusContracts,
daoData,
Expand Down Expand Up @@ -86,6 +88,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
): DaoTxBuilder {
return new DaoTxBuilder(
this.signerOrProvider,
this.publicClient,
this.baseContracts,
this.azoriusContracts,
this.daoData,
Expand All @@ -108,6 +111,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
): FreezeGuardTxBuilder {
return new FreezeGuardTxBuilder(
this.signerOrProvider,
this.publicClient,
this.baseContracts,
this.daoData as SubDAO,
this.safeContract!,
Expand All @@ -133,6 +137,7 @@ export class TxBuilderFactory extends BaseTxBuilder {
public async createAzoriusTxBuilder(): Promise<AzoriusTxBuilder> {
const azoriusTxBuilder = new AzoriusTxBuilder(
this.signerOrProvider,
this.publicClient,
this.baseContracts,
this.azoriusContracts!,
this.daoData as AzoriusERC20DAO,
Expand Down

0 comments on commit 1f0e490

Please sign in to comment.