0.1.23 • Published 2 years ago
@prophouse/communities v0.1.23
Description
The prop-house-community package manages the voting strategies for Prop House communities.
Development
Install dependencies
yarnBuild
yarn buildUsage
import { getVotingPower } from '@prophouse/communities';
const votes = await getVotingPower(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
Providerto make calls on-chain - Strategies must return a
Promise<number>denoting the number of votes theuserAddresshas forcommunityAddressat snapshot blockblockTag.
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();
};
};0.1.14
2 years ago
0.1.15
2 years ago
0.1.20
2 years ago
0.1.21
2 years ago
0.1.22
2 years ago
0.1.23
2 years ago
0.1.16
2 years ago
0.1.17
2 years ago
0.1.18
2 years ago
0.1.19
2 years ago
0.1.13
3 years ago
0.1.12
3 years ago
0.1.11
3 years ago
0.1.10
3 years ago
0.1.9
3 years ago
0.1.8
3 years ago
0.1.7
3 years ago
0.1.6
3 years ago
0.1.5
3 years ago
0.1.4
3 years ago
0.1.3
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago