You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: graphql-api.md
+59-60Lines changed: 59 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,31 +8,31 @@ description: >-
8
8
9
9
## Explorer
10
10
11
-
You can run queries on Snapshot data using a GraphQL Explorer.
11
+
You can run queries on Snapshot data using a GraphQL Explorer.
12
12
13
-
We have exposed an integrated development environment in the browser that includes docs, syntax highlighting, and validation errors. Click the link below to access the interface.
13
+
We have exposed an integrated development environment in the browser that includes docs, syntax highlighting, and validation errors. Click the link below to access the interface.
### Get a single space <ahref="#space"id="space"></a>
36
36
37
37
#### Arguments
38
38
@@ -82,16 +82,16 @@ query {
82
82
83
83
Try on [GraphiQL](https://hub.snapshot.org/graphql?query=query%20%7B%0A%20%20space%28id%3A%20%22yam.eth%22%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20name%0A%20%20%20%20about%0A%20%20%20%20network%0A%20%20%20%20symbol%0A%20%20%20%20members%0A%20%20%7D%0A%7D)
84
84
85
-
### Get multiple spaces <aid="spaces"></a>
85
+
### Get multiple spaces <ahref="#spaces"id="spaces"></a>
86
86
87
87
#### Arguments
88
88
89
-
first `number`
90
-
skip `number`
91
-
where:
92
-
- id`string`
93
-
- id\_in`array`
94
-
orderBy `string`
89
+
first `number`\
90
+
skip `number`\
91
+
where:\
92
+
\- id`string`\
93
+
\- id\_in`array`\
94
+
orderBy `string`\
95
95
orderDirection `asc` or `desc`
96
96
97
97
#### Example
@@ -172,9 +172,9 @@ query {
172
172
173
173
Try on [GraphiQL](https://hub.snapshot.org/graphql?query=%0Aquery%20Spaces%20%7B%0A%20%20spaces%28%0A%20%20%20%20first%3A%2020%2C%0A%20%20%20%20skip%3A%200%2C%0A%20%20%20%20orderBy%3A%20%22created%22%2C%0A%20%20%20%20orderDirection%3A%20asc%0A%20%20%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20name%0A%20%20%20%20about%0A%20%20%20%20network%0A%20%20%20%20symbol%0A%20%20%20%20strategies%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20params%0A%20%20%20%20%7D%0A%20%20%20%20admins%0A%20%20%20%20members%0A%20%20%20%20filters%20%7B%0A%20%20%20%20%20%20minScore%0A%20%20%20%20%20%20onlyMembers%0A%20%20%20%20%7D%0A%20%20%20%20plugins%0A%20%20%7D%0A%7D)
174
174
175
-
### Get a single proposal <aid="proposal"></a>
175
+
### Get a single proposal <ahref="#proposal"id="proposal"></a>
Try on [GraphiQL](https://hub.snapshot.org/graphql?operationName=Proposal&query=query%20Proposal%20%7B%0A%20%20proposal%28id%3A%22QmWbpCtwdLzxuLKnMW4Vv4MPFd2pdPX71YBKPasfZxqLUS%22%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20title%0A%20%20%20%20body%0A%20%20%20%20choices%0A%20%20%20%20start%0A%20%20%20%20end%0A%20%20%20%20snapshot%0A%20%20%20%20state%0A%20%20%20%20author%0A%20%20%20%20space%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)
242
+
Try on [GraphiQL](https://hub.snapshot.org/graphql?operationName=Proposal\&query=query%20Proposal%20%7B%0A%20%20proposal%28id%3A%22QmWbpCtwdLzxuLKnMW4Vv4MPFd2pdPX71YBKPasfZxqLUS%22%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20title%0A%20%20%20%20body%0A%20%20%20%20choices%0A%20%20%20%20start%0A%20%20%20%20end%0A%20%20%20%20snapshot%0A%20%20%20%20state%0A%20%20%20%20author%0A%20%20%20%20space%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)
243
243
244
-
### Get proposals <aid="proposals"></a>
244
+
### Get proposals <ahref="#proposals"id="proposals"></a>
245
245
246
246
#### Arguments
247
247
248
-
first `number`
249
-
skip `number`
250
-
where:
251
-
- id`string`
252
-
- id\_in`array`
253
-
- space:`string`
254
-
- space\_in:`array`
255
-
- author:`string`
256
-
- author\_in:`array`
257
-
- network: `string`
258
-
- network\_in: `array`
259
-
- state: `array`
260
-
orderBy `string`
248
+
first `number`\
249
+
skip `number`\
250
+
where:\
251
+
\- id`string`\
252
+
\- id\_in`array`\
253
+
\- space:`string`\
254
+
\- space\_in:`array`\
255
+
\- author:`string`\
256
+
\- author\_in:`array`\
257
+
\- network: `string`\
258
+
\- network\_in: `array`\
259
+
\- state: `array`\
260
+
orderBy `string`\
261
261
orderDirection `asc` or `desc`
262
262
263
263
#### Example
@@ -326,11 +326,11 @@ query {
326
326
{% endtab %}
327
327
{% endtabs %}
328
328
329
-
Try on [GraphiQL](https://hub.snapshot.org/graphql?operationName=Proposals&query=query%20Proposals%20%7B%0A%20%20proposals%20%28%0A%20%20%20%20first%3A%2020%2C%0A%20%20%20%20skip%3A%200%2C%0A%20%20%20%20where%3A%20%7B%0A%20%20%20%20%20%20space_in%3A%20%5B%22yam.eth%22%5D%2C%0A%20%20%20%20%20%20state%3A%20%22closed%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20orderBy%3A%20%22created%22%2C%0A%20%20%20%20orderDirection%3A%20desc%0A%20%20%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20title%0A%20%20%20%20body%0A%20%20%20%20choices%0A%20%20%20%20start%0A%20%20%20%20end%0A%20%20%20%20snapshot%0A%20%20%20%20state%0A%20%20%20%20author%0A%20%20%20%20space%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)
329
+
Try on [GraphiQL](https://hub.snapshot.org/graphql?operationName=Proposals\&query=query%20Proposals%20%7B%0A%20%20proposals%20%28%0A%20%20%20%20first%3A%2020%2C%0A%20%20%20%20skip%3A%200%2C%0A%20%20%20%20where%3A%20%7B%0A%20%20%20%20%20%20space\_in%3A%20%5B%22yam.eth%22%5D%2C%0A%20%20%20%20%20%20state%3A%20%22closed%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20orderBy%3A%20%22created%22%2C%0A%20%20%20%20orderDirection%3A%20desc%0A%20%20%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20title%0A%20%20%20%20body%0A%20%20%20%20choices%0A%20%20%20%20start%0A%20%20%20%20end%0A%20%20%20%20snapshot%0A%20%20%20%20state%0A%20%20%20%20author%0A%20%20%20%20space%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)
330
330
331
-
### Get a single vote <aid="vote"></a>
331
+
### Get a single vote <ahref="#vote"id="vote"></a>
Try on [GraphiQL](https://hub.snapshot.org/graphql?operationName=Vote&query=query%20Vote%20%7B%0A%20%20vote%20%28%0A%20%20%20%20id%3A%20%22QmeU7ct9Y4KLrh6F6mbT1eJNMkeQKMSnSujEfMCfbRLCMp%22%0A%20%20%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20voter%0A%20%20%20%20created%0A%20%20%20%20proposal%0A%20%20%20%20choice%0A%20%20%20%20space%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)
379
+
Try on [GraphiQL](https://hub.snapshot.org/graphql?operationName=Vote\&query=query%20Vote%20%7B%0A%20%20vote%20%28%0A%20%20%20%20id%3A%20%22QmeU7ct9Y4KLrh6F6mbT1eJNMkeQKMSnSujEfMCfbRLCMp%22%0A%20%20%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20voter%0A%20%20%20%20created%0A%20%20%20%20proposal%0A%20%20%20%20choice%0A%20%20%20%20space%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)
380
380
381
-
### Get votes <aid="votes"></a>
381
+
### Get votes <ahref="#votes"id="votes"></a>
382
382
383
383
#### Arguments
384
384
385
-
first `number`
386
-
skip `number`
387
-
where:
388
-
- id`string`
389
-
- id\_in`array`
390
-
- space:`string`
391
-
- space\_in:`array`
392
-
- voter:`string`
393
-
- voter\_in:`array`
394
-
- proposal: `string`
395
-
- proposal\_in: `array`
396
-
orderBy `string`
385
+
first `number`\
386
+
skip `number`\
387
+
where:\
388
+
\- id`string`\
389
+
\- id\_in`array`\
390
+
\- space:`string`\
391
+
\- space\_in:`array`\
392
+
\- voter:`string`\
393
+
\- voter\_in:`array`\
394
+
\- proposal: `string`\
395
+
\- proposal\_in: `array`\
396
+
orderBy `string`\
397
397
orderDirection `asc` or `desc`
398
398
399
399
#### Example
@@ -457,22 +457,22 @@ query {
457
457
{% endtab %}
458
458
{% endtabs %}
459
459
460
-
Try on [GraphiQL](https://hub.snapshot.org/graphql?operationName=Votes&query=query%20Votes%20%7B%0A%20%20votes%20%28%0A%20%20%20%20first%3A%201000%0A%20%20%20%20skip%3A%200%0A%20%20%20%20where%3A%20%7B%0A%20%20%20%20%20%20proposal%3A%20%22QmPvbwguLfcVryzBRrbY4Pb9bCtxURagdv1XjhtFLf3wHj%22%0A%20%20%20%20%7D%0A%20%20%20%20orderBy%3A%20%22created%22%2C%0A%20%20%20%20orderDirection%3A%20desc%0A%20%20%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20voter%0A%20%20%20%20created%0A%20%20%20%20proposal%0A%20%20%20%20choice%0A%20%20%20%20space%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
460
+
Try on [GraphiQL](https://hub.snapshot.org/graphql?operationName=Votes\&query=query%20Votes%20%7B%0A%20%20votes%20%28%0A%20%20%20%20first%3A%201000%0A%20%20%20%20skip%3A%200%0A%20%20%20%20where%3A%20%7B%0A%20%20%20%20%20%20proposal%3A%20%22QmPvbwguLfcVryzBRrbY4Pb9bCtxURagdv1XjhtFLf3wHj%22%0A%20%20%20%20%7D%0A%20%20%20%20orderBy%3A%20%22created%22%2C%0A%20%20%20%20orderDirection%3A%20desc%0A%20%20%29%20%7B%0A%20%20%20%20id%0A%20%20%20%20voter%0A%20%20%20%20created%0A%20%20%20%20proposal%0A%20%20%20%20choice%0A%20%20%20%20space%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)
461
461
462
-
### Get follows <aid="follows"></a>
462
+
### Get follows <ahref="#follows"id="follows"></a>
463
463
464
464
#### Arguments
465
465
466
-
first `number`
467
-
skip `number`
468
-
where:
469
-
- id`string`
470
-
- id\_in`array`
471
-
- space:`string`
472
-
- space\_in:`array`
473
-
- follower:`string`
474
-
- follower\_in:`array`
475
-
orderBy `string`
466
+
first `number`\
467
+
skip `number`\
468
+
where:\
469
+
\- id`string`\
470
+
\- id\_in`array`\
471
+
\- space:`string`\
472
+
\- space\_in:`array`\
473
+
\- follower:`string`\
474
+
\- follower\_in:`array`\
475
+
orderBy `string`\
476
476
orderDirection `asc` or `desc`
477
477
478
478
#### Example
@@ -542,4 +542,3 @@ Try on [GraphiQL](https://hub.snapshot.org/graphql?query=query%20%7B%0A%20%20fol
Copy file name to clipboardExpand all lines: strategies/create.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,11 +24,12 @@ To add your own strategy on Snapshot you need to fork the **snapshot-strategies*
24
24
npm run test --strategy=<STRATEGYNAME>// replace <STRATEGY NAME>
25
25
```
26
26
27
+
See [How to write a basic strategy](how-to-write-a-basic-strategy.md)
28
+
27
29
### 4. Make sure you pass the checklist
28
30
29
31
Have a look here on the requirements for adding a new strategy and make sure you full fill the points in the checklist: [https://github.com/snapshot-labs/snapshot.js/issues/212](https://github.com/snapshot-labs/snapshot.js/issues/212)
30
32
31
33
### 5. Create a pull request
32
34
33
35
The team will then review your PR and after it's approved and merged it will be available in your space settings.
Every strategy is, at its core, the implementation of the `strategy(space, network, provider, addresses, options, snapshot)` function.
8
+
9
+
A quick word on the function parameters:
10
+
11
+
*`space`: the space (if applicable), based on the registered ENS associated with this strategy (see [Spaces](../spaces/))
12
+
*`network`: the network id as an integer (1 for Ethereum)
13
+
*`provider`: the network provider used by the web browser
14
+
*`addresses`: the list of addresses of the voters being processed.
15
+
*`options`: a collection of options that can be passed to strategy(...) - those have no default keys and can be used to pass any useful data
16
+
*`snapshots`: the block height at which the data are queried by strategy(...) - if none is passed, 'latest' is used. 
17
+
18
+
`Strategy(...)` returns a javascript object with every addresses from the addresses array as keys and the corresponding voting power as value (expressed in number of token owned by the address for `erc20-balance-of`, as a number of rocks owned for `has-rock`, etc).
19
+
20
+
Every strategy comes with a JSON file `examples.json`. This file is mandatory as it will be used for testing and validating the strategy before including it in Snapshot main GitHub branch. Here are the main keys:
21
+
22
+
*`"name"`: a human-reading name for the strategy ("ERC20 balance" for instance).
23
+
*`"strategy"`: the core parameters of the strategy
24
+
*`"name"`: the strategy name ("erc20-balance-of")
25
+
*`"params"`: optional parameters passed in `options` to strategy(...). Any useful "key":"value" can be used here and retrieved inside `strategy(...)` via `options.key`
26
+
*`"address"`: the address of the token contract (the DAI contract for instance)
27
+
*`"symbol"`: the token symbol ("DAI")
28
+
*`"decimals"`: the number of decimals (18)
29
+
*`"network"`: the network id (1 for ethereum)
30
+
*`"addresses"`: an array of addresses which will be used for testing (they should therefore have some token)
31
+
*`"snapshot"`: the block height (by taking a block height in the past where the addresses\[] had a positive balance, the test will be easily repeated)
32
+
33
+
Finally, all strategies will contain some similar steps, illustrated in [erc20-balance-of](https://github.com/snapshot-labs/snapshot-strategies/blob/f41f98249cff78486914473a3fef29ea960971e5/src/strategies/erc20-balance-of/index.ts):
34
+
35
+
* Getting the block height ('latest' or a specific one via the `snapshot` argument).
* Initializing Multicaller: looping over the addresses\[] array is **not allowed** as the strategy complexity would increase with the array size. Instead, Snapshot provides the Multicaller utility to group blockchain queries for a series of addresses. The abi can be in ethers human-readable form ( `['function balanceOf(address account) external view returns (uint256)']` for instance)
42
+
43
+
```
44
+
const multi = new Multicaller(network, provider, abi, { blockTag });
45
+
```
46
+
47
+
* Feeding data into the multicaller and executing the multicall: every query is queued in the multicaller via `Multicaller.call(...)`. Once they are all stored, an unique call is executed via `Multicall.execute()`. 
48
+
49
+
`option.address` is the token contract address (`strategy.params.address` in `examples.json`).
0 commit comments