Create a voting strategy
Learn how to create a new custom voting strategy.
1. Fork the score-api repository
Not found
2. Duplicate the erc20-balance-of strategy folder
erc20-balance-of strategy folder└── src
└── strategies
└── strategies
└── erc20-balance-of3. Write the logic for your strategy
a. index.ts
index.ts
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';
export const author = 'bonustrack';
export const version = '0.1.1';
const abi = [
'function balanceOf(address account) external view returns (uint256)'
];
export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const multi = new Multicaller(network, provider, abi, { blockTag });
addresses.forEach((address) =>
multi.call(address, options.address, 'balanceOf', [address])
);
const result: Record<string, BigNumberish> = await multi.execute();
return Object.fromEntries(
Object.entries(result).map(([address, balance]) => [
address,
parseFloat(formatUnits(balance, options.decimals))
])
);
}b. schema.json
schema.jsond. ./score-api/src/strategies/strategies/index.ts
./score-api/src/strategies/strategies/index.tsd. examples.json
examples.jsone. README.md
README.md4. Test the strategy locally
5. Review the checklist
6. Create a pull request
7. Try it out!
Last updated
Was this helpful?
