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 5, 2024
1 parent 7f59a19 commit ffa9a66
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 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,11 +18,14 @@ 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 { buildContractCall, getRandomBytes } from '../helpers';
import { buildContractCall, buildContractCallViem, getRandomBytes } from '../helpers';
import {
BaseContracts,
SafeTransaction,
Expand Down Expand Up @@ -54,7 +55,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 @@ -66,6 +67,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder {

constructor(
signerOrProvider: any,
publicClient: PublicClient,
baseContracts: BaseContracts,
azoriusContracts: AzoriusContracts,
daoData: AzoriusERC20DAO | AzoriusERC721DAO,
Expand All @@ -77,6 +79,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder {
) {
super(
signerOrProvider,
publicClient,
baseContracts,
azoriusContracts,
daoData,
Expand Down Expand Up @@ -244,9 +247,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 @@ -546,6 +554,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 @@ -556,10 +568,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
8 changes: 5 additions & 3 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,9 @@ 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) {
const tokenApprovalTx = azoriusTxBuilder.buildApproveClaimAllocation();
if (this.parentTokenAddress && parentAllocation && parentAllocation !== 0n && tokenApprovalTx) {
tokenClaimTx = azoriusTxBuilder.buildDeployTokenClaim();
const tokenApprovalTx = azoriusTxBuilder.buildApproveClaimAllocation();
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 ffa9a66

Please sign in to comment.