Skip to content

Commit

Permalink
Fix types and add burn function
Browse files Browse the repository at this point in the history
  • Loading branch information
samuveth committed Jan 22, 2024
1 parent 1633b87 commit fc7ecfb
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 107 deletions.
22 changes: 13 additions & 9 deletions src/components/SpaceProposalBoost.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<script setup lang="ts">
import { getClaims, getBoosts } from '@/helpers/boost/subgraph';
import { SUPPORTED_NETWORKS } from '@/helpers/boost';
import { Proposal, BoostSubgraphResult } from '@/helpers/interfaces';
import { Proposal } from '@/helpers/interfaces';
import { useStorage } from '@vueuse/core';
import { getAddress } from '@ethersproject/address';
import { getRewards, Reward } from '@/helpers/boost/api';
import { BoostClaimSubgraph } from '@/helpers/boost/types';
import { getRewards } from '@/helpers/boost/api';
import {
BoostClaimSubgraph,
BoostRewardGuard,
BoostSubgraph
} from '@/helpers/boost/types';
const props = defineProps<{
proposal: Proposal;
}>();
const createModalOpen = ref(false);
const boostsModalOpen = ref(false);
const boosts = ref<BoostSubgraphResult[]>([]);
const boosts = ref<BoostSubgraph[]>([]);
const claims = ref<BoostClaimSubgraph[]>([]);
const loaded = ref(false);
const loadingRewards = ref(false);
const boostRewards = ref<Reward[]>([]);
const boostRewards = ref<BoostRewardGuard[]>([]);
const router = useRouter();
const { formatRelativeTime, longRelativeTimeFormatter } = useIntl();
Expand All @@ -36,7 +40,7 @@ const newBoostLink = computed(() => ({
const isActive = computed(() => props.proposal.state === 'active');
const isFinal = computed(() => props.proposal.scores_state === 'final');
function isEligible(boost: BoostSubgraphResult) {
function isEligible(boost: BoostSubgraph) {
const choice = boost.strategy.eligibility.choice;
if (!web3Account.value) return false;
Expand All @@ -62,9 +66,9 @@ const hasUserClaimed = computed(() => {
const boostsSorted = computed(() => {
if (!boosts.value.length) return [];
const eligible: BoostSubgraphResult[] = [];
const claimed: BoostSubgraphResult[] = [];
const other: BoostSubgraphResult[] = [];
const eligible: BoostSubgraph[] = [];
const claimed: BoostSubgraph[] = [];
const other: BoostSubgraph[] = [];
boosts.value.forEach(boost => {
const isClaimed = claims.value.some(claim => claim.boost.id === boost.id);
Expand Down
11 changes: 6 additions & 5 deletions src/components/SpaceProposalBoostClaim.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<script setup lang="ts">
import { Proposal, BoostSubgraphResult } from '@/helpers/interfaces';
import { getVouchers, Reward } from '@/helpers/boost/api';
import { Proposal } from '@/helpers/interfaces';
import { getVouchers } from '@/helpers/boost/api';
import { formatUnits } from '@ethersproject/units';
import { claimAllTokens } from '@/helpers/boost';
import { getAddress } from '@ethersproject/address';
import { getInstance } from '@snapshot-labs/lock/plugins/vue3';
import { BoostRewardGuard, BoostSubgraph } from '@/helpers/boost/types';
const props = defineProps<{
proposal: Proposal;
boosts: BoostSubgraphResult[];
eligibleBoosts: BoostSubgraphResult[];
boosts: BoostSubgraph[];
eligibleBoosts: BoostSubgraph[];
hasUserClaimed: boolean;
rewards: Reward[];
rewards: BoostRewardGuard[];
loadingRewards: boolean;
}>();
Expand Down
13 changes: 8 additions & 5 deletions src/components/SpaceProposalBoostItem.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<script setup lang="ts">
import { Proposal, BoostSubgraphResult } from '@/helpers/interfaces';
import { Proposal } from '@/helpers/interfaces';
import { formatUnits } from '@ethersproject/units';
import { Reward } from '@/helpers/boost/api';
import { BoostClaimSubgraph } from '@/helpers/boost/types';
import {
BoostClaimSubgraph,
BoostRewardGuard,
BoostSubgraph
} from '@/helpers/boost/types';
const props = defineProps<{
proposal: Proposal;
boost: BoostSubgraphResult;
boost: BoostSubgraph;
claims?: BoostClaimSubgraph[];
web3Account: string;
isEligible?: boolean;
reward?: Reward;
reward?: BoostRewardGuard;
}>();
const { formatNumber, getNumberFormatter } = useIntl();
Expand Down
4 changes: 2 additions & 2 deletions src/components/SpaceProposalBoostItemMenu.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { BoostSubgraphResult } from '@/helpers/interfaces';
import { BoostSubgraph } from '@/helpers/boost/types';
import { explorerUrl } from '@/helpers/utils';
import { openProfile } from '@/helpers/utils';
const props = defineProps<{
boost: BoostSubgraphResult;
boost: BoostSubgraph;
}>();
const { domain } = useApp();
Expand Down
17 changes: 10 additions & 7 deletions src/components/SpaceProposalBoostModalBoosts.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<script setup lang="ts">
import { BoostSubgraphResult, Proposal } from '@/helpers/interfaces';
import { Reward } from '@/helpers/boost/api';
import { BoostClaimSubgraph } from '@/helpers/boost/types';
import { Proposal } from '@/helpers/interfaces';
import {
BoostClaimSubgraph,
BoostRewardGuard,
BoostSubgraph
} from '@/helpers/boost/types';
defineProps<{
open: boolean;
boosts: BoostSubgraphResult[];
boostsOwner: BoostSubgraphResult[];
boosts: BoostSubgraph[];
boostsOwner: BoostSubgraph[];
claims: BoostClaimSubgraph[];
proposal: Proposal;
rewards: Reward[];
isEligible: (boost: BoostSubgraphResult) => boolean;
rewards: BoostRewardGuard[];
isEligible: (boost: BoostSubgraph) => boolean;
}>();
defineEmits(['close']);
Expand Down
15 changes: 11 additions & 4 deletions src/components/SpaceProposalBoostOwner.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<script setup lang="ts">
import { Proposal, BoostSubgraphResult } from '@/helpers/interfaces';
import { Proposal } from '@/helpers/interfaces';
import { formatUnits } from '@ethersproject/units';
import { withdrawAndBurn } from '@/helpers/boost';
import { getInstance } from '@snapshot-labs/lock/plugins/vue3';
import { BoostSubgraph } from '@/helpers/boost/types';
defineProps<{
boosts: BoostSubgraphResult[];
boosts: BoostSubgraph[];
proposal: Proposal;
}>();
const auth = getInstance();
const { formatNumber, getNumberFormatter, formatDuration } = useIntl();
const { web3Account } = useWeb3();
function claimPeriodEnded(boost: BoostSubgraphResult) {
function claimPeriodEnded(boost: BoostSubgraph) {
return Number(boost.end) < Date.now() / 1000;
}
function withdrawalAmount(boost: BoostSubgraphResult) {
function withdrawalAmount(boost: BoostSubgraph) {
const formattedUnits = formatUnits(
boost.currentBalance,
boost.token.decimals
Expand Down Expand Up @@ -57,6 +61,9 @@ function withdrawalAmount(boost: BoostSubgraphResult) {

<TuneButton
class="h-5 px-[12px] text-skin-link bg-skin-bg w-full sm:w-auto mt-2 sm:mt-0"
@click="
withdrawAndBurn(auth.web3, boost.chainId, boost.id, web3Account)
"
>
Withdraw {{ withdrawalAmount(boost) }} {{ boost.token.symbol }}
</TuneButton>
Expand Down
19 changes: 4 additions & 15 deletions src/helpers/boost/api.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
type Boosts = string[][];

export type Reward = {
boost_id: string;
chain_id: string;
reward: string;
};
import { BoostRewardGuard, BoostVoucherGuard } from '@/helpers/boost/types';

export type Voucher = {
boost_id: string;
chain_id: string;
signature: string;
reward: string;
};
type Boosts = string[][];

export async function getRewards(
proposal_id: string,
voter_address: string,
boosts: Boosts
): Promise<Reward[]> {
): Promise<BoostRewardGuard[]> {
const results = await fetch(
'https://boost-guard-djc2x.ondigitalocean.app/get-rewards',
{
Expand All @@ -41,7 +30,7 @@ export async function getVouchers(
proposal_id: string,
voter_address: string,
boosts: Boosts
): Promise<Voucher[]> {
): Promise<BoostVoucherGuard[]> {
const results = await fetch(
'https://boost-guard-djc2x.ondigitalocean.app/create-vouchers',
{
Expand Down
33 changes: 21 additions & 12 deletions src/helpers/boost/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Web3Provider } from '@ethersproject/providers';
import { Contract } from '@ethersproject/contracts';
import { parseEther } from '@ethersproject/units';
import { pin } from '@snapshot-labs/pineapple';
import { BoostStrategy } from '@/helpers/interfaces';
import { BoostStrategy } from '@/helpers/boost/types';
import ABI from './abi.json';

export const BOOST_CONTRACTS = {
Expand All @@ -14,20 +14,18 @@ export const SUPPORTED_NETWORKS = Object.keys(BOOST_CONTRACTS);
export const SNAPSHOT_GUARD_ADDRESS =
'0x06A85356DCb5b307096726FB86A78c59D38e08ee';

interface Boost {
strategyURI: string;
token: string;
amount: string;
owner: string;
guard: string;
start: number;
end: number;
}

export async function createBoost(
web3: Web3Provider,
networkId: string,
params: Boost
params: {
strategyURI: string;
token: string;
amount: string;
owner: string;
guard: string;
start: number;
end: number;
}
): Promise<any> {
const { strategyURI, token, amount, guard, start, end, owner } = params;
const signer = web3.getSigner();
Expand Down Expand Up @@ -88,3 +86,14 @@ export async function getStrategyURI(strategy: BoostStrategy) {
const { cid } = await pin(strategy);
return `ipfs://${cid}`;
}

export async function withdrawAndBurn(
web3: Web3Provider,
networkId: string,
boostId: string,
to: string
): Promise<any> {
const signer = web3.getSigner();
const contract = new Contract(BOOST_CONTRACTS[networkId], ABI, signer);
return await contract.burn(boostId, to);
}
60 changes: 60 additions & 0 deletions src/helpers/boost/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,63 @@ export type BoostClaimSubgraph = {
id: string;
};
};

export type BoostRewardGuard = {
boost_id: string;
chain_id: string;
reward: string;
};

export type BoostVoucherGuard = {
boost_id: string;
chain_id: string;
signature: string;
reward: string;
};

export interface BoostStrategy {
name: string;
params: {
proposal: string;
eligibility: {
choice?: number;
};
distribution: {
type: 'even' | 'weighted';
limit?: number;
};
};
}

export type BoostSubgraph = {
id: string;
strategyURI: string;
poolSize: string;
guard: string;
start: string;
end: string;
owner: string;
chainId: string;
currentBalance: string;
transaction: string;
token: {
id: string;
name: string;
symbol: string;
decimals: string;
};
strategy: {
id: string;
version: string;
name: string;
proposal: string;
eligibility: {
type: 'incentive' | 'bribe';
choice: number | null;
};
distribution: {
type: 'even' | 'weighted';
limit: number | null;
};
};
};
47 changes: 0 additions & 47 deletions src/helpers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,50 +415,3 @@ export type DelegatesProposal = {
author: string;
title: string;
};

export interface BoostStrategy {
name: string;
params: {
proposal: string;
eligibility: {
choice?: number;
};
distribution: {
type: 'even' | 'weighted';
limit?: number;
};
};
}

export type BoostSubgraphResult = {
id: string;
strategyURI: string;
poolSize: string;
guard: string;
start: string;
end: string;
owner: string;
chainId: string;
currentBalance: string;
transaction: string;
token: {
id: string;
name: string;
symbol: string;
decimals: string;
};
strategy: {
id: string;
version: string;
name: string;
proposal: string;
eligibility: {
type: 'incentive' | 'bribe';
choice: number | null;
};
distribution: {
type: 'even' | 'weighted';
limit: number | null;
};
};
};
Loading

0 comments on commit fc7ecfb

Please sign in to comment.