@d10r/snapshot-strategies
v0.1.4
Published
This was originally an unmodified fork of https://github.com/snapshot-labs/snapshot-strategies. All we needed was the package to be published on npm so we can use snapshot strategies in our applications (e.g. in https://github.com/superfluid-org/sup-metri
Readme
About this fork
This was originally an unmodified fork of https://github.com/snapshot-labs/snapshot-strategies. All we needed was the package to be published on npm so we can use snapshot strategies in our applications (e.g. in https://github.com/superfluid-org/sup-metrics-api) without relying on the Score API (and its rate limits).
The upstream snapshot-strategies repository was later archived an merged into https://github.com/snapshot-labs/score-api . This project wasn't set up such that if published to npm, the functionality we wanted worked out of the box. Specifically, we want something like
import snapshotStrategies from '@d10r/snapshot-strategies';
...
const chunkScores = await snapshotStrategies.utils.getScoresDirect(...);
...Thus this fork now tracks the upstream scores-api repository, but with small modifications to package.json and tsconfig.json which result in the published npm package to expose the strategy relation functionality as before.
Snapshot Score API
The Score API is a simple RESTful API that calculates scores for various strategies based on the Snapshot protocol. This README outlines the functionality provided by the API and how to use it without any specific code examples.
🚀 For strategy & validation development
If you're looking to add new voting strategies or validation strategies, please see the STRATEGIES.md guide which contains detailed instructions for developers.
We recommend using the snapshot.js library for obtaining voting power and doing validation, as it provides a simple and convenient way to interact with the Snapshot Score API. The snapshot.js library offers the following methods:
getScores()- https://docs.snapshot.org/tools/snapshot.js#getscoresgetVp()- https://github.com/snapshot-labs/snapshot.js/blob/ad55119b0b684f7d6eeaa06f3642f7424d1fa949/src/utils.ts#L190validate()- https://github.com/snapshot-labs/snapshot.js/blob/ad55119b0b684f7d6eeaa06f3642f7424d1fa949/src/utils.ts#L227
The URL for score api is https://score.snapshot.org
API Endpoints
1. POST /
The base endpoint serves as the entry point for various methods:
- get_vp: Calculate voting power for a given address using strategies.
- validate: Validate a given address using validation strategies.
2. GET /api
This endpoint returns the current version of the Snapshot Score API and block numbers for different networks.
Send a GET request to this endpoint to receive a JSON object containing the version and block_num properties.
3. GET /api/strategies
This endpoint returns a list of available strategies for calculating voting power.
Send a GET request to this endpoint to receive a JSON object containing key-value pairs representing the strategies and their respective information.
4. GET /api/validations
This endpoint returns a list of available validation strategies for address validation.
Send a GET request to this endpoint to receive a JSON object containing key-value pairs representing the validation strategies and their respective information.
5. POST /api/scores
This endpoint calculates scores for a given set of strategies and addresses.
To use this endpoint, send a POST request with a JSON body containing the params object. The params object should include:
- space: The id of the space to calculate scores for.
- network: The network ID to use for calculations.
- snapshot: A specific block number or 'latest' for the latest block.
- addresses: An array of addresses for which the scores will be calculated.
- strategies: An array of strategy objects, each containing a name and params property.
- force: A boolean indicating whether to force the calculation of scores despite potential restrictions.
Running the API locally with Docker
You can run the API locally using Docker. To do so, follow these steps:
- Clone the repository and
cdinto it. - Copy the
.env.examplefile to.envand set necessary values. - Run
docker-compose upto start the API.
Running load tests with Artillery
You can run load tests on the API using Artillery. To do so, follow these steps:
- Clone the repository and
cdinto it. - Copy the
.env.examplefile to.envand set necessary values. - Run
npm installto install dependencies. - Install Artillery globally by running
npm install -g artillery. - Run
artillery run -t <your server url> ./test/load/<test-file>.ymlto run the load test.` to run the load test.
