Create a voting strategy
Learn how to create a new custom voting strategy.
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
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.
3. Write the logic for your strategy
There are several files you need to edit:
a. index.ts
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:
b. schema.json
schema.json
Describe the structure of your strategy by editing the properties
, required
and additionalProperties
key-value pairs according to the logic from index.ts
file:
d. ./snapshot-strategies/src/strategies/index.ts
./snapshot-strategies/src/strategies/index.ts
Import and declare you new strategy in the index.ts
file:
d. examples.json
examples.json
Provide an example for the custom strategy setup which will be displayed on https://snapshot.org on the strategy's details page.
Make sure to include all the parameters you defined above and a list of addresses to test against:
e. README.md
README.md
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.
4. Test the strategy locally
Once you saved all the files run the below command with the name of your new strategy:
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.
5. Review the checklist
Ensure you meet the requirements for adding a new strategy by reviewing the checklist for adding a new strategy which can be found at: https://github.com/snapshot-labs/snapshot-strategies#checklist-for-adding-a-new-strategy
6. Create a pull request
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!
Last updated