If you can't find a strategy that fits your the needs of your space you can create a new custom one. Follow the steps below to learn how to do that:
1. Fork the snapshot-strategies repository
Create a fork of the snapshot-strategies repository:
2. Duplicate the erc20-balance-of strategy folder
Navigate to strategies directory, duplicate the erc20-balance-of directory and rename it to the chosen name for your new strategy.
└──src└──strategies└──erc20-balance-of
3. Write the logic for your strategy
There are several files you need to edit:
a. index.ts
This file defines the logic for calculation of the voting power. As an example, the erc20-balance-of is taking as parameters space, network, provider, addresses, options and snapshot in order to be able to retrieve the balances of the token specified in the options parameter for the provided addresses:
Describe the structure of your strategy by editing the properties, required and additionalProperties key-value pairs according to the logic from index.ts file:
Write the description of how the strategy works and provide an example of the setup. It will be displayed on the strategy's details page.
This is the most common strategy, it returns the balances of the voters for a specific ERC20 token.
Here is an example of parameters:
{
"address": "0x6b175474e89094c44da98b954eedeac495271d0f",
"symbol": "DAI",
"decimals": 18
}
4. Test the strategy locally
Once you saved all the files run the below command with the name of your new strategy:
npm run test --strategy=<STRATEGYNAME> // replace <STRATEGYNAME>
It will trigger the tests which you can find in this file. If you get any errors read them carefully as they should point directly to the problem.
Create a Pull Request with the above changes on the original snapshot-strategies repo.
The review can take the team up to 72 hours, so please be patient 🙏
After the PR has been merged, you will need to wait for the release of a new version of Snapshot which can take a couple of days. Once it's deployed you can move on to the next step.
7. Try it out!
Head to the strategy's details page and click Playground button. Follow the instructions from to see if it works as you intended.
Congrats, you've just added a new custom voting strategy!