From dfd4f7191134e43ca3b6ec65d8e2fe9494608ea2 Mon Sep 17 00:00:00 2001 From: emmdim Date: Tue, 7 Nov 2023 19:53:32 +0100 Subject: [PATCH] BREAKING: Updates to new smart contracts onlyMultisigProposalCreation -> onlyExecutionMultisigProposalCreation minDuration -> minVoteDuration expirationTime -> minTallyDuration censusBlock desaparece createProposal now needs: totalVotingPower -> census weight censusURI censusRoot --- packages/contracts-ethers/package.json | 2 +- packages/js-client/package.json | 6 +-- packages/js-client/src/internal/constants.ts | 6 +-- .../src/internal/graphql-queries/proposal.ts | 4 +- .../src/internal/modules/encoding.ts | 13 +++--- .../src/internal/modules/estimation.ts | 12 +++--- .../js-client/src/internal/modules/methods.ts | 14 +++--- packages/js-client/src/internal/utils.ts | 30 +++++++------ packages/js-client/src/types.ts | 43 +++++++------------ 9 files changed, 63 insertions(+), 67 deletions(-) diff --git a/packages/contracts-ethers/package.json b/packages/contracts-ethers/package.json index 68431a5e..2b0201b8 100644 --- a/packages/contracts-ethers/package.json +++ b/packages/contracts-ethers/package.json @@ -1,7 +1,7 @@ { "name": "@vocdoni/gasless-voting-ethers", "author": "Vocdoni Association", - "version": "0.0.1-rc1", + "version": "0.0.1-rc4", "description": "Plugin contract definitions for ethers.js", "main": "dist/bundle-cjs.js", "module": "dist/bundle-esm.js", diff --git a/packages/js-client/package.json b/packages/js-client/package.json index bcd95b22..3755573f 100644 --- a/packages/js-client/package.json +++ b/packages/js-client/package.json @@ -1,7 +1,7 @@ { "name": "@vocdoni/gasless-voting", "author": "Vocdoni Association", - "version": "0.0.1-rc7", + "version": "0.0.1-rc13", "license": "AGPL-3.0-or-later", "main": "dist/index.js", "module": "dist/gasless-voting.esm.js", @@ -56,7 +56,7 @@ "ganache": "^7.8.0", "husky": "^7.0.4", "size-limit": "^7.0.8", - "tsdx": "^0.14.1", + "tsdx": "^0.14.1", "tslib": "^2.3.1", "typescript": "^4.6.2" }, @@ -71,7 +71,7 @@ "@ethersproject/wallet": "^5.7.0", "graphql": "^16.6.0", "graphql-request": "4.3.0", - "@vocdoni/gasless-voting-ethers": "./vocdoni-gasless-voting-ethers-v0.0.1-rc1.tgz", + "@vocdoni/gasless-voting-ethers": "./vocdoni-gasless-voting-ethers-v0.0.1-rc4.tgz", "@vocdoni/sdk": "0.3.1", "axios": "0.27.2", "@types/big.js": "^6.1.5" diff --git a/packages/js-client/src/internal/constants.ts b/packages/js-client/src/internal/constants.ts index fe1c1044..d359f320 100644 --- a/packages/js-client/src/internal/constants.ts +++ b/packages/js-client/src/internal/constants.ts @@ -74,7 +74,7 @@ export const INSTALLATION_ABI: MetadataAbiInput[] = [ components: [ { internalType: 'bool', - name: 'onlyCommitteeProposalCreation', + name: 'onlyExecutionMultisigProposalCreation', type: 'bool', description: '', }, @@ -98,7 +98,7 @@ export const INSTALLATION_ABI: MetadataAbiInput[] = [ }, { internalType: 'uint64', - name: 'minDuration', + name: 'minVoteDuration', type: 'uint64', description: '', }, @@ -116,7 +116,7 @@ export const INSTALLATION_ABI: MetadataAbiInput[] = [ }, { internalType: 'string', - name: 'censusStrategy', + name: 'censusStrategyURI', type: 'string', description: '', }, diff --git a/packages/js-client/src/internal/graphql-queries/proposal.ts b/packages/js-client/src/internal/graphql-queries/proposal.ts index 3e2690df..b3128901 100644 --- a/packages/js-client/src/internal/graphql-queries/proposal.ts +++ b/packages/js-client/src/internal/graphql-queries/proposal.ts @@ -25,7 +25,7 @@ export const QueryTokenVotingProposal = gql` votingMode supportThreshold startDate - endDate + voteEndDate executed earlyExecutable potentiallyExecutable @@ -89,7 +89,7 @@ export const QueryTokenVotingProposals = gql` no abstain startDate - endDate + voteEndDate executed earlyExecutable potentiallyExecutable diff --git a/packages/js-client/src/internal/modules/encoding.ts b/packages/js-client/src/internal/modules/encoding.ts index aaf39eb2..88ccc48c 100644 --- a/packages/js-client/src/internal/modules/encoding.ts +++ b/packages/js-client/src/internal/modules/encoding.ts @@ -98,19 +98,22 @@ export class GaslessVotingClientEncoding const votingInterface = VocdoniVoting__factory.createInterface(); const args = gaslessVotingSettingsToContract(params); // get hex bytes + // const expectedfunction = votingInterface.getFunction( + // 'updatePluginSettings((bool,uint16,uint32,uint32,uint64,uint64,address,uint256,string))' + // ); const hexBytes = votingInterface.encodeFunctionData( - 'updatePluginSettings', + "updatePluginSettings", [ { - onlyCommitteeProposalCreation: args[0], + onlyExecutionMultisigProposalCreation: args[0], minTallyApprovals: args[1], minParticipation: args[2], supportThreshold: args[3], - minDuration: args[4], - expirationTime: args[5], + minVoteDuration: args[4], + minTallyDuration: args[5], daoTokenAddress: args[6], minProposerVotingPower: args[7], - censusStrategy: args[8], + censusStrategyURI: args[8], }, ] ); diff --git a/packages/js-client/src/internal/modules/estimation.ts b/packages/js-client/src/internal/modules/estimation.ts index 7f53ab2c..98cf133b 100644 --- a/packages/js-client/src/internal/modules/estimation.ts +++ b/packages/js-client/src/internal/modules/estimation.ts @@ -45,15 +45,17 @@ export class GaslessVotingClientEstimation const startTimestamp = params.startDate?.getTime() || 0; - const endTimestamp = params.endDate.getTime(); - const expirationTimestamp = params.expirationDate?.getTime() || 0; + const endTimestamp = params.voteEndDate.getTime(); + const minTallyDurationTimestamp = params.tallyEndDate?.getTime() || 0; const votingParams: GaslessProposalParametersContractStruct = { - censusBlock: [] as string[], startDate: BigInt(Math.round(startTimestamp / 1000)), - endDate: BigInt(Math.round(endTimestamp / 1000)), - expirationDate: BigInt(Math.round(expirationTimestamp / 1000)), + voteEndDate: BigInt(Math.round(endTimestamp / 1000)), + tallyEndDate: BigInt(Math.round(minTallyDurationTimestamp / 1000)), securityBlock: BigInt(0), + totalVotingPower: params.totalVotingPower, + censusURI: params.censusURI, + censusRoot: hexToBytes(params.censusRoot) }; const estimatedGasFee = await gaslessVotingContract.estimateGas.createProposal( diff --git a/packages/js-client/src/internal/modules/methods.ts b/packages/js-client/src/internal/modules/methods.ts index 3ae54178..d332e322 100644 --- a/packages/js-client/src/internal/modules/methods.ts +++ b/packages/js-client/src/internal/modules/methods.ts @@ -116,16 +116,18 @@ export class GaslessVotingClientMethods const allowFailureMap = boolArrayToBitmap(params.failSafeActions); const startTimestamp = params.startDate?.getTime() || 0; - const endTimestamp = params.endDate.getTime() || 0; - const expirationTimestamp = params.expirationDate?.getTime() || 0; + const endTimestamp = params.voteEndDate.getTime() || 0; + const minTallyDurationTimestamp = params.tallyEndDate?.getTime() || 0; const votingParams: GaslessProposalParametersContractStruct = { - censusBlock: [] as string[], startDate: BigInt(Math.round(startTimestamp / 1000)), - endDate: BigInt(Math.round(endTimestamp / 1000)), - expirationDate: BigInt(Math.round(expirationTimestamp / 1000)), + voteEndDate: BigInt(Math.round(endTimestamp / 1000)), + tallyEndDate: BigInt(Math.round(minTallyDurationTimestamp / 1000)), securityBlock: BigInt(0), + totalVotingPower: params.totalVotingPower, + censusURI: params.censusURI, + censusRoot: hexToBytes(params.censusRoot) }; const tx = await gaslessVotingContract.createProposal( // toUtf8Bytes(params.metadataUri), @@ -665,7 +667,7 @@ export class GaslessVotingClientMethods signer ); - return tokenVotingContract.isCommitteeMember(memberAddress); + return tokenVotingContract.isExecutionMultisigMember(memberAddress); } /** diff --git a/packages/js-client/src/internal/utils.ts b/packages/js-client/src/internal/utils.ts index 43c8c340..84420f75 100644 --- a/packages/js-client/src/internal/utils.ts +++ b/packages/js-client/src/internal/utils.ts @@ -84,12 +84,12 @@ export function gaslessVotingSettingsToContract( string ] { return [ - params.onlyMultisigProposalCreation || true, + params.onlyExecutionMultisigProposalCreation || true, params.minTallyApprovals, encodeRatio(params.minParticipation, 6), encodeRatio(params.supportThreshold, 6), - BigNumber.from(params.minDuration), - BigNumber.from(params.expirationTime), + BigNumber.from(params.minVoteDuration), + BigNumber.from(params.minTallyDuration), '0x0000000000000000000000000000000000000000', BigNumber.from(params.minProposerVotingPower ?? 0), params.censusStrategy, @@ -100,12 +100,12 @@ export function votingSettingsfromContract( settings: VocdoniVoting.PluginSettingsStructOutput ): GaslessPluginVotingSettings { return { - onlyMultisigProposalCreation: settings[0], + onlyExecutionMultisigProposalCreation: settings[0], minTallyApprovals: settings[1], minParticipation: decodeRatio(settings[2], 6), supportThreshold: decodeRatio(settings[3], 6), - minDuration: settings[4].toNumber(), - expirationTime: settings[5].toNumber(), + minVoteDuration: settings[4].toNumber(), + minTallyDuration: settings[5].toNumber(), daoTokenAddress: settings[6], minProposerVotingPower: settings[7].toBigInt(), censusStrategy: settings[8], @@ -116,11 +116,13 @@ export function proposalParamsfromContract( params: VocdoniVoting.ProposalParametersStructOutput ): GaslessProposalParametersStruct { return { - censusBlock: params.censusBlock, securityBlock: params.securityBlock.toNumber(), startDate: new Date(Number(params.startDate) * 1000), - endDate: new Date(Number(params.endDate) * 1000), - expirationDate: new Date(Number(params.expirationDate) * 1000), + voteEndDate: new Date(Number(params.voteEndDate) * 1000), + tallyEndDate: new Date(Number(params.tallyEndDate) * 1000), + totalVotingPower: params.totalVotingPower.toBigInt(), + censusURI: params.censusURI, + censusRoot: params.censusRoot, }; } @@ -140,7 +142,7 @@ export function initParamsToContract(params: GaslessVotingPluginInstall) { params.useToken.wrappedToken.symbol, ]; } - params.votingSettings.onlyMultisigProposalCreation = true; + params.votingSettings.onlyExecutionMultisigProposalCreation = true; return [ params.multisig, gaslessVotingSettingsToContract(params.votingSettings), @@ -230,13 +232,13 @@ export function computeProposalStatus( executed: boolean, hasSucceeded: boolean, startDate: Date, - endDate: Date + voteEndDate: Date ): ProposalStatus { const now = new Date(); if (startDate >= now) { return ProposalStatus.PENDING; } - if (endDate >= now) { + if (voteEndDate >= now) { return ProposalStatus.ACTIVE; } if (executed) { @@ -279,7 +281,7 @@ export function toNewProposal( // census3Token.decimals ); const startDate = SCProposal.parameters.startDate as Date; - const endDate = new Date(SCProposal.parameters.endDate); + const endDate = new Date(SCProposal.parameters.voteEndDate); return { id: `0x${SCproposalID.toString()}`, // string; @@ -303,7 +305,7 @@ export function toNewProposal( startDate, //Date; endDate, //Date; creationDate: vochainProposal.creationTime, //Date; - expirationDate: new Date(SCProposal.parameters.expirationDate as Date), + tallyEndDate: new Date(SCProposal.parameters.tallyEndDate as Date), actions: SCProposal.actions, //DaoAction[]; status: computeProposalStatus( SCProposal.executed, diff --git a/packages/js-client/src/types.ts b/packages/js-client/src/types.ts index 10447c15..9091dabc 100644 --- a/packages/js-client/src/types.ts +++ b/packages/js-client/src/types.ts @@ -99,7 +99,7 @@ export type VotingSettings = { votingMode: number; supportThreshold: number; minParticipation: number; - minDuration: bigint; + minVoteDuration: bigint; minProposerVotingPower: bigint; }; @@ -112,46 +112,33 @@ export const ONE_YEAR = 365 * ONE_DAY; export type GaslessPluginVotingSettings = { minTallyApprovals: number; - minDuration: number; - expirationTime: number; + minVoteDuration: number; + minTallyDuration: number; minParticipation: number; supportThreshold: number; minProposerVotingPower: bigint; censusStrategy: string; daoTokenAddress?: string; // calculated during the DAO installation - onlyMultisigProposalCreation?: boolean; + onlyExecutionMultisigProposalCreation?: boolean; }; - -// export type GaslessProposalParamsOut = { -// censusBlock: number; -// securityBlock: number; -// startDate: Date; -// endDate: Date; -// expirationDate: Date; -// }; - -// export type GaslessProposalParams = { -// censusBlock: string[]; // following the multichain notation https://eips.ethereum.org/EIPS/eip-3770 -// securityBlock: number; // calculated internally in the smart contract -// startDate: number; -// endDate: number; -// expirationDate: number; // calculated internally in the smart contract based on expirationTime -// }; - export type GaslessProposalParametersStruct = { - censusBlock?: string[]; // following the multichain notation https://eips.ethereum.org/EIPS/eip-3770 securityBlock?: number; // calculated internally in the smart contract startDate?: Date; // UNIX timestamp (ms) - endDate: Date; // UNIX timestamp (ms) - expirationDate?: Date; // calculated internally in the smart contract based on expirationTime + voteEndDate: Date; // UNIX timestamp (ms) + tallyEndDate?: Date; // calculated internally in the smart contract based on minTallyDuration + totalVotingPower: bigint; // the total census voting power provided by the weight of the census in census3 + censusURI: string; // the URI of the census as provided by census3 + censusRoot: string; // the hex census root as provided by census3 }; export type GaslessProposalParametersContractStruct = { - censusBlock: string[]; securityBlock: bigint; startDate: bigint; - endDate: bigint; - expirationDate: bigint; + voteEndDate: bigint; + tallyEndDate: bigint; + totalVotingPower: bigint; + censusURI: string; + censusRoot: Uint8Array; }; export type GaslessVotingProposalFromSC = { @@ -165,7 +152,7 @@ export type GaslessVotingProposalFromSC = { }; export type GaslessVotingProposal = ProposalBase & { - expirationDate: Date; + tallyEndDate: Date; executed: boolean; approvers: string[]; vochainProposalId: string;