Skip to content

Commit

Permalink
Feature: Use provider for non signed tx (#277)
Browse files Browse the repository at this point in the history
* update use provider for non signed tx

* fix comments
  • Loading branch information
josemarinas authored Aug 31, 2023
1 parent 34c32a8 commit 4ebcb0f
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 51 deletions.
5 changes: 2 additions & 3 deletions modules/client-common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)"](
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export class AddresslistVotingClientEstimation extends ClientCore
public async createProposal(
params: CreateMajorityVotingProposalParams,
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

const addresslistContract = AddresslistVoting__factory.connect(
params.pluginAddress,
signer,
provider,
);

if (
Expand Down Expand Up @@ -68,15 +68,15 @@ export class AddresslistVotingClientEstimation extends ClientCore
public async voteProposal(
params: VoteProposalParams,
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

const { pluginAddress, id } = decodeProposalId(
params.proposalId,
);

const addresslistContract = AddresslistVoting__factory.connect(
pluginAddress,
signer,
provider,
);

const estimation = await addresslistContract.estimateGas.vote(
Expand All @@ -97,15 +97,15 @@ export class AddresslistVotingClientEstimation extends ClientCore
public async executeProposal(
proposalId: string,
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

const { pluginAddress, id } = decodeProposalId(
proposalId,
);

const addresslistContract = AddresslistVoting__factory.connect(
pluginAddress,
signer,
provider,
);
const estimation = await addresslistContract.estimateGas.execute(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ export class AddresslistVotingClientMethods extends ClientCore
* @memberof AddresslistVotingClientMethods
*/
public async canVote(params: CanVoteParams): Promise<boolean> {
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,
Expand All @@ -296,13 +296,13 @@ export class AddresslistVotingClientMethods extends ClientCore
public async canExecute(
proposalId: string,
): Promise<boolean> {
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);
Expand Down
6 changes: 3 additions & 3 deletions modules/client/src/internal/client/estimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ClientEstimation extends ClientCore implements IClientEstimation {
* @memberof ClientEstimation
*/
public async createDao(params: CreateDaoParams): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();
if (
params.ensSubdomain && !params.ensSubdomain.match(/^[a-z0-9\-]+$/)
) {
Expand All @@ -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)"](
Expand Down
8 changes: 4 additions & 4 deletions modules/client/src/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,9 @@ export class ClientMethods extends ClientCore implements IClientMethods {
* @memberof ClientMethods
*/
public async hasPermission(params: HasPermissionParams): Promise<boolean> {
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,
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions modules/client/src/multisig/internal/client/estimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class MultisigClientEstimation extends ClientCore
public async createProposal(
params: CreateMultisigProposalParams,
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

const multisigContract = Multisig__factory.connect(
params.pluginAddress,
signer,
provider,
);

if (
Expand Down Expand Up @@ -66,14 +66,14 @@ export class MultisigClientEstimation extends ClientCore
public async approveProposal(
params: ApproveMultisigProposalParams,
): Promise<GasFeeEstimation> {
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(
Expand All @@ -92,15 +92,15 @@ export class MultisigClientEstimation extends ClientCore
public async executeProposal(
proposalId: string,
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

const { pluginAddress, id } = decodeProposalId(
proposalId,
);

const multisigContract = Multisig__factory.connect(
pluginAddress,
signer,
provider,
);

const estimation = await multisigContract.estimateGas.execute(
Expand Down
8 changes: 4 additions & 4 deletions modules/client/src/multisig/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ export class MultisigClientMethods extends ClientCore
public async canApprove(
params: CanApproveParams,
): Promise<boolean> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();
if (!isAddress(params.approverAddressOrEns)) {
throw new InvalidAddressOrEnsError();
}
const { pluginAddress, id } = decodeProposalId(params.proposalId);

const multisigContract = Multisig__factory.connect(
pluginAddress,
signer,
provider,
);

return multisigContract.canApprove(id, params.approverAddressOrEns);
Expand All @@ -299,13 +299,13 @@ export class MultisigClientMethods extends ClientCore
public async canExecute(
proposalId: string,
): Promise<boolean> {
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);
Expand Down
16 changes: 8 additions & 8 deletions modules/client/src/tokenVoting/internal/client/estimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export class TokenVotingClientEstimation extends ClientCore
public async createProposal(
params: CreateMajorityVotingProposalParams,
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

const tokenVotingContract = TokenVoting__factory.connect(
params.pluginAddress,
signer,
provider,
);

if (
Expand Down Expand Up @@ -70,15 +70,15 @@ export class TokenVotingClientEstimation extends ClientCore
public async voteProposal(
params: VoteProposalParams,
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

const { pluginAddress, id } = decodeProposalId(
params.proposalId,
);

const tokenVotingContract = TokenVoting__factory.connect(
pluginAddress,
signer,
provider,
);

const estimation = await tokenVotingContract.estimateGas.vote(
Expand All @@ -99,15 +99,15 @@ export class TokenVotingClientEstimation extends ClientCore
public async executeProposal(
proposalId: string,
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

const { pluginAddress, id } = decodeProposalId(
proposalId,
);

const tokenVotingContract = TokenVoting__factory.connect(
pluginAddress,
signer,
provider,
);
const estimation = await tokenVotingContract.estimateGas.execute(
id,
Expand All @@ -125,10 +125,10 @@ export class TokenVotingClientEstimation extends ClientCore
public async delegateTokens(
params: DelegateTokensParams,
): Promise<GasFeeEstimation> {
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,
Expand Down
13 changes: 6 additions & 7 deletions modules/client/src/tokenVoting/internal/client/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export class TokenVotingClientMethods extends ClientCore
* @returns {*} {Promise<boolean>}
*/
public async canVote(params: CanVoteParams): Promise<boolean> {
const signer = this.web3.getConnectedSigner();
const provider = this.web3.getProvider();

if (!isAddress(params.voterAddressOrEns)) {
throw new InvalidAddressError();
Expand All @@ -420,7 +420,7 @@ export class TokenVotingClientMethods extends ClientCore

const tokenVotingContract = TokenVoting__factory.connect(
pluginAddress,
signer,
provider,
);
return tokenVotingContract.callStatic.canVote(
id,
Expand All @@ -439,13 +439,13 @@ export class TokenVotingClientMethods extends ClientCore
public async canExecute(
proposalId: string,
): Promise<boolean> {
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);
Expand Down Expand Up @@ -762,7 +762,6 @@ export class TokenVotingClientMethods extends ClientCore
public async isTokenVotingCompatibleToken(
tokenAddress: string,
): Promise<TokenVotingTokenCompatibility> {
const signer = this.web3.getConnectedSigner();
// check if is address
if (!isAddress(tokenAddress) || tokenAddress === AddressZero) {
throw new InvalidAddressError();
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 4ebcb0f

Please sign in to comment.