Skip to content

Commit

Permalink
fix: enable boost on shielded voting proposals (#4668)
Browse files Browse the repository at this point in the history
* fix: enable boost on shielded voting proposals

* Add ranked choice to boost

* Show boost on ranked choice

* remove comment

* fix: disable bribing for shutter and unsupported voting type

* fix: improve message

* fix: fix wrong contract function name

---------

Co-authored-by: ChaituVR <[email protected]>
  • Loading branch information
wa0x6e and ChaituVR authored Apr 23, 2024
1 parent ac12784 commit 48c4219
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
14 changes: 3 additions & 11 deletions src/components/SpaceCreateVoting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ExtendedSpace } from '@/helpers/interfaces';
import draggable from 'vuedraggable';
import SpaceCreateLegacyOsnap from './SpaceCreateLegacyOsnap.vue';
import SpaceCreateOsnap from './SpaceCreateOsnap.vue';
import { BOOST_ENABLED_VOTING_TYPES } from '@/helpers/constants';
const props = defineProps<{
space: ExtendedSpace;
Expand Down Expand Up @@ -122,20 +123,11 @@ defineEmits<{
/>
<template v-if="isWhitelisted(space.id)">
<BaseMessage
v-if="form.type !== 'single-choice' && form.type !== 'basic'"
v-if="!BOOST_ENABLED_VOTING_TYPES.includes(form.type)"
level="info"
class="mt-2 border bg-[--border-color-subtle] p-3 rounded-xl"
>
Note that Boost is not available for this voting type. Please use
Basic or Single Choice if you want to use Boost.
</BaseMessage>
<BaseMessage
v-else-if="space.voting.privacy === 'shutter'"
level="info"
class="mt-2 border bg-[--border-color-subtle] p-3 rounded-xl"
>
Note that Boost is not available with Shutter encrypted voting. Please
disable it in the space settings if you want to use Boost.
Note that Boost is not available for this voting type.
</BaseMessage>
</template>

Expand Down
2 changes: 1 addition & 1 deletion src/components/SpaceProposalBoost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function isEligible(boost: BoostSubgraph) {
const choice = boost.strategy.eligibility.choice;
if (!web3Account.value) return false;
if (props.proposal.privacy === 'shutter' && !isFinal.value) return false;
if (!isFinal.value) return false;
if (!userVote.value) return false;
if (choice === null) return true;
Expand Down
5 changes: 2 additions & 3 deletions src/components/SpaceProposalPage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import voting from '@snapshot-labs/snapshot.js/src/voting';
import { ExtendedSpace, Proposal, Results } from '@/helpers/interfaces';
import { BOOST_ENABLED_VOTING_TYPES } from '@/helpers/constants';
const props = defineProps<{ space: ExtendedSpace; proposal: Proposal }>();
const emit = defineEmits(['reload-proposal']);
Expand Down Expand Up @@ -56,9 +57,7 @@ const strategies = computed(
const boostEnabled = computed(() => {
return (
(props.proposal.type === 'basic' ||
props.proposal.type === 'single-choice') &&
props.proposal.privacy !== 'shutter' &&
BOOST_ENABLED_VOTING_TYPES.includes(props.proposal.type) &&
isWhitelisted(props.space.id) &&
props.space.boost.enabled
);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/boost/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export async function withdrawAndBurn(
): Promise<any> {
const signer = web3.getSigner();
const contract = new Contract(BOOST_CONTRACTS[networkId], ABI, signer);
return await contract.burn(boostId, to);
return await contract.withdrawAndBurn(boostId, to);
}

export async function getFees(web3: Web3Provider, networkId: string) {
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ export const TWO_WEEKS = 1209600;
export const ONE_DAY = 86400;

export const SNAPSHOT_HELP_LINK = 'https://help.snapshot.org/en';

export const BOOST_ENABLED_VOTING_TYPES = [
'basic',
'single-choice',
'ranked-choice'
];
40 changes: 32 additions & 8 deletions src/views/SpaceBoost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ const isWrongNetwork = computed(() => {
return form.value.network !== web3.value.network.key.toString();
});
const bribeEnabled = computed(() => {
return (
proposal.value.privacy !== 'shutter' &&
props.space.boost.bribeEnabled &&
['basic', 'single-choice'].includes(proposal.value.type)
);
});
const eligibilityOptions = computed(() => {
const proposalChoices = proposal.value?.choices.map(
(choice: string, index: number) => {
return {
value: index + 1,
label: `Who votes '${choice}'`,
extras: { disabled: !props.space.boost.bribeEnabled }
extras: {
disabled: !bribeEnabled.value
}
};
}
);
Expand Down Expand Up @@ -655,14 +665,28 @@ watch(
:items="eligibilityOptions"
label="Eligible to"
/>
<TuneBlockFooter v-if="!space.boost.bribeEnabled">
<TuneBlockFooter v-if="!bribeEnabled">
<BaseMessage level="info">
Selecting a specific choice is disabled for the
<span class="font-semibold">
{{ space.name }}
</span>
space. Please enable strategic incentivization in the space
settings to enable this feature.
<template v-if="!space.boost.bribeEnabled">
Selecting a specific choice is disabled for the
<span class="font-semibold">
{{ space.name }}
</span>
space. Please enable strategic incentivization in the space
settings to enable this feature.
</template>
<template v-else-if="proposal.privacy === 'shutter'">
Strategic incentivization is disabled for proposal with
shutter on.
</template>
<template
v-else-if="
!['basic', 'single-choice'].includes(proposal.type)
"
>
Strategic incentivization is available only for basic and
single choice voting type.
</template>
</BaseMessage>
</TuneBlockFooter>
</TuneBlock>
Expand Down

0 comments on commit 48c4219

Please sign in to comment.