From 1edd110d17a7d2a929382afb27b4c9d7fd4897d4 Mon Sep 17 00:00:00 2001 From: darklight81 Date: Sun, 5 Jan 2025 14:26:24 +0100 Subject: [PATCH 1/6] feat: added voting positions table --- ...ePositions.vue => TableOwnedPositions.vue} | 30 +- components/TableVotingPositions.vue | 431 ++++++++++++++++++ pages/index.vue | 19 +- utils/hooks.ts | 30 +- 4 files changed, 492 insertions(+), 18 deletions(-) rename components/{TablePositions.vue => TableOwnedPositions.vue} (95%) create mode 100644 components/TableVotingPositions.vue diff --git a/components/TablePositions.vue b/components/TableOwnedPositions.vue similarity index 95% rename from components/TablePositions.vue rename to components/TableOwnedPositions.vue index e80a763..e1b9934 100644 --- a/components/TablePositions.vue +++ b/components/TableOwnedPositions.vue @@ -51,12 +51,8 @@ - {{ formatSeconds(stake.duration) }} + {{ shortenAddress(stake.votingDelegate) }} - - ({{ stake.lockUpEpochs }} epochs) - - @@ -183,6 +188,14 @@ const isFetchingVotingPower = computed(() => votingPowerQuery.isLoading.value) const userStakesWithVotingPowerQuery = useUserStakesWithVotingPower(address, epoch, chainId) const userStakesWithVotingPower = computed(() => userStakesWithVotingPowerQuery.data.value) + +const userStakesWithVotingPowerFiltered = computed(() => userStakesWithVotingPower.value?.filter( stake => { + return address.value !== stake.owner +})) +const votingDelegationCount = computed(() => userStakesWithVotingPowerFiltered.value?.length ?? 0) +const hasAnyVotingDelegation = computed(() => votingDelegationCount.value > 0) + + const isFetchingUserStakesWithVotingPower = computed(() => userStakesWithVotingPowerQuery.isLoading.value) const votingMultiplier = computed(() => { @@ -238,7 +251,7 @@ const nextUnlockFormatted = computed(() => { const vestedTokensAmount = computed(() => { if (!vestingsQuery.data?.value?.length) { - return undefined + return undefined } let totalAmount = 0n diff --git a/utils/hooks.ts b/utils/hooks.ts index 0a5697b..8dd5286 100644 --- a/utils/hooks.ts +++ b/utils/hooks.ts @@ -1,5 +1,5 @@ import { useQuery } from "@tanstack/vue-query"; -import { erc20Abi, parseAbiItem, type Address } from "viem"; +import {erc20Abi, parseAbiItem, type Address, parseEventLogs} from "viem"; import { getLogs } from "viem/actions"; import { getClient, readContract } from "@wagmi/vue/actions"; import { EPOCH_CLOCK_ABI, VE_PWN_TOKEN_ABI } from "~/constants/abis"; @@ -23,6 +23,32 @@ export const useUserPwnBalance = (walletAddress: Ref
, chain }) } +export function useAllBeneficiaries(stakeIds: bigint[], chainId: Ref) { + return useQuery({ + queryKey: ['allBeneficiaries', stakeIds], + queryFn: async () => { + const client = getClient(wagmiAdapter.wagmiConfig) + const logs = await getLogs(client!, { + address: VE_PWN_TOKEN[chainId.value], + event: parseAbiItem('event StakePowerDelegated(uint256 indexed stakeId, address indexed originalBeneficiary, address indexed newBeneficiary)'), + fromBlock: 0n, + }) + + // Create a map of stakeId to latest beneficiary + const beneficiaryMap = new Map() + + for (const log of logs) { + if (stakeIds.includes(log.args.stakeId!)) { + beneficiaryMap.set(log.args.stakeId!, log.args.newBeneficiary || '') + } + } + + return beneficiaryMap + }, + enabled: stakeIds.length > 0 + }) +} + export const useUserStakes = (walletAddress: Ref
, chainId: Ref) => { return useQuery({ queryKey: ['stakedPwnBalance', walletAddress, chainId], @@ -155,7 +181,7 @@ export const useUserCumulativeVotingPowerSummary = (walletAddress: Ref
{ // Keep the number if it's not zero if (stakerPower.power !== 0n) return true; - + // If it's zero, check if there's a non-zero number ahead return parsedStakerPowers.slice(index + 1).some(_stakerPower => _stakerPower.power !== 0n); }); From 617247139c1434ca77459c68167b59d552fd91b1 Mon Sep 17 00:00:00 2001 From: darklight81 Date: Thu, 9 Jan 2025 03:17:24 +0100 Subject: [PATCH 2/6] fix: fixes from PR --- components/TableOwnedPositions.vue | 22 +++++++++---- components/TableVotingPositions.vue | 49 +++++------------------------ pages/index.vue | 2 +- 3 files changed, 25 insertions(+), 48 deletions(-) diff --git a/components/TableOwnedPositions.vue b/components/TableOwnedPositions.vue index e1b9934..34a2ad6 100644 --- a/components/TableOwnedPositions.vue +++ b/components/TableOwnedPositions.vue @@ -50,9 +50,17 @@ - + + + + ---