npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@foresto/prop-house-communities

v1.0.2

Published

The `prop-house-community` package manages the voting strategies for Prop House communities.

Downloads

7

Readme

Description

The prop-house-community package manages the voting strategies for Prop House communities.

Development

Install dependencies

yarn

Build

yarn build

Usage

import { getNumVotes } from 'prop-house-communities';

const votes = await getNumVotes(address, communityAddress, provider, blockTag);

Strategies

Strategies can be found in the strategies/ directory. A strategy is a function that returns a function of Strategy type. Put another way, custom strategies are functions that return the implementation of the base Strategy type.

// base Strategy type
export type Strategy = (
  userAddress: string,
  communityAddress: string,
  blockTag: number,
  provider: Provider,
) => Promise<number>;

// example strategy
export const myCustomStrategy = (optionalParams: string): Strategy => {
  return async (
    userAddress: string
    communityAddress: string,
    blockTag: number,
    provider: Provider,
  ) => {
    // my custom implementation
    return numVotesForAddress
    };
};

Considerations:

  • Strategies may add additional parameters particular to the community (optional)
  • Strategies may use the ethers.js Provider to make calls on-chain
  • Strategies must return a Promise<number> denoting the number of votes the userAddress has for communityAddress at snapshot block blockTag.

Example

The balanceOfErc20 strategy requires two additional parameters (decimals and multiplier). It uses said parameters to implement and return a function of Strategy type.

export const balanceOfErc20 = (decimals: number, multiplier: number = 1): Strategy => {
  return async (
    userAddress: string,
    communityAddress: string,
    blockTag: number,
    provider: Provider,
  ) => {
    const contract = new Contract(communityAddress, BalanceOfABI, provider);
    const balance = await contract.balanceOf(userAddress, { blockTag: parseBlockTag(blockTag) });
    return new BigNumber(formatUnits(balance, decimals).toString()).times(multiplier).toNumber();
  };
};