Skip to content

Commit 23646ee

Browse files
wa0x6eChaituVR
andauthored
feat: add support for starknet treasuries and delegations (#1069)
* feat: allow starknet network on delegation and treasury network * test: add tests * make delegationNetwork as required param * Update src/schemas/space.json * v0.12.23 --------- Co-authored-by: ChaituVR <[email protected]>
1 parent 37a4ad4 commit 23646ee

File tree

6 files changed

+84
-12
lines changed

6 files changed

+84
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.12.22",
3+
"version": "0.12.23",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",

src/schemas/space.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,22 @@
258258
},
259259
"delegationContract": {
260260
"type": "string",
261-
"format": "evmAddress",
262261
"title": "Contract address",
263262
"description": "The address of your delegation contract",
264-
"examples": ["0x3901D0fDe202aF1427216b79f5243f8A022d68cf"]
263+
"examples": ["0x3901D0fDe202aF1427216b79f5243f8A022d68cf"],
264+
"anyOf": [
265+
{ "format": "evmAddress" },
266+
{ "format": "starknetAddress" }
267+
]
265268
},
266269
"delegationNetwork": {
267270
"type": "string",
268-
"snapshotNetwork": true,
269271
"title": "Delegation network",
270-
"minLength": 1,
271-
"maxLength": 32,
272-
"description": "The network of your delegation contract"
272+
"description": "The network of your delegation contract",
273+
"anyOf": [
274+
{ "snapshotNetwork": true },
275+
{ "starknetNetwork": true }
276+
]
273277
},
274278
"delegationApi": {
275279
"type": "string",
@@ -281,7 +285,7 @@
281285
]
282286
}
283287
},
284-
"required": ["delegationType", "delegationApi", "delegationContract"],
288+
"required": ["delegationType", "delegationNetwork", "delegationApi", "delegationContract"],
285289
"additionalProperties": false
286290
},
287291
"allowAlias": {
@@ -379,9 +383,11 @@
379383
},
380384
"network": {
381385
"type": "string",
382-
"snapshotNetwork": true,
383386
"title": "Network",
384-
"maxLength": 12
387+
"anyOf": [
388+
{ "snapshotNetwork": true },
389+
{ "starknetNetwork": true }
390+
]
385391
}
386392
},
387393
"required": ["name", "address", "network"],

src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const ENS_ABI = [
3636
'function resolver(bytes32 node) view returns (address)' // ENS registry ABI
3737
];
3838
const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000';
39+
const STARKNET_NETWORKS = ['0x534e5f4d41494e', '0x534e5f5345504f4c4941'];
3940

4041
const scoreApiHeaders = {
4142
Accept: 'application/json',
@@ -166,6 +167,16 @@ ajv.addKeyword({
166167
}
167168
});
168169

170+
ajv.addKeyword({
171+
keyword: 'starknetNetwork',
172+
validate: function (schema, data) {
173+
return STARKNET_NETWORKS.includes(data);
174+
},
175+
error: {
176+
message: 'network not allowed'
177+
}
178+
});
179+
169180
ajv.addKeyword({
170181
keyword: 'maxLengthWithSpaceType',
171182
validate: function validate(schema, data) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "Loot Owners",
3+
"skin": "indexed",
4+
"about": "",
5+
"admins": [
6+
"0xF296178d553C8Ec21A2fBD2c5dDa8CA9ac905A00"
7+
],
8+
"avatar": "https://pbs.twimg.com/profile_images/1431587138202701826/lpgblc4h_400x400.jpg",
9+
"github": "lootproject",
10+
"symbol": "LOOT",
11+
"filters": {
12+
"minScore": 1,
13+
"onlyMembers": false
14+
},
15+
"members": [],
16+
"network": "1",
17+
"plugins": {},
18+
"twitter": "lootproject",
19+
"domain": "vote.lootproject.abc",
20+
"strategies": [
21+
{
22+
"name": "erc721",
23+
"params": {
24+
"symbol": "LOOT",
25+
"address": "0xff9c1b15b16263c61d017ee9f65c50e4ae0113d7"
26+
}
27+
}
28+
],
29+
"delegationPortal":{
30+
"delegationType": "compound-governor",
31+
"delegationContract": "0x05702362b68a350c1cae8f2a529d74fdbb502369ddcebfadac7e91da37636947",
32+
"delegationNetwork": "0x534e5f4d41494e",
33+
"delegationApi": "https://snapshot.org"
34+
},
35+
"validation": {
36+
"name": "basic",
37+
"params": {}
38+
},
39+
"voting": {
40+
"delay": 2592000,
41+
"period": 15552000,
42+
"quorum": 100
43+
}
44+
}

test/examples/space.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@
4747
"network": "1"
4848
},
4949
{
50-
"name": "Starknet treasury",
50+
"name": "Mainnet Starknet treasury",
5151
"address": "0x05702362b68a350c1cae8f2a529d74fdbb502369ddcebfadac7e91da37636947",
52-
"network": "1"
52+
"network": "0x534e5f4d41494e"
53+
},
54+
{
55+
"name": "Sepolia Starknet treasury",
56+
"address": "0x05702362b68a350c1cae8f2a529d74fdbb502369ddcebfadac7e91da37636947",
57+
"network": "0x534e5f5345504f4c4941"
5358
}
5459
],
5560
"labels": [

test/schema.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { validateSchema } from '../src/utils';
33
import space from './examples/space.json';
44
import proposal from './examples/proposal.json';
55
import spaceTurbo from './examples/space-turbo.json';
6+
import spaceStarknetDelegation from './examples/space-starknet-delegation.json';
67
import proposalTurbo from './examples/proposal-turbo.json';
78
import vote from './examples/vote.json';
89
import profile from './examples/profile.json';
@@ -15,6 +16,11 @@ import spaceMaxItemsWithSpaceTypeError from './examples/space-maxItemsWithSpaceT
1516
// Tests for default spaces
1617
describe.each([
1718
{ schemaType: 'space', schema: schemas.space, example: space },
19+
{
20+
schemaType: 'space',
21+
schema: schemas.space,
22+
example: spaceStarknetDelegation
23+
},
1824
{ schemaType: 'proposal', schema: schemas.proposal, example: proposal },
1925
{ schemaType: 'vote', schema: schemas.vote, example: vote },
2026
{ schemaType: 'profile', schema: schemas.profile, example: profile },

0 commit comments

Comments
 (0)