Custom calculations
If none of the above scenarios work for your use case, you can use the customizable Strategies to leverage your own custom calculation mechanisms. Read on to learn more!
Snapshot provides several Voting Strategies that allow you to use your own API to return user's Voting Power or for example perform mathematical calculations on the results from existing Strategies.
You can also create a new custom Voting or Validation Strategy if none of the available solutions meet your needs. Have a look at the Create a strategy section of this documentation to learn more!
This strategy allows off-chain data to be used as Voting Power through calling a custom API endpoint to request the score for a set of addresses.
It's useful to use this strategy if your API can return the Voting Power directly. It's network agnostic.
Strategy setup:
If you are passing an IPFS URL use the following format:
If you are passing a JSON URL use the following format:
If you are passing an API URL use the following format:
All voter addresses will be passed in the query string.
If you are passing a API URL with POST method use the following format:
You can test it out in the Playground on Snapshot:
You can use the math
strategy flexibly with various tokens and networks. This example demonstrates how to set a threshold taking into account tokens on different chains.
Math
strategy is powerful in its composability. It allows you to apply common mathematical operations to the outputs of Voting Strategies.
As an example, you can take a square root of the Voting Power calculated by erc20-balance-of, or the lower (min
) value out of two different Voting Strategies. You can see all possibilities on the strategy page.
How to set it up for a multichain scenario?
If the Voting Power calculated for your space is based on tokens on different chains and you want to set a minimum threshold defining if a user is eligible to vote, you can use the a-if-lt-b
operand. Don't worry if it sounds cryptic, we will go through it step by step.
Let's look at the formula first: (x, a, b) = x < b ? a : x
, where:
x - sum of Voting Power calculated by the two Voting Strategies on chains
137
and1
(as per the example below)a - first constant, in our case it's 0
b - first constant, in our case it's 100
Strategy setup:
The algorithm will check if x is smaller than b, the second constant:
if it's below b, the final Voting Power will be set to a, first constant -> 0
if it's equal to and higher than b, the final Voting Power will be set to x, the sum of result from the Voting Strategies
As you can see we can easily define what is the minimum Voting Power (our example: 100) coming from different chains that is required for the user to vote!
You can test it out in the Playground on Snapshot:
Strategy used in the example: multichain
Last updated