Skip to content

Commit

Permalink
Added query to dao-voting-cw721-staked to map staked NFT token ID to …
Browse files Browse the repository at this point in the history
…staker address.
  • Loading branch information
NoahSaso committed Dec 4, 2023
1 parent 46a5da6 commit 2420a8e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/data/formulas/contract/voting/daoVotingCw721Staked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,49 @@ export const topStakers: ContractFormula<
return stakers
},
}

// Map NFT token ID to staker.
export const ownersOfStakedNfts: ContractFormula<Record<string, string>> = {
filter: {
codeIdsKeys: CODE_IDS_KEYS,
},
compute: async (env) => {
const { contractAddress, getTransformationMap } = env

const stakedCountMap =
(await getTransformationMap<string, string>(
contractAddress,
'stakedCount'
)) ?? {}
const stakers = Object.entries(stakedCountMap)
// Remove zero counts.
.filter(([, stakedCount]) => Number(stakedCount) > 0)
.map(([address]) => address)

const stakedNftsPerStaker = await Promise.all(
stakers.map(async (address) => ({
address,
tokenIds: await stakedNfts.compute({
...env,
args: {
address,
},
}),
}))
)

return stakedNftsPerStaker.reduce(
(acc, { address, tokenIds }) => ({
...acc,
...tokenIds.reduce(
(acc, tokenId) => ({
...acc,
[tokenId]: address,
}),
{} as Record<string, string>
),
}),
{} as Record<string, string>
)
},
}

0 comments on commit 2420a8e

Please sign in to comment.