Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Governance: time to vote eneded calculates with cool off time #579

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions packages/governance-sdk/src/governance/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export class GovernanceConfig {

minCommunityTokensToCreateProposal: BN;
minInstructionHoldUpTime: number;
maxVotingTime: number;
baseVotingTime: number;
communityVoteTipping: VoteTipping;
minCouncilTokensToCreateProposal: BN;

Expand All @@ -467,24 +467,24 @@ export class GovernanceConfig {
communityVoteThreshold: VoteThreshold;
minCommunityTokensToCreateProposal: BN;
minInstructionHoldUpTime: number;
maxVotingTime: number;
baseVotingTime: number;
communityVoteTipping?: VoteTipping;
minCouncilTokensToCreateProposal: BN;

// VERSION >= 3
// For versions < 3 must be set to YesVotePercentage(0)
councilVoteThreshold: VoteThreshold;
councilVetoVoteThreshold: VoteThreshold;
communityVetoVoteThreshold: VoteThreshold;
councilVoteTipping: VoteTipping;
votingCoolOffTime: number;
depositExemptProposalCount: number;
councilVoteThreshold?: VoteThreshold;
councilVetoVoteThreshold?: VoteThreshold;
communityVetoVoteThreshold?: VoteThreshold;
councilVoteTipping?: VoteTipping;
votingCoolOffTime?: number;
depositExemptProposalCount?: number;
}) {
this.communityVoteThreshold = args.communityVoteThreshold;
this.minCommunityTokensToCreateProposal =
args.minCommunityTokensToCreateProposal;
this.minInstructionHoldUpTime = args.minInstructionHoldUpTime;
this.maxVotingTime = args.maxVotingTime;
this.baseVotingTime = args.baseVotingTime;
this.communityVoteTipping = args.communityVoteTipping ?? VoteTipping.Strict;
this.minCouncilTokensToCreateProposal =
args.minCouncilTokensToCreateProposal;
Expand All @@ -502,8 +502,12 @@ export class GovernanceConfig {
this.councilVoteTipping =
args.councilVoteTipping ?? this.communityVoteTipping;

this.votingCoolOffTime = args.votingCoolOffTime;
this.depositExemptProposalCount = args.depositExemptProposalCount;
this.votingCoolOffTime = args.votingCoolOffTime ?? 0;
this.depositExemptProposalCount = args.depositExemptProposalCount ?? 0;
}

get maxVotingTime() {
return this.baseVotingTime + this.votingCoolOffTime;
}
}

Expand Down Expand Up @@ -946,12 +950,12 @@ export class Proposal {
return this.isPreVotingState()
? governance.config.maxVotingTime
: (this.votingAt?.toNumber() ?? 0) +
governance.config.maxVotingTime -
governance.config.maxVotingTime +
unixTimestampInSeconds;
}

hasVoteTimeEnded(governance: Governance) {
return this.getTimeToVoteEnd(governance) <= 0;
return this.getTimeToVoteEnd(governance) < 0;
}

canCancel(governance: Governance) {
Expand Down
4 changes: 2 additions & 2 deletions packages/governance-sdk/src/governance/serialisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function createGovernanceStructSchema(
['communityVoteThreshold', 'VoteThreshold'],
['minCommunityTokensToCreateProposal', 'u64'],
['minInstructionHoldUpTime', 'u32'],
['maxVotingTime', 'u32'],
['baseVotingTime', 'u32'],
['communityVoteTipping', 'u8'],
['councilVoteThreshold', 'VoteThreshold'],
['councilVetoVoteThreshold', 'VoteThreshold'],
Expand Down Expand Up @@ -832,7 +832,7 @@ function createGovernanceAccountSchema(accountVersion: number) {

...(accountVersion === ACCOUNT_VERSION_V1
? []
: [['maxVotingTime', { kind: 'option', type: 'u32' }]]),
: [['baseVotingTime', { kind: 'option', type: 'u32' }]]),

['voteThreshold', { kind: 'option', type: 'VoteThreshold' }],

Expand Down
2 changes: 1 addition & 1 deletion packages/governance-sdk/tests/chat/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test('postProposalComment', async () => {
}),
minCommunityTokensToCreateProposal: new BN(1),
minInstructionHoldUpTime: 0,
maxVotingTime: getTimestampFromDays(3),
baseVotingTime: getTimestampFromDays(3),
voteTipping: VoteTipping.Strict,
councilVoteThreshold: new VoteThreshold({
type: VoteThresholdType.Disabled,
Expand Down
2 changes: 1 addition & 1 deletion packages/governance-sdk/tests/governance/api.smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ test('setupRealm', async () => {
communityVoteThreshold: communityVoteThreshold,
minCommunityTokensToCreateProposal: new BN(1),
minInstructionHoldUpTime: 0,
maxVotingTime: getTimestampFromDays(3),
baseVotingTime: getTimestampFromDays(3),
communityVoteTipping: VoteTipping.Strict,
councilVoteTipping: VoteTipping.Strict,
minCouncilTokensToCreateProposal: new BN(1),
Expand Down
2 changes: 1 addition & 1 deletion packages/governance-sdk/tests/governance/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ test('createRealmWithGovernanceAndProposal', async () => {
communityVoteThreshold: communityVoteThreshold,
minCommunityTokensToCreateProposal: new BN(1),
minInstructionHoldUpTime: 0,
maxVotingTime: getTimestampFromDays(3),
baseVotingTime: getTimestampFromDays(3),
communityVoteTipping: VoteTipping.Strict,
councilVoteTipping: VoteTipping.Strict,
minCouncilTokensToCreateProposal: new BN(1),
Expand Down
2 changes: 1 addition & 1 deletion packages/governance-sdk/tests/governance/api.v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('createGovernanceWithConfig', async () => {
}),
minCommunityTokensToCreateProposal: new BN(1),
minInstructionHoldUpTime: 0,
maxVotingTime: getTimestampFromDays(3),
baseVotingTime: getTimestampFromDays(3),
communityVoteTipping: VoteTipping.Strict,
councilVoteTipping: VoteTipping.Strict,
minCouncilTokensToCreateProposal: new BN(1),
Expand Down
2 changes: 1 addition & 1 deletion packages/governance-sdk/tests/governance/api.v3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test('createGovernanceWithConfig', async () => {
}),
minCommunityTokensToCreateProposal: new BN(1),
minInstructionHoldUpTime: 0,
maxVotingTime: getTimestampFromDays(3),
baseVotingTime: getTimestampFromDays(3),
communityVoteTipping: VoteTipping.Strict,
councilVoteTipping: VoteTipping.Strict,
minCouncilTokensToCreateProposal: new BN(1),
Expand Down
2 changes: 1 addition & 1 deletion packages/governance-sdk/tests/tools/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export class RealmBuilder {
}),
minCommunityTokensToCreateProposal: new BN(1),
minInstructionHoldUpTime: 0,
maxVotingTime: getTimestampFromDays(3),
baseVotingTime: getTimestampFromDays(3),
communityVoteTipping: VoteTipping.Strict,
councilVoteTipping: VoteTipping.Strict,
minCouncilTokensToCreateProposal: new BN(1),
Expand Down