fix(governance): fix willpassbylpvotecalculation (#5824)

This commit is contained in:
Edd 2024-02-20 16:10:44 +00:00 committed by GitHub
parent b8725a7fa8
commit a92fe92778
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 83 additions and 10 deletions

View File

@ -333,7 +333,6 @@ const VoteBreakDownUI = ({
noPercentage, noPercentage,
noLPPercentage, noLPPercentage,
yesPercentage, yesPercentage,
yesLPPercentage,
yesTokens, yesTokens,
noTokens, noTokens,
totalEquityLikeShareWeight, totalEquityLikeShareWeight,
@ -346,6 +345,7 @@ const VoteBreakDownUI = ({
majorityLPMet, majorityLPMet,
willPassByTokenVote, willPassByTokenVote,
willPassByLPVote, willPassByLPVote,
lpVoteWeight,
} = voteInfo; } = voteInfo;
const participationThresholdProgress = BigNumber.min( const participationThresholdProgress = BigNumber.min(
@ -425,7 +425,7 @@ const VoteBreakDownUI = ({
data-testid="lp-majority-breakdown" data-testid="lp-majority-breakdown"
> >
<VoteProgress <VoteProgress
percentageFor={yesLPPercentage} percentageFor={lpVoteWeight}
colourfulBg={true} colourfulBg={true}
testId="lp-majority-progress" testId="lp-majority-progress"
> >
@ -444,10 +444,10 @@ const VoteBreakDownUI = ({
<span>{t('liquidityProviderVotesFor')}:</span> <span>{t('liquidityProviderVotesFor')}:</span>
<Tooltip <Tooltip
description={ description={
<span>{yesLPPercentage.toFixed(defaultDP)}%</span> <span>{lpVoteWeight.toFixed(defaultDP)}%</span>
} }
> >
<button>{yesLPPercentage.toFixed(1)}%</button> <button>{lpVoteWeight.toFixed(1)}%</button>
</Tooltip> </Tooltip>
</div> </div>

View File

@ -273,4 +273,74 @@ describe('use-vote-information', () => {
expect(current?.willPassByTokenVote).toEqual(false); expect(current?.willPassByTokenVote).toEqual(false);
expect(current?.willPassByLPVote).toEqual(true); 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);
});
}); });

View File

@ -123,15 +123,19 @@ const getVoteData = (
totalSupply.multipliedBy(params.requiredParticipation) totalSupply.multipliedBy(params.requiredParticipation)
); );
const lpVoteWeight = yesEquityLikeShareWeight
.dividedBy(totalEquityLikeShareWeight)
.multipliedBy(100);
const participationLPMet = params.requiredParticipationLP const participationLPMet = params.requiredParticipationLP
? totalEquityLikeShareWeight.isGreaterThan(params.requiredParticipationLP) ? lpVoteWeight.isGreaterThan(params.requiredParticipationLP)
: false; : false;
const majorityMet = yesPercentage.isGreaterThanOrEqualTo( const majorityMet = yesPercentage.isGreaterThanOrEqualTo(
requiredMajorityPercentage requiredMajorityPercentage
); );
const majorityLPMet = yesLPPercentage.isGreaterThanOrEqualTo( const majorityLPMet = lpVoteWeight.isGreaterThanOrEqualTo(
requiredMajorityLPPercentage requiredMajorityLPPercentage
); );
@ -149,14 +153,12 @@ const getVoteData = (
const willPassByLPVote = const willPassByLPVote =
participationLPMet && participationLPMet &&
new BigNumber(yesLPPercentage).isGreaterThanOrEqualTo( lpVoteWeight.isGreaterThanOrEqualTo(requiredMajorityLPPercentage);
requiredMajorityLPPercentage
);
let willPass = false; let willPass = false;
if (changeType === 'UpdateMarket' || changeType === 'UpdateMarketState') { if (changeType === 'UpdateMarket' || changeType === 'UpdateMarketState') {
willPass = willPassByTokenVote && willPassByLPVote; willPass = willPassByTokenVote || willPassByLPVote;
} else { } else {
willPass = willPassByTokenVote; willPass = willPassByTokenVote;
} }
@ -182,6 +184,7 @@ const getVoteData = (
totalLPTokensPercentage, totalLPTokensPercentage,
willPassByTokenVote, willPassByTokenVote,
willPassByLPVote, willPassByLPVote,
lpVoteWeight: lpVoteWeight.isNaN() ? new BigNumber(0) : lpVoteWeight,
yesVotes: new BigNumber(votes.yes.totalNumber ?? 0), yesVotes: new BigNumber(votes.yes.totalNumber ?? 0),
noVotes: new BigNumber(votes.no.totalNumber ?? 0), noVotes: new BigNumber(votes.no.totalNumber ?? 0),
totalVotes: new BigNumber(votes.yes.totalNumber ?? 0).plus( totalVotes: new BigNumber(votes.yes.totalNumber ?? 0).plus(