From a92fe92778dfa6fba89e9b5d08b9fb050711166c Mon Sep 17 00:00:00 2001 From: Edd Date: Tue, 20 Feb 2024 16:10:44 +0000 Subject: [PATCH] fix(governance): fix willpassbylpvotecalculation (#5824) --- .../vote-breakdown/vote-breakdown.tsx | 8 +-- .../hooks/use-vote-information.spec.ts | 70 +++++++++++++++++++ .../proposals/hooks/use-vote-information.ts | 15 ++-- 3 files changed, 83 insertions(+), 10 deletions(-) diff --git a/apps/governance/src/routes/proposals/components/vote-breakdown/vote-breakdown.tsx b/apps/governance/src/routes/proposals/components/vote-breakdown/vote-breakdown.tsx index fc5963449..30a965bf1 100644 --- a/apps/governance/src/routes/proposals/components/vote-breakdown/vote-breakdown.tsx +++ b/apps/governance/src/routes/proposals/components/vote-breakdown/vote-breakdown.tsx @@ -333,7 +333,6 @@ const VoteBreakDownUI = ({ noPercentage, noLPPercentage, yesPercentage, - yesLPPercentage, yesTokens, noTokens, totalEquityLikeShareWeight, @@ -346,6 +345,7 @@ const VoteBreakDownUI = ({ majorityLPMet, willPassByTokenVote, willPassByLPVote, + lpVoteWeight, } = voteInfo; const participationThresholdProgress = BigNumber.min( @@ -425,7 +425,7 @@ const VoteBreakDownUI = ({ data-testid="lp-majority-breakdown" > @@ -444,10 +444,10 @@ const VoteBreakDownUI = ({ {t('liquidityProviderVotesFor')}: {yesLPPercentage.toFixed(defaultDP)}% + {lpVoteWeight.toFixed(defaultDP)}% } > - + diff --git a/apps/governance/src/routes/proposals/hooks/use-vote-information.spec.ts b/apps/governance/src/routes/proposals/hooks/use-vote-information.spec.ts index 07c82fb5a..adbf3a82c 100644 --- a/apps/governance/src/routes/proposals/hooks/use-vote-information.spec.ts +++ b/apps/governance/src/routes/proposals/hooks/use-vote-information.spec.ts @@ -273,4 +273,74 @@ describe('use-vote-information', () => { expect(current?.willPassByTokenVote).toEqual(false); expect(current?.willPassByLPVote).toEqual(true); }); + + it('mainnet recreation: only yes LP votes equal passing', () => { + const yesVotes = 0; + const noVotes = 70; + const yesEquityLikeShareWeight = '0.21'; + const noEquityLikeShareWeight = '0'; + const fixedTokenValue = 1000000000000000000; + + const proposal = generateProposal({ + terms: { + change: { + __typename: 'UpdateMarket', + marketId: '12345', + }, + }, + votes: { + __typename: 'ProposalVotes', + yes: generateYesVotes( + yesVotes, + fixedTokenValue, + yesEquityLikeShareWeight + ), + no: generateNoVotes(noVotes, fixedTokenValue, noEquityLikeShareWeight), + }, + }); + + const { + result: { current }, + } = renderHook(() => + useVoteInformation({ terms: proposal.terms, votes: proposal.votes }) + ); + + expect(current?.willPassByTokenVote).toEqual(false); + expect(current?.willPassByLPVote).toEqual(true); + }); + + it('mainnet recreation: mixed yes and no LP votes equal failing', () => { + const yesVotes = 0; + const noVotes = 70; + const yesEquityLikeShareWeight = '0.21'; + const noEquityLikeShareWeight = '0.22'; + const fixedTokenValue = 1000000000000000000; + + const proposal = generateProposal({ + terms: { + change: { + __typename: 'UpdateMarket', + marketId: '12345', + }, + }, + votes: { + __typename: 'ProposalVotes', + yes: generateYesVotes( + yesVotes, + fixedTokenValue, + yesEquityLikeShareWeight + ), + no: generateNoVotes(noVotes, fixedTokenValue, noEquityLikeShareWeight), + }, + }); + + const { + result: { current }, + } = renderHook(() => + useVoteInformation({ terms: proposal.terms, votes: proposal.votes }) + ); + + expect(current?.willPassByTokenVote).toEqual(false); + expect(current?.willPassByLPVote).toEqual(false); + }); }); diff --git a/apps/governance/src/routes/proposals/hooks/use-vote-information.ts b/apps/governance/src/routes/proposals/hooks/use-vote-information.ts index 4e0e92435..e3abf86e9 100644 --- a/apps/governance/src/routes/proposals/hooks/use-vote-information.ts +++ b/apps/governance/src/routes/proposals/hooks/use-vote-information.ts @@ -123,15 +123,19 @@ const getVoteData = ( totalSupply.multipliedBy(params.requiredParticipation) ); + const lpVoteWeight = yesEquityLikeShareWeight + .dividedBy(totalEquityLikeShareWeight) + .multipliedBy(100); + const participationLPMet = params.requiredParticipationLP - ? totalEquityLikeShareWeight.isGreaterThan(params.requiredParticipationLP) + ? lpVoteWeight.isGreaterThan(params.requiredParticipationLP) : false; const majorityMet = yesPercentage.isGreaterThanOrEqualTo( requiredMajorityPercentage ); - const majorityLPMet = yesLPPercentage.isGreaterThanOrEqualTo( + const majorityLPMet = lpVoteWeight.isGreaterThanOrEqualTo( requiredMajorityLPPercentage ); @@ -149,14 +153,12 @@ const getVoteData = ( const willPassByLPVote = participationLPMet && - new BigNumber(yesLPPercentage).isGreaterThanOrEqualTo( - requiredMajorityLPPercentage - ); + lpVoteWeight.isGreaterThanOrEqualTo(requiredMajorityLPPercentage); let willPass = false; if (changeType === 'UpdateMarket' || changeType === 'UpdateMarketState') { - willPass = willPassByTokenVote && willPassByLPVote; + willPass = willPassByTokenVote || willPassByLPVote; } else { willPass = willPassByTokenVote; } @@ -182,6 +184,7 @@ const getVoteData = ( totalLPTokensPercentage, willPassByTokenVote, willPassByLPVote, + lpVoteWeight: lpVoteWeight.isNaN() ? new BigNumber(0) : lpVoteWeight, yesVotes: new BigNumber(votes.yes.totalNumber ?? 0), noVotes: new BigNumber(votes.no.totalNumber ?? 0), totalVotes: new BigNumber(votes.yes.totalNumber ?? 0).plus(