Create a voting strategy
Learn how to create a new custom voting strategy.
Last updated
Was this helpful?
Learn how to create a new custom voting strategy.
Last updated
Was this helpful?
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:
Create a fork of the snapshot-strategies repository:
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.
There are several files you need to edit:
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:
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:
./snapshot-strategies/src/strategies/index.ts
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:
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.
Once you saved all the files run the below command with the name of your new strategy:
The review can take the team up to 72 hours, so please be patient 🙏
Import and declare you new strategy in the file:
It will trigger the tests which you can find in . If you get any errors read them carefully as they should point directly to the problem.
Ensure you meet the requirements for adding a new strategy by reviewing the checklist for adding a new strategy which can be found at:
Create a Pull Request with the above changes on the original repo.
After the PR has been merged, you will need to wait for the release of a new version of which can take a couple of days. Once it's deployed you can move on to the next step.
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!