diff --git a/modules/client-common/src/utils.ts b/modules/client-common/src/utils.ts index 5a0c9159e..82ded9dc8 100644 --- a/modules/client-common/src/utils.ts +++ b/modules/client-common/src/utils.ts @@ -83,7 +83,6 @@ export async function prepareGenericInstallationEstimation( web3: IClientWeb3Core, params: PrepareInstallationParams, ) { - const signer = web3.getConnectedSigner(); const provider = web3.getProvider(); if (!isAddress(params.pluginRepo)) { throw new InvalidAddressError(); @@ -94,7 +93,7 @@ export async function prepareGenericInstallationEstimation( if (!version) { const pluginRepo = PluginRepo__factory.connect( params.pluginRepo, - signer, + provider, ); const currentRelease = await pluginRepo.latestRelease(); const latestVersion = await pluginRepo["getLatestVersion(uint8)"]( @@ -111,7 +110,7 @@ export async function prepareGenericInstallationEstimation( // connect to psp contract const pspContract = PluginSetupProcessor__factory.connect( LIVE_CONTRACTS[networkName].pluginSetupProcessorAddress, - signer, + provider, ); const gasEstimation = await pspContract.estimateGas.prepareInstallation( diff --git a/modules/client/CHANGELOG.md b/modules/client/CHANGELOG.md index 28d4c7c25..8846e5e02 100644 --- a/modules/client/CHANGELOG.md +++ b/modules/client/CHANGELOG.md @@ -19,6 +19,7 @@ TEMPLATE: ## [UPCOMING] ### Changed - All addresses are now lowercased on subgraph methods +- Use signer only when transactions need to be signed, else use provider ## [1.13.1-rc1] ### Fixes - Support for ERC115Transfers and balances diff --git a/modules/client/src/addresslistVoting/internal/client/estimation.ts b/modules/client/src/addresslistVoting/internal/client/estimation.ts index dac239f5a..802146b0a 100644 --- a/modules/client/src/addresslistVoting/internal/client/estimation.ts +++ b/modules/client/src/addresslistVoting/internal/client/estimation.ts @@ -27,11 +27,11 @@ export class AddresslistVotingClientEstimation extends ClientCore public async createProposal( params: CreateMajorityVotingProposalParams, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const addresslistContract = AddresslistVoting__factory.connect( params.pluginAddress, - signer, + provider, ); if ( @@ -68,7 +68,7 @@ export class AddresslistVotingClientEstimation extends ClientCore public async voteProposal( params: VoteProposalParams, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId( params.proposalId, @@ -76,7 +76,7 @@ export class AddresslistVotingClientEstimation extends ClientCore const addresslistContract = AddresslistVoting__factory.connect( pluginAddress, - signer, + provider, ); const estimation = await addresslistContract.estimateGas.vote( @@ -97,7 +97,7 @@ export class AddresslistVotingClientEstimation extends ClientCore public async executeProposal( proposalId: string, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId( proposalId, @@ -105,7 +105,7 @@ export class AddresslistVotingClientEstimation extends ClientCore const addresslistContract = AddresslistVoting__factory.connect( pluginAddress, - signer, + provider, ); const estimation = await addresslistContract.estimateGas.execute( id, diff --git a/modules/client/src/addresslistVoting/internal/client/methods.ts b/modules/client/src/addresslistVoting/internal/client/methods.ts index 2eae9793b..c40cb8f39 100644 --- a/modules/client/src/addresslistVoting/internal/client/methods.ts +++ b/modules/client/src/addresslistVoting/internal/client/methods.ts @@ -272,13 +272,13 @@ export class AddresslistVotingClientMethods extends ClientCore * @memberof AddresslistVotingClientMethods */ public async canVote(params: CanVoteParams): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId(params.proposalId); const addresslistContract = AddresslistVoting__factory.connect( pluginAddress, - signer, + provider, ); return addresslistContract.callStatic.canVote( id, @@ -296,13 +296,13 @@ export class AddresslistVotingClientMethods extends ClientCore public async canExecute( proposalId: string, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId(proposalId); const addresslistContract = AddresslistVoting__factory.connect( pluginAddress, - signer, + provider, ); return addresslistContract.canExecute(id); diff --git a/modules/client/src/internal/client/estimation.ts b/modules/client/src/internal/client/estimation.ts index 777d5f5da..9bad472f9 100644 --- a/modules/client/src/internal/client/estimation.ts +++ b/modules/client/src/internal/client/estimation.ts @@ -51,7 +51,7 @@ export class ClientEstimation extends ClientCore implements IClientEstimation { * @memberof ClientEstimation */ public async createDao(params: CreateDaoParams): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); if ( params.ensSubdomain && !params.ensSubdomain.match(/^[a-z0-9\-]+$/) ) { @@ -60,11 +60,11 @@ export class ClientEstimation extends ClientCore implements IClientEstimation { const daoInstance = DAOFactory__factory.connect( this.web3.getAddress("daoFactoryAddress"), - signer, + provider, ); const pluginInstallationData: DAOFactory.PluginSettingsStruct[] = []; for (const plugin of params.plugins) { - const repo = PluginRepo__factory.connect(plugin.id, signer); + const repo = PluginRepo__factory.connect(plugin.id, provider); const currentRelease = await repo.latestRelease(); const latestVersion = await repo["getLatestVersion(uint8)"]( diff --git a/modules/client/src/internal/client/methods.ts b/modules/client/src/internal/client/methods.ts index baa5de1f7..3c8bf539d 100644 --- a/modules/client/src/internal/client/methods.ts +++ b/modules/client/src/internal/client/methods.ts @@ -645,9 +645,9 @@ export class ClientMethods extends ClientCore implements IClientMethods { * @memberof ClientMethods */ public async hasPermission(params: HasPermissionParams): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); // connect to the managing dao - const daoInstance = DAO__factory.connect(params.daoAddressOrEns, signer); + const daoInstance = DAO__factory.connect(params.daoAddressOrEns, provider); return daoInstance.hasPermission( params.where, params.who, @@ -1034,10 +1034,10 @@ export class ClientMethods extends ClientCore implements IClientMethods { if (!isAddress(contractAddress)) { throw new InvalidAddressError(); } - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const protocolInstance = IProtocolVersion__factory.connect( contractAddress, - signer, + provider, ); let version: [number, number, number]; try { diff --git a/modules/client/src/multisig/internal/client/estimation.ts b/modules/client/src/multisig/internal/client/estimation.ts index f652f09a9..b690640bb 100644 --- a/modules/client/src/multisig/internal/client/estimation.ts +++ b/modules/client/src/multisig/internal/client/estimation.ts @@ -26,11 +26,11 @@ export class MultisigClientEstimation extends ClientCore public async createProposal( params: CreateMultisigProposalParams, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const multisigContract = Multisig__factory.connect( params.pluginAddress, - signer, + provider, ); if ( @@ -66,14 +66,14 @@ export class MultisigClientEstimation extends ClientCore public async approveProposal( params: ApproveMultisigProposalParams, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId( params.proposalId, ); const multisigContract = Multisig__factory.connect( pluginAddress, - signer, + provider, ); const estimation = await multisigContract.estimateGas.approve( @@ -92,7 +92,7 @@ export class MultisigClientEstimation extends ClientCore public async executeProposal( proposalId: string, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId( proposalId, @@ -100,7 +100,7 @@ export class MultisigClientEstimation extends ClientCore const multisigContract = Multisig__factory.connect( pluginAddress, - signer, + provider, ); const estimation = await multisigContract.estimateGas.execute( diff --git a/modules/client/src/multisig/internal/client/methods.ts b/modules/client/src/multisig/internal/client/methods.ts index ac528274e..060d86b52 100644 --- a/modules/client/src/multisig/internal/client/methods.ts +++ b/modules/client/src/multisig/internal/client/methods.ts @@ -276,7 +276,7 @@ export class MultisigClientMethods extends ClientCore public async canApprove( params: CanApproveParams, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); if (!isAddress(params.approverAddressOrEns)) { throw new InvalidAddressOrEnsError(); } @@ -284,7 +284,7 @@ export class MultisigClientMethods extends ClientCore const multisigContract = Multisig__factory.connect( pluginAddress, - signer, + provider, ); return multisigContract.canApprove(id, params.approverAddressOrEns); @@ -299,13 +299,13 @@ export class MultisigClientMethods extends ClientCore public async canExecute( proposalId: string, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId(proposalId); const multisigContract = Multisig__factory.connect( pluginAddress, - signer, + provider, ); return multisigContract.canExecute(id); diff --git a/modules/client/src/tokenVoting/internal/client/estimation.ts b/modules/client/src/tokenVoting/internal/client/estimation.ts index 1415f6a2a..e3cf76599 100644 --- a/modules/client/src/tokenVoting/internal/client/estimation.ts +++ b/modules/client/src/tokenVoting/internal/client/estimation.ts @@ -30,11 +30,11 @@ export class TokenVotingClientEstimation extends ClientCore public async createProposal( params: CreateMajorityVotingProposalParams, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const tokenVotingContract = TokenVoting__factory.connect( params.pluginAddress, - signer, + provider, ); if ( @@ -70,7 +70,7 @@ export class TokenVotingClientEstimation extends ClientCore public async voteProposal( params: VoteProposalParams, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId( params.proposalId, @@ -78,7 +78,7 @@ export class TokenVotingClientEstimation extends ClientCore const tokenVotingContract = TokenVoting__factory.connect( pluginAddress, - signer, + provider, ); const estimation = await tokenVotingContract.estimateGas.vote( @@ -99,7 +99,7 @@ export class TokenVotingClientEstimation extends ClientCore public async executeProposal( proposalId: string, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId( proposalId, @@ -107,7 +107,7 @@ export class TokenVotingClientEstimation extends ClientCore const tokenVotingContract = TokenVoting__factory.connect( pluginAddress, - signer, + provider, ); const estimation = await tokenVotingContract.estimateGas.execute( id, @@ -125,10 +125,10 @@ export class TokenVotingClientEstimation extends ClientCore public async delegateTokens( params: DelegateTokensParams, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const governanceErc20Contract = GovernanceERC20__factory.connect( params.tokenAddress, - signer, + provider, ); const estimation = await governanceErc20Contract.estimateGas.delegate( params.delegatee, diff --git a/modules/client/src/tokenVoting/internal/client/methods.ts b/modules/client/src/tokenVoting/internal/client/methods.ts index 054a16b0b..eb402f821 100644 --- a/modules/client/src/tokenVoting/internal/client/methods.ts +++ b/modules/client/src/tokenVoting/internal/client/methods.ts @@ -410,7 +410,7 @@ export class TokenVotingClientMethods extends ClientCore * @returns {*} {Promise} */ public async canVote(params: CanVoteParams): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); if (!isAddress(params.voterAddressOrEns)) { throw new InvalidAddressError(); @@ -420,7 +420,7 @@ export class TokenVotingClientMethods extends ClientCore const tokenVotingContract = TokenVoting__factory.connect( pluginAddress, - signer, + provider, ); return tokenVotingContract.callStatic.canVote( id, @@ -439,13 +439,13 @@ export class TokenVotingClientMethods extends ClientCore public async canExecute( proposalId: string, ): Promise { - const signer = this.web3.getConnectedSigner(); + const provider = this.web3.getProvider(); const { pluginAddress, id } = decodeProposalId(proposalId); const tokenVotingContract = TokenVoting__factory.connect( pluginAddress, - signer, + provider, ); return tokenVotingContract.canExecute(id); @@ -762,7 +762,6 @@ export class TokenVotingClientMethods extends ClientCore public async isTokenVotingCompatibleToken( tokenAddress: string, ): Promise { - const signer = this.web3.getConnectedSigner(); // check if is address if (!isAddress(tokenAddress) || tokenAddress === AddressZero) { throw new InvalidAddressError(); @@ -775,10 +774,10 @@ export class TokenVotingClientMethods extends ClientCore const contract = new Contract( tokenAddress, ERC165_ABI, - signer, + provider, ); - if (!await isERC20Token(tokenAddress, signer)) { + if (!await isERC20Token(tokenAddress, provider)) { return TokenVotingTokenCompatibility.INCOMPATIBLE; } try { diff --git a/modules/client/src/tokenVoting/internal/utils.ts b/modules/client/src/tokenVoting/internal/utils.ts index 8c5aaed89..d720b8317 100644 --- a/modules/client/src/tokenVoting/internal/utils.ts +++ b/modules/client/src/tokenVoting/internal/utils.ts @@ -41,9 +41,9 @@ import { ProposalStatus, TokenType, } from "@aragon/sdk-client-common"; -import { Signer } from "@ethersproject/abstract-signer"; import { Contract } from "@ethersproject/contracts"; import { abi as ERC_20_ABI } from "@openzeppelin/contracts/build/contracts/ERC20.json"; +import { JsonRpcProvider } from "@ethersproject/providers"; export function toTokenVotingProposal( proposal: SubgraphTokenVotingProposal, @@ -339,8 +339,8 @@ export function computeProposalStatusFilter(status: ProposalStatus) { /** * Checks if the given address is an ERC20 token - * This function isn not 100% accurate. - * It just checks if the token has a balanceOf + * This function is not 100% accurate. + * It just checks if the token has a balanceOf * function and a decimals function * * @export @@ -350,7 +350,7 @@ export function computeProposalStatusFilter(status: ProposalStatus) { */ export async function isERC20Token( tokenAddress: string, - signer: Signer, + signer: JsonRpcProvider, ): Promise { const contract = new Contract( tokenAddress, @@ -359,11 +359,11 @@ export async function isERC20Token( ); try { await Promise.all([ - contract.balanceOf(await signer.getAddress()), + contract.balanceOf(AddressZero), contract.decimals(), ]); return true; } catch { return false; } -} \ No newline at end of file +}