Skip to content

Commit

Permalink
Implements estimation for createProposal
Browse files Browse the repository at this point in the history
Signed-off-by: emmdim <[email protected]>
  • Loading branch information
emmdim committed Sep 25, 2023
1 parent 6dc0793 commit df8b547
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
8 changes: 6 additions & 2 deletions packages/js-client/src/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ export interface IOffchainVotingClientMethods {
getMembers(pluginAddress: string): Promise<TokenVotingMember[]>;
}
export interface IOffchainVotingClientEstimation {
prepareInstallation(
params: PrepareInstallationParams
// prepareInstallation(
// params: PrepareInstallationParams
// ): Promise<GasFeeEstimation>;
// createProposal
createProposal(
params: CreateGasslessProposalParams
): Promise<GasFeeEstimation>;
// Add any estimation methods that you need
}
Expand Down
49 changes: 20 additions & 29 deletions packages/js-client/src/internal/modules/estimation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {
CreateGasslessProposalParams,
GaslessProposalParametersContractStruct,
} from '../../types';
import { OffchainVotingClientCore } from '../core';
import { IOffchainVotingClientEstimation } from '../interfaces';
import { PluginRepo__factory } from '@aragon/osx-ethers';
import { GasFeeEstimation } from '@aragon/sdk-client-common';
import {
GasFeeEstimation,
prepareGenericInstallationEstimation,
} from '@aragon/sdk-client-common';
import { SizeMismatchError, boolArrayToBitmap } from '@aragon/sdk-common';
SizeMismatchError,
boolArrayToBitmap,
hexToBytes,
} from '@aragon/sdk-common';
import { VocdoniVoting__factory } from '@vocdoni/offchain-voting-ethers';

export class OffchainVotingClientEstimation
Expand All @@ -15,16 +19,16 @@ export class OffchainVotingClientEstimation
/**
* Estimates the gas fee of creating a proposal on the plugin
*
* @param {CreateMajorityVotingProposalParams} params
* @param {CreateGasslessProposalParams} params
* @return {*} {Promise<GasFeeEstimation>}
* @memberof TokenVotingClientEstimation
* @memberof OffchainVotingClientEstimation
*/
public async createProposal(
params: CreateMajorityVotingProposalParams
params: CreateGasslessProposalParams
): Promise<GasFeeEstimation> {
const signer = this.web3.getConnectedSigner();

const tokenVotingContract = VocdoniVoting__factory.connect(
const gaslessVotingContract = VocdoniVoting__factory.connect(
params.pluginAddress,
signer
);
Expand All @@ -37,35 +41,22 @@ export class OffchainVotingClientEstimation
}
const allowFailureMap = boolArrayToBitmap(params.failSafeActions);

const startTimestamp = params.startDate?.getTime() || 0;
const endTimestamp = params.endDate?.getTime() || 0;

const votingParams: GaslessProposalParametersContractStruct = {
censusBlock: [] as string[],
startDate: BigInt(params.startDate),
endDate: BigInt(params.endDate),
expirationDate: BigInt(0),
securityBlock: BigInt(0),
};
const tx = await gaslessVotingContract.createProposal(
// toUtf8Bytes(params.metadataUri),
hexToBytes(params.vochainProposalId),
allowFailureMap,
votingParams,
params.actions || []
// params.creatorVote || 0,
// params.executeOnPass || false,
);

const estimatedGasFee =
await tokenVotingContract.estimateGas.createProposal(
toUtf8Bytes(params.metadataUri),
params.actions || [],
await gaslessVotingContract.estimateGas.createProposal(
// toUtf8Bytes(params.metadataUri),
hexToBytes(params.vochainProposalId),
allowFailureMap,
Math.round(startTimestamp / 1000),
Math.round(endTimestamp / 1000),
params.creatorVote || 0,
params.executeOnPass || false
votingParams,
params.actions || []
// params.creatorVote || 0,
// params.executeOnPass || false,
);
return this.web3.getApproximateGasFee(estimatedGasFee.toBigInt());
}
Expand Down
1 change: 0 additions & 1 deletion packages/js-client/src/internal/modules/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
hexToBytes,
} from '@aragon/sdk-common';
import { isAddress } from '@ethersproject/address';
import { BigNumber } from '@ethersproject/bignumber';
import { VocdoniVoting__factory } from '@vocdoni/offchain-voting-ethers';
import {
EnvOptions,
Expand Down
1 change: 0 additions & 1 deletion packages/js-client/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
VoteOption,
ProposalFromSC,
GaslessProposalParametersStruct,
GaslessProposalParametersContractStruct,
InvalidResults,
GaslessVotingProposalFromSC,
} from '../types';
Expand Down

0 comments on commit df8b547

Please sign in to comment.