diff --git a/src/hooks/DAO/useBuildDAOTx.ts b/src/hooks/DAO/useBuildDAOTx.ts index f8eeeebd81..7a0c90c18b 100644 --- a/src/hooks/DAO/useBuildDAOTx.ts +++ b/src/hooks/DAO/useBuildDAOTx.ts @@ -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'; @@ -27,6 +28,7 @@ const useBuildDAOTx = () => { governance, governanceContracts: { erc721LinearVotingContractAddress }, } = useFractal(); + const publicClient = usePublicClient(); const buildDao = useCallback( async ( @@ -36,7 +38,7 @@ const useBuildDAOTx = () => { ) => { let azoriusContracts: AzoriusContracts | undefined; - if (!user.address || !signerOrProvider || !baseContracts) { + if (!user.address || !signerOrProvider || !baseContracts || !publicClient) { return; } const { @@ -102,6 +104,7 @@ const useBuildDAOTx = () => { const txBuilderFactory = new TxBuilderFactory( signerOrProvider, + publicClient, buildrerBaseContracts, azoriusContracts, daoData, @@ -148,6 +151,7 @@ const useBuildDAOTx = () => { [ user.address, signerOrProvider, + publicClient, baseContracts, erc721LinearVotingContractAddress, dao, diff --git a/src/hooks/DAO/useDeployAzorius.ts b/src/hooks/DAO/useDeployAzorius.ts index 7a85510812..58fc7ddb1f 100644 --- a/src/hooks/DAO/useDeployAzorius.ts +++ b/src/hooks/DAO/useDeployAzorius.ts @@ -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'; @@ -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 { @@ -81,6 +84,7 @@ const useDeployAzorius = () => { const txBuilderFactory = new TxBuilderFactory( signerOrProvider, + publicClient, builderBaseContracts, azoriusContracts, daoData, @@ -135,6 +139,7 @@ const useDeployAzorius = () => { }, [ signerOrProvider, + publicClient, baseContracts, t, canUserCreateProposal, diff --git a/src/models/AzoriusTxBuilder.ts b/src/models/AzoriusTxBuilder.ts index 7c2f2ad4a4..b61494e35b 100644 --- a/src/models/AzoriusTxBuilder.ts +++ b/src/models/AzoriusTxBuilder.ts @@ -5,8 +5,6 @@ import { LinearERC20Voting__factory, LinearERC721Voting, LinearERC721Voting__factory, - VotesERC20, - VotesERC20__factory, } from '@fractal-framework/fractal-contracts'; import { getCreate2Address, @@ -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, @@ -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 | undefined; private votesERC20WrapperMasterCopyAddress: string; private votesERC20MasterCopyAddress: string; @@ -66,6 +67,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { constructor( signerOrProvider: any, + publicClient: PublicClient, baseContracts: BaseContracts, azoriusContracts: AzoriusContracts, daoData: AzoriusERC20DAO | AzoriusERC721DAO, @@ -77,6 +79,7 @@ export class AzoriusTxBuilder extends BaseTxBuilder { ) { super( signerOrProvider, + publicClient, baseContracts, azoriusContracts, daoData, @@ -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, @@ -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!, @@ -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!, diff --git a/src/models/BaseTxBuilder.ts b/src/models/BaseTxBuilder.ts index d9c5ee903d..aa912cf1b1 100644 --- a/src/models/BaseTxBuilder.ts +++ b/src/models/BaseTxBuilder.ts @@ -1,4 +1,5 @@ import { ethers } from 'ethers'; +import { PublicClient } from 'viem'; import { BaseContracts, AzoriusContracts, @@ -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; @@ -18,6 +20,7 @@ export class BaseTxBuilder { constructor( signerOrProvider: ethers.Signer | any, + publicClient: PublicClient, baseContracts: BaseContracts, azoriusContracts: AzoriusContracts | undefined, daoData: SafeMultisigDAO | AzoriusERC20DAO | AzoriusERC721DAO | SubDAO, @@ -25,6 +28,7 @@ export class BaseTxBuilder { parentTokenAddress?: string, ) { this.signerOrProvider = signerOrProvider; + this.publicClient = publicClient; this.baseContracts = baseContracts; this.daoData = daoData; this.azoriusContracts = azoriusContracts; diff --git a/src/models/DaoTxBuilder.ts b/src/models/DaoTxBuilder.ts index 46b2f28aa5..a4887dcd2b 100644 --- a/src/models/DaoTxBuilder.ts +++ b/src/models/DaoTxBuilder.ts @@ -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 { @@ -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, @@ -48,6 +49,7 @@ export class DaoTxBuilder extends BaseTxBuilder { ) { super( signerOrProvider, + publicClient, baseContracts, azoriusContracts, daoData, @@ -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); } diff --git a/src/models/FreezeGuardTxBuilder.ts b/src/models/FreezeGuardTxBuilder.ts index 739422bf06..ba999c0e47 100644 --- a/src/models/FreezeGuardTxBuilder.ts +++ b/src/models/FreezeGuardTxBuilder.ts @@ -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'; @@ -62,6 +63,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder { constructor( signerOrProvider: any, + publicClient: PublicClient, baseContracts: BaseContracts, daoData: SubDAO, safeContract: GnosisSafeL2, @@ -76,6 +78,7 @@ export class FreezeGuardTxBuilder extends BaseTxBuilder { ) { super( signerOrProvider, + publicClient, baseContracts, azoriusContracts, daoData, diff --git a/src/models/TxBuilderFactory.ts b/src/models/TxBuilderFactory.ts index cae1742ce3..80a31d8c18 100644 --- a/src/models/TxBuilderFactory.ts +++ b/src/models/TxBuilderFactory.ts @@ -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'; @@ -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, @@ -45,6 +46,7 @@ export class TxBuilderFactory extends BaseTxBuilder { ) { super( signerOrProvider, + publicClient, baseContracts, azoriusContracts, daoData, @@ -86,6 +88,7 @@ export class TxBuilderFactory extends BaseTxBuilder { ): DaoTxBuilder { return new DaoTxBuilder( this.signerOrProvider, + this.publicClient, this.baseContracts, this.azoriusContracts, this.daoData, @@ -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!, @@ -133,6 +137,7 @@ export class TxBuilderFactory extends BaseTxBuilder { public async createAzoriusTxBuilder(): Promise { const azoriusTxBuilder = new AzoriusTxBuilder( this.signerOrProvider, + this.publicClient, this.baseContracts, this.azoriusContracts!, this.daoData as AzoriusERC20DAO,