Introduction
This task aims to find ways to enable community members can vote with multiple tokens in a Snapshot space. It provides an in-depth analysis of the different strategies and considerations involved in allowing voting with multiple ERC1155 tokens. The discussion includes the possibility of voting with different token types, the configuration of voting strategies, and the implementation process for custom strategies. This can be helpful for voting with Respect from different seasons or auxiliary tokens, such as OPC.
Table of Contents
- Introduction
- Does snapshot allow you to vote with different tokens in the same space? For example, could you vote with two different ERC1155 NFTs or 2 different ERC 20 tokens? If so, how would this work? Would you be able to or required to vote with each type of token independently? Or would you automatically vote with full voting power of both tokens combined? Would the UI show the amount voted for both tokens after voting? Is it possible to set different weights for different tokens (ie 2x voting power for one ERC1155 collection and 1x for another)?
- Provide any other details that may be helpful to get started doing this. For example, how much time, effort, or resources may be requiredto set up the custom voting strategy? Is there any shortcut? Can this be done with more than two tokens (ie 3,4, or 10 tokens)? Provide Javascript code to write the custom strategy. Point out any parts that would need to be modified or considered to make it work properly and how much additional work would be required
- Steps to Set Up a Custom Voting Strategy
- Time, Effort, and Resources
- Shortcut
- Custom Strategy Example
- Modifications and Considerations
- Additional Work Required
- Provide detailed javascript code snippet that works with ERC1155 and instructions to make it as quick as possible for a developer to get started. If a talented developer has these code snippet and instructions, then how fast could it be done?
- JavaScript Code Snippet for ERC-1155 Voting Strategy
- Necessary Modifications and Considerations
- Instructions to Get Started Quickly
- Time Estimate for a Talented Developer
- Are there any existing frameworks or strategies that might help make this quicker with multiple ERC1155 tokens?
- Does this mean that custom development isn't needed and we can just use one of these strategies? Which strategy is most fitting for the use case described above?
- What steps would be needed to implement the strategy for ERC1155 With Multiplier (erc1155-with-multiplier)?
Does snapshot allow you to vote with different tokens in the same space? For example, could you vote with two different ERC1155 NFTs or 2 different ERC 20 tokens? If so, how would this work? Would you be able to or required to vote with each type of token independently? Or would you automatically vote with full voting power of both tokens combined? Would the UI show the amount voted for both tokens after voting? Is it possible to set different weights for different tokens (ie 2x voting power for one ERC1155 collection and 1x for another)?
Yes, Snapshot does allow you to vote with different types of tokens within the same space, including different ERC-1155 NFTs or different ERC-20 tokens. This capability is made possible through the use of custom voting strategies within a Snapshot space.
How It Works:
- Custom Voting Strategies: Space administrators can configure custom voting strategies that define how voting power is calculated. These strategies can be set up to include various types of tokens, such as ERC-20 or ERC-1155 tokens, and can even combine multiple token types within the same voting proposal.
- Independent or Combined Voting: The way tokens contribute to voting power can vary based on the strategy configured by the space:
- Independent Voting: Each token type could count independently, meaning votes are cast separately based on the holdings of each token type.
- Combined Voting: Voting power can be aggregated from different tokens, where the contributions of each token type are summed to determine the total voting power of a participant.
- User Interface (UI) Feedback: After voting, the Snapshot UI typically displays the voting power used, but the detail level (e.g., breakdown by token type) depends on the space’s configuration and the custom strategy’s complexity.
- Setting Different Weights for Different Tokens: Yes, it is possible to assign different weights to different tokens. For example, one ERC-1155 collection could be given a higher weight compared to another, effectively granting it more influence in the vote. This is configured within the custom voting strategy.
Implementation:
To implement such a system, the space administrator would need to:
- Develop a custom strategy using JavaScript, which involves programming the logic that combines or separates the voting contributions of different tokens.
- Deploy the strategy to the Snapshot space, ensuring it aligns with the governance goals of the community.
- Test the strategy to confirm it accurately reflects the intended voting power dynamics.
The flexibility of Snapshot’s strategy system allows for a wide range of configurations to suit different governance needs, making it a robust tool for communities that utilize diverse types of digital assets for voting. For more detailed guidance on setting up custom strategies, you can refer to Snapshot’s documentation on creating voting strategies.
Provide any other details that may be helpful to get started doing this. For example, how much time, effort, or resources may be requiredto set up the custom voting strategy? Is there any shortcut? Can this be done with more than two tokens (ie 3,4, or 10 tokens)? Provide Javascript code to write the custom strategy. Point out any parts that would need to be modified or considered to make it work properly and how much additional work would be required
Setting up a custom voting strategy on Snapshot that allows voting with multiple tokens (such as 3, 4, or even 10 different tokens) involves a few key steps and considerations. The complexity and resources required can vary based on the specific requirements and the familiarity of the team with JavaScript and blockchain technologies.
Steps to Set Up a Custom Voting Strategy
- Define the Strategy: Decide how each token type should influence the vote. Should all tokens contribute equally, or should some have more weight?
- Development: Write the custom voting strategy in JavaScript. This involves programming logic that processes the balances of various token types for each voter.
- Deployment: Implement the strategy on the Snapshot space, which involves uploading and configuring it through the Snapshot interface.
- Testing: Ensure that the strategy works as intended across various scenarios to handle different token types and voting conditions.
Time, Effort, and Resources
- Time: The setup can take anywhere from a few days to weeks, depending on the complexity and testing requirements.
- Effort: Requires a proficient understanding of JavaScript, especially in asynchronous programming and interacting with blockchain data.
- Resources: Access to tools for developing and testing JavaScript code, and possibly access to a blockchain test network for live testing.
Shortcut
While there's no "shortcut" for setting up custom strategies (since it requires specific logic tailored to your governance model), using existing frameworks or libraries provided by Snapshot can simplify the process. Cloning and modifying an existing strategy that closely matches your needs can also reduce development time.
Custom Strategy Example
Here's a simplified example of a JavaScript code snippet for a custom strategy that handles multiple ERC-20 tokens. This is a basic template and would need to be expanded based on specific needs:
javascriptCopy code
const { strategyUtils } = require('@snapshot-labs/snapshot.js');
async function multiTokenStrategy(space, network, provider, addresses, options, snapshot) {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const multiCaller = new strategyUtils.Multicaller(network, provider, [], { blockTag });
options.tokens.forEach(token => {
const abi = ['function balanceOf(address owner) view returns (uint256)'];
addresses.forEach(address => {
multiCaller.call(`${token.address}_${address}`, token.address, 'balanceOf', [address]);
});
});
const result = await multiCaller.execute();
const scores = {};
addresses.forEach(address => {
scores[address] = options.tokens.reduce((score, token) => {
const balance = result[`${token.address}_${address}`] || 0;
return score + balance * token.weight; // Apply weight per token
}, 0);
});
return scores;
}
module.exports = {
author: 'your-username',
version: '1.0.0',
strategy: multiTokenStrategy
};
Modifications and Considerations
- Token List and Weights: You need to specify the list of tokens and their weights in the
options
parameter when configuring the strategy in Snapshot. - Smart Contract Interaction: Ensure the ABI used matches the token contracts' methods.
- Testing for Edge Cases: Thoroughly test the strategy to handle edge cases, such as addresses with zero balances across some or all tokens.
Additional Work Required
- Extending the strategy to handle ERC-1155 or other token standards.
- Adding security checks and error handling to make the strategy robust against failures or unexpected data.
This basic framework provides a starting point, but real-world application will require detailed customization to align with the governance model's specific requirements.
Provide detailed javascript code snippet that works with ERC1155 and instructions to make it as quick as possible for a developer to get started. If a talented developer has these code snippet and instructions, then how fast could it be done?
ChatGPT
To create a custom Snapshot voting strategy that works with ERC-1155 tokens, you'll need to develop a JavaScript function that computes the voting power based on the ownership of specific ERC-1155 tokens. Below is a detailed JavaScript code snippet that you can use as a starting point. This strategy assumes you're familiar with JavaScript, Node.js, and interacting with Ethereum smart contracts.
JavaScript Code Snippet for ERC-1155 Voting Strategy
javascriptCopy code
const { Multicaller } = require('@snapshot-labs/snapshot.js/lib/utils');
async function erc1155VotingStrategy(space, network, provider, addresses, options, snapshot) {
const blockTag = snapshot ? snapshot : 'latest';
const multi = new Multicaller(network, provider, options.abi, { blockTag });
// Add calls for each address and token id
addresses.forEach(address => {
options.tokenIds.forEach(tokenId => {
multi.call(`${address}_${tokenId}`, options.address, 'balanceOf', [address, tokenId]);
});
});
// Execute multicall
const balances = await multi.execute();
// Calculate scores based on balances and token weights
const scores = addresses.reduce((acc, address) => {
const totalBalance = options.tokenIds.reduce((sum, tokenId) => {
const balance = balances[`${address}_${tokenId}`] || 0;
const weight = options.weights[tokenId] || 1; // Default weight is 1 if not specified
return sum + (balance * weight);
}, 0);
acc[address] = totalBalance;
return acc;
}, {});
return scores;
}
module.exports = {
author: 'your-username',
version: '1.0.0',
strategy: erc1155VotingStrategy
};
Necessary Modifications and Considerations
- Smart Contract ABI: Make sure you include the ABI for the
balanceOf
function of the ERC-1155 token which typically looks like: - Token Addresses and IDs: You'll need to specify the contract address of the ERC-1155 tokens and the token IDs that are relevant for the voting.
- Weights: If different tokens should have different weights in the voting calculation, specify these in the
weights
object where the keys are token IDs.
jsonCopy code
[
{
"constant": true,
"inputs": [
{"name": "_owner", "type": "address"},
{"name": "_id", "type": "uint256"}
],
"name": "balanceOf",
"outputs": [{"name": "", "type": "uint256"}],
"type": "function"
}
]
Include this ABI in the options
parameter when configuring the strategy.
Instructions to Get Started Quickly
- Setup Environment:
- Ensure Node.js is installed.
- Set up a project directory, navigate into it, and run
npm init -y
. - Install necessary packages:
npm install @snapshot-labs/snapshot.js
. - Deploy the Strategy:
- Save the provided JavaScript code in a file, e.g.,
erc1155Strategy.js
. - Modify the
options
parameter to include the correct token address, token IDs, and their weights as required by your governance model. - Deploy this strategy on your Snapshot space through the Snapshot strategy interface.
- Test the Strategy:
- Use tools like Hardhat or Truffle configured to the appropriate network to test the strategy with actual ERC-1155 token balances.
- Ensure that the strategy behaves as expected across various scenarios and token distributions.
Time Estimate for a Talented Developer
A talented developer, given this snippet and instructions, could set up and test the strategy within a few hours to a day, depending on their familiarity with the Snapshot environment and Ethereum blockchain interactions. More complex weighting and token setups might extend this time slightly.
Are there any existing frameworks or strategies that might help make this quicker with multiple ERC1155 tokens?
Yes, Snapshot supports the use of multiple ERC1155 tokens for voting through custom voting strategies. These strategies can be configured to handle various tokens within a single Snapshot space, allowing you to tailor the voting power calculations based on the type and number of tokens a voter holds.
To facilitate this, Snapshot provides several predefined strategies that you can utilize or modify according to your needs:
- ERC1155 Balance of Strategy: This strategy calculates voting power based on the balance of a specific ERC1155 token.
- ERC1155 Balance of IDs Strategy: Useful when you want to calculate voting power by considering multiple specific token IDs within an ERC1155 contract.
- ERC1155 Balance of All Strategy: This strategy calculates the voting power by considering the balance of all tokens within an ERC1155 contract.
- ERC1155 With Multiplier: This allows for voting power adjustments by applying a multiplier to the balance of specific tokens, giving you the ability to weigh some tokens more heavily than others.
Setting up one of these strategies involves:
- Forking the snapshot-strategies repository on GitHub.
- Modifying an existing strategy or creating a new one based on your requirements.
- Deploying this custom strategy to your Snapshot space.
A proficient developer with all the necessary information and access could set up a basic custom strategy within a few hours. More complex setups, especially those involving multiple tokens and sophisticated weighting mechanisms, could take longer to configure and test thoroughly.
For a detailed guide on setting up these strategies, you can refer to Snapshot's documentation on creating voting strategies. Here you will find step-by-step instructions on how to fork the repository, make necessary modifications, and test your strategy to ensure it works as expected. This process is crucial to prevent any issues with the voting process and ensure that your governance model functions smoothly.
If you're looking to implement this kind of strategy and need more specific guidance, you might want to explore the Snapshot Strategies GitHub repository and Snapshot's official documentation on voting strategies.
Does this mean that custom development isn't needed and we can just use one of these strategies? Which strategy is most fitting for the use case described above?
For the use case you described, where you want to allow voting with multiple ERC1155 tokens within the same space, custom development might not be necessary if one of the pre-existing Snapshot strategies closely matches your needs. Here’s a breakdown of the available strategies that could be suitable:
- ERC1155 Balance of IDs Strategy (
erc1155-balance-of-ids
): This strategy is most fitting if you want to include specific token IDs in the voting process. It allows you to define which token IDs from an ERC1155 contract should be considered and their respective weights in voting power. - ERC1155 Balance of All Strategy (
erc1155-all-balances-of
): If you want to consider all token IDs within a specific ERC1155 contract for voting, this strategy will calculate the voting power based on the total balance of all tokens owned by the voter. - ERC1155 With Multiplier (
erc1155-with-multiplier
): This strategy allows for adjusting the voting power by applying a multiplier to the token balances. This is useful if you want to give different voting weights to different tokens, enhancing the flexibility of your voting mechanics.
For implementing any of these strategies, you can utilize the existing frameworks provided by Snapshot. You would need to configure the strategy parameters according to your governance model's requirements, such as setting the token contract address, token IDs, and any multipliers or weights for the tokens.
Here’s a brief guide on how you can proceed:
- Select the appropriate strategy: Based on your requirements, choose one of the strategies mentioned.
- Configure the strategy: This involves setting up parameters like the contract address and token IDs. For ERC1155 tokens, you will also decide if you want to include all tokens or specific ones.
- Deploy the strategy to your Snapshot space: Follow Snapshot's guidelines to add the strategy to your space. This might include editing JSON files and deploying them through the Snapshot strategy interface.
- Test the strategy: Before going live, ensure that the strategy functions as expected in various voting scenarios to confirm it reflects the intended voting power calculations.
If none of the existing strategies perfectly fit your needs, you may still need to modify an existing strategy or create a new one. This would involve more in-depth work with JavaScript and understanding of the Snapshot strategy API.
To get started with any of these strategies or if you need to customize them, refer to the Snapshot Strategies Documentation and the Snapshot GitHub repository for detailed guidance and code examples.
What steps would be needed to implement the strategy for ERC1155 With Multiplier (erc1155-with-multiplier)?
ChatGPT
To implement the "ERC1155 With Multiplier" strategy on Snapshot for voting with ERC1155 tokens, you can follow these steps:
- Fork the Snapshot Strategies Repository:
- Visit the Snapshot strategies GitHub repository and fork it. This will create a copy of the repository in your GitHub account.
- Setup Your Local Environment:
- Clone the forked repository to your local machine.
- Navigate to the repository directory and install dependencies:
- Create or Modify the Strategy:
- Navigate to the
src/strategies
directory. - If a pre-existing "ERC1155 With Multiplier" strategy does not exist, you can create a new directory and begin setting up your files.
- If modifying an existing strategy, locate the
erc1155-with-multiplier
directory (if available) and start modifying the files according to your needs. - Strategy Development:
- Inside your strategy folder, you will primarily modify the
index.ts
file where you define the logic for calculating voting power. This involves reading the balances of ERC1155 tokens and applying a multiplier to those balances. - Define the parameters your strategy will accept, such as the address of the ERC1155 token contract, the token IDs to check, and the multipliers for each token.
- Use the
Multicaller
utility from Snapshot.js to fetch balances in bulk and apply the multiplier to calculate the final voting power. - Testing Your Strategy:
- Use the testing framework provided in the repository to write tests for your strategy. This is crucial to ensure your strategy works as expected under different scenarios.
- Run tests using:
- Document Your Strategy:
- Write clear documentation in your strategy's directory explaining how it works, the parameters it requires, and any other relevant details. This documentation will be crucial for users of your strategy to understand how to use it correctly.
- Commit and Push Your Changes:
- Once you’re satisfied with the strategy and its testing, commit your changes and push them to your forked repository on GitHub.
- Create a Pull Request:
- Submit a pull request to the original Snapshot strategies repository. This will include a description of your new strategy and any other relevant details that explain why it should be added.
- The Snapshot team and community will review your pull request. They may request changes before it is merged into the main repository.
- Deploy the Strategy on Snapshot:
- Once your strategy is merged, you can add it to your Snapshot space through the Snapshot interface. You will need to specify the parameters as defined in your strategy's schema.
- Monitor and Maintain:
Copy code
yarn install
bashCopy code
yarn test --strategy=your-strategy-name
- After deployment, monitor the strategy for any issues and gather feedback from users.
- Be prepared to make adjustments or updates based on user feedback or changes in the Snapshot platform or ERC1155 token standards.
This process involves technical skills in JavaScript, familiarity with blockchain technology, and an understanding of the Snapshot platform's strategy system.