Skip to content

Commit

Permalink
BREAKING: Updates to new smart contracts
Browse files Browse the repository at this point in the history
onlyMultisigProposalCreation -> onlyExecutionMultisigProposalCreation
minDuration -> minVoteDuration
expirationTime -> minTallyDuration
censusBlock desaparece
createProposal now needs:
	totalVotingPower -> census weight
        censusURI
        censusRoot
  • Loading branch information
emmdim committed Nov 7, 2023
1 parent f40532f commit dfd4f71
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 67 deletions.
2 changes: 1 addition & 1 deletion packages/contracts-ethers/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/js-client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
},
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions packages/js-client/src/internal/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const INSTALLATION_ABI: MetadataAbiInput[] = [
components: [
{
internalType: 'bool',
name: 'onlyCommitteeProposalCreation',
name: 'onlyExecutionMultisigProposalCreation',
type: 'bool',
description: '',
},
Expand All @@ -98,7 +98,7 @@ export const INSTALLATION_ABI: MetadataAbiInput[] = [
},
{
internalType: 'uint64',
name: 'minDuration',
name: 'minVoteDuration',
type: 'uint64',
description: '',
},
Expand All @@ -116,7 +116,7 @@ export const INSTALLATION_ABI: MetadataAbiInput[] = [
},
{
internalType: 'string',
name: 'censusStrategy',
name: 'censusStrategyURI',
type: 'string',
description: '',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/js-client/src/internal/graphql-queries/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const QueryTokenVotingProposal = gql`
votingMode
supportThreshold
startDate
endDate
voteEndDate
executed
earlyExecutable
potentiallyExecutable
Expand Down Expand Up @@ -89,7 +89,7 @@ export const QueryTokenVotingProposals = gql`
no
abstain
startDate
endDate
voteEndDate
executed
earlyExecutable
potentiallyExecutable
Expand Down
13 changes: 8 additions & 5 deletions packages/js-client/src/internal/modules/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
]
);
Expand Down
12 changes: 7 additions & 5 deletions packages/js-client/src/internal/modules/estimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 8 additions & 6 deletions packages/js-client/src/internal/modules/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -665,7 +667,7 @@ export class GaslessVotingClientMethods
signer
);

return tokenVotingContract.isCommitteeMember(memberAddress);
return tokenVotingContract.isExecutionMultisigMember(memberAddress);
}

/**
Expand Down
30 changes: 16 additions & 14 deletions packages/js-client/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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],
Expand All @@ -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,
};
}

Expand All @@ -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),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
43 changes: 15 additions & 28 deletions packages/js-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export type VotingSettings = {
votingMode: number;
supportThreshold: number;
minParticipation: number;
minDuration: bigint;
minVoteDuration: bigint;
minProposerVotingPower: bigint;
};

Expand All @@ -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 = {
Expand All @@ -165,7 +152,7 @@ export type GaslessVotingProposalFromSC = {
};

export type GaslessVotingProposal = ProposalBase & {
expirationDate: Date;
tallyEndDate: Date;
executed: boolean;
approvers: string[];
vochainProposalId: string;
Expand Down

0 comments on commit dfd4f71

Please sign in to comment.