@snapshot-labs/snapshot.js 0.8.0-beta.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/dist/sign/index.d.ts +16 -16
- package/dist/snapshot.cjs.js +235 -170
- package/dist/snapshot.esm.js +234 -170
- package/dist/snapshot.min.js +5 -5
- package/dist/utils.d.ts +6 -13
- package/package.json +3 -3
- package/src/networks.json +99 -11
- package/src/sign/index.ts +10 -12
- package/src/utils.ts +73 -117
- package/src/utils/dist/provider.js +0 -47
- /package/src/sign/{types.json → hashedTypes.json} +0 -0
package/dist/utils.d.ts
CHANGED
|
@@ -5,8 +5,6 @@ import { signMessage, getBlockNumber } from './utils/web3';
|
|
|
5
5
|
import { getHash, verify } from './sign/utils';
|
|
6
6
|
interface Options {
|
|
7
7
|
url?: string;
|
|
8
|
-
timeout?: number;
|
|
9
|
-
headers?: any;
|
|
10
8
|
}
|
|
11
9
|
interface Strategy {
|
|
12
10
|
name: string;
|
|
@@ -25,19 +23,14 @@ export declare const SNAPSHOT_SUBGRAPH_URL: {
|
|
|
25
23
|
};
|
|
26
24
|
export declare function call(provider: any, abi: any[], call: any[], options?: any): Promise<any>;
|
|
27
25
|
export declare function multicall(network: string, provider: any, abi: any[], calls: any[], options?: any): Promise<any>;
|
|
28
|
-
export declare function subgraphRequest(url: string, query: any, options?:
|
|
29
|
-
export declare function getUrl(uri:
|
|
30
|
-
export declare function getJSON(uri:
|
|
31
|
-
|
|
32
|
-
}): Promise<any>;
|
|
33
|
-
export declare function ipfsGet(gateway: string, ipfsHash: string, protocolType?: string, options?: Options): Promise<any>;
|
|
26
|
+
export declare function subgraphRequest(url: string, query: any, options?: any): Promise<any>;
|
|
27
|
+
export declare function getUrl(uri: any, gateway?: string): any;
|
|
28
|
+
export declare function getJSON(uri: any, options?: any): Promise<any>;
|
|
29
|
+
export declare function ipfsGet(gateway: string, ipfsHash: string, protocolType?: string): Promise<any>;
|
|
34
30
|
export declare function sendTransaction(web3: any, contractAddress: string, abi: any[], action: string, params: any[], overrides?: {}): Promise<any>;
|
|
35
|
-
export declare function getScores(space: string, strategies: Strategy[], network: string, addresses: string[], snapshot?: number | string, scoreApiUrl?: string, options?:
|
|
36
|
-
returnValue?: string;
|
|
37
|
-
pathname?: string;
|
|
38
|
-
}): Promise<any>;
|
|
31
|
+
export declare function getScores(space: string, strategies: Strategy[], network: string, addresses: string[], snapshot?: number | string, scoreApiUrl?: string, options?: any): Promise<any>;
|
|
39
32
|
export declare function getVp(address: string, network: string, strategies: Strategy[], snapshot: number | 'latest', space: string, delegation: boolean, options?: Options): Promise<any>;
|
|
40
|
-
export declare function validate(validation: string, author: string, space: string, network: string, snapshot: number | 'latest', params: any, options
|
|
33
|
+
export declare function validate(validation: string, author: string, space: string, network: string, snapshot: number | 'latest', params: any, options: any): Promise<any>;
|
|
41
34
|
export declare function validateSchema(schema: any, data: any): true | import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | null | undefined;
|
|
42
35
|
export declare function getEnsTextRecord(ens: string, record: string, network?: string, options?: any): Promise<any>;
|
|
43
36
|
export declare function getSpaceUri(id: string, network?: string, options?: any): Promise<string | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snapshot-labs/snapshot.js",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"repository": "snapshot-labs/snapshot.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/snapshot.cjs.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"@ethersproject/wallet": "^5.6.2",
|
|
20
20
|
"ajv": "^8.11.0",
|
|
21
21
|
"ajv-formats": "^2.1.1",
|
|
22
|
+
"cross-fetch": "^3.1.6",
|
|
22
23
|
"json-to-graphql-query": "^2.2.4",
|
|
23
|
-
"lodash.set": "^4.3.2"
|
|
24
|
-
"ofetch": "^1.3.3"
|
|
24
|
+
"lodash.set": "^4.3.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@rollup/plugin-commonjs": "^18.1.0",
|
package/src/networks.json
CHANGED
|
@@ -292,7 +292,7 @@
|
|
|
292
292
|
"name": "XDC Apothem.network",
|
|
293
293
|
"shortName": "XDC",
|
|
294
294
|
"chainId": 51,
|
|
295
|
-
"network": "
|
|
295
|
+
"network": "xdc",
|
|
296
296
|
"multicall": "0x3b353b02a8b42ee4222ea4be0836629b1f40c8db",
|
|
297
297
|
"rpc": [
|
|
298
298
|
"https://apothemrpc.blocksscan.io"
|
|
@@ -449,6 +449,20 @@
|
|
|
449
449
|
"start": 10780012,
|
|
450
450
|
"logo": "ipfs://QmXAKaNsyv6ctuRenYRJuZ1V4kn1eFwkUtjrjzX6jiKTqe"
|
|
451
451
|
},
|
|
452
|
+
"75": {
|
|
453
|
+
"key": "75",
|
|
454
|
+
"name": "Decimal",
|
|
455
|
+
"shortName": "mainnet",
|
|
456
|
+
"chainId": 75,
|
|
457
|
+
"network": "mainnet",
|
|
458
|
+
"multicall": "0x949d1A0757803C51F2EfFFEb5472C861A898B8E8",
|
|
459
|
+
"rpc": [],
|
|
460
|
+
"explorer": {
|
|
461
|
+
"url": "https://explorer.decimalchain.com"
|
|
462
|
+
},
|
|
463
|
+
"start": 16031065,
|
|
464
|
+
"logo": "ipfs://bafkreihkdhbce5rkogl63xegaarlirjrvbfarxbtbf5mqme3s5grvbjyxm"
|
|
465
|
+
},
|
|
452
466
|
"80": {
|
|
453
467
|
"key": "80",
|
|
454
468
|
"name": "GeneChain",
|
|
@@ -680,7 +694,7 @@
|
|
|
680
694
|
},
|
|
681
695
|
"137": {
|
|
682
696
|
"key": "137",
|
|
683
|
-
"name": "Polygon
|
|
697
|
+
"name": "Polygon PoS",
|
|
684
698
|
"shortName": "Polygon",
|
|
685
699
|
"chainId": 137,
|
|
686
700
|
"network": "mainnet",
|
|
@@ -699,7 +713,7 @@
|
|
|
699
713
|
"apiUrl": "https://api.polygonscan.com"
|
|
700
714
|
},
|
|
701
715
|
"start": 9834491,
|
|
702
|
-
"logo": "ipfs://
|
|
716
|
+
"logo": "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
|
|
703
717
|
},
|
|
704
718
|
"144": {
|
|
705
719
|
"key": "144",
|
|
@@ -747,6 +761,20 @@
|
|
|
747
761
|
"start": 4720651,
|
|
748
762
|
"logo": "ipfs://bafkreiabhsxuq35pp4kmrbptdeypd6clhcy3ue7ydpppo6onoo4igcjqia"
|
|
749
763
|
},
|
|
764
|
+
"204": {
|
|
765
|
+
"key": "204",
|
|
766
|
+
"name": "opBNB",
|
|
767
|
+
"shortName": "mainnet",
|
|
768
|
+
"chainId": 204,
|
|
769
|
+
"network": "mainnet",
|
|
770
|
+
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
771
|
+
"rpc": [],
|
|
772
|
+
"explorer": {
|
|
773
|
+
"url": "http://opbnbscan.com/"
|
|
774
|
+
},
|
|
775
|
+
"start": 512881,
|
|
776
|
+
"logo": "ipfs://bafkreibll4la7wqerzs7zwxjne2j7ayynbg2wlenemssoahxxj5rbt6c64"
|
|
777
|
+
},
|
|
750
778
|
"246": {
|
|
751
779
|
"key": "246",
|
|
752
780
|
"name": "Energy Web Chain",
|
|
@@ -807,7 +835,6 @@
|
|
|
807
835
|
"shortName": "HPB",
|
|
808
836
|
"chainId": 269,
|
|
809
837
|
"network": "mainnet",
|
|
810
|
-
"testnet": false,
|
|
811
838
|
"multicall": "0x67D0f263aef2F6167FA77353695D75b582Ff4Bca",
|
|
812
839
|
"rpc": [
|
|
813
840
|
"https://hpbnode.com"
|
|
@@ -854,6 +881,20 @@
|
|
|
854
881
|
"start": 74,
|
|
855
882
|
"logo": "ipfs://QmNc7QZFpPDue3Ef4SsuX55RHkqXxUxSyTCpoASeg2hW6d"
|
|
856
883
|
},
|
|
884
|
+
"314": {
|
|
885
|
+
"key": "314",
|
|
886
|
+
"name": "Filecoin",
|
|
887
|
+
"shortName": "mainnet",
|
|
888
|
+
"chainId": 314,
|
|
889
|
+
"network": "mainnet",
|
|
890
|
+
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
891
|
+
"rpc": [],
|
|
892
|
+
"explorer": {
|
|
893
|
+
"url": "https://filfox.io"
|
|
894
|
+
},
|
|
895
|
+
"start": 3328594,
|
|
896
|
+
"logo": "ipfs://bafybeibyvjfmk6aqlfdrczvth55jkmnoadtrch7ht3rdmvqmy2bfxynecm"
|
|
897
|
+
},
|
|
857
898
|
"321": {
|
|
858
899
|
"key": "321",
|
|
859
900
|
"name": "KCC Mainnet",
|
|
@@ -1144,6 +1185,7 @@
|
|
|
1144
1185
|
"shortName": "pulsechain",
|
|
1145
1186
|
"chainId": 940,
|
|
1146
1187
|
"network": "Testnet",
|
|
1188
|
+
"testnet": true,
|
|
1147
1189
|
"multicall": "0x5e67901C2Dd1915E9Ef49aF39B62C28DF8C2c529",
|
|
1148
1190
|
"rpc": [
|
|
1149
1191
|
"https://rpc.testnet.pulsedisco.net"
|
|
@@ -1163,6 +1205,7 @@
|
|
|
1163
1205
|
"shortName": "pulsechain",
|
|
1164
1206
|
"chainId": 941,
|
|
1165
1207
|
"network": "Testnet v2B",
|
|
1208
|
+
"testnet": true,
|
|
1166
1209
|
"multicall": "0x959a437F1444DaDaC8aF997E71EAF0479c810267",
|
|
1167
1210
|
"rpc": [
|
|
1168
1211
|
"https://rpc.testnet.pulsedisco.net"
|
|
@@ -1182,6 +1225,7 @@
|
|
|
1182
1225
|
"shortName": "Boabab",
|
|
1183
1226
|
"chainId": 1001,
|
|
1184
1227
|
"network": "testnet",
|
|
1228
|
+
"testnet": true,
|
|
1185
1229
|
"multicall": "0x40643B8Aeaaca0b87Ea1A1E596e64a0e14B1d244",
|
|
1186
1230
|
"rpc": [
|
|
1187
1231
|
"https://archive-en.baobab.klaytn.net"
|
|
@@ -1190,7 +1234,7 @@
|
|
|
1190
1234
|
"wss://archive-en.baobab.klaytn.net/ws"
|
|
1191
1235
|
],
|
|
1192
1236
|
"explorer": {
|
|
1193
|
-
"url": "https://baobab.scope.klaytn.com
|
|
1237
|
+
"url": "https://baobab.scope.klaytn.com"
|
|
1194
1238
|
},
|
|
1195
1239
|
"logo": "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
|
|
1196
1240
|
},
|
|
@@ -1242,6 +1286,20 @@
|
|
|
1242
1286
|
"start": 451,
|
|
1243
1287
|
"logo": "ipfs://QmYeskHqrEvWHqeAuqett64LxfH52HUXZi2T9BAMmgKvBF"
|
|
1244
1288
|
},
|
|
1289
|
+
"1101": {
|
|
1290
|
+
"key": "1101",
|
|
1291
|
+
"name": "Polygon zkEVM",
|
|
1292
|
+
"shortName": "mainnet",
|
|
1293
|
+
"chainId": 1101,
|
|
1294
|
+
"network": "mainnet",
|
|
1295
|
+
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
1296
|
+
"rpc": [],
|
|
1297
|
+
"explorer": {
|
|
1298
|
+
"url": "https://zkevm.polygonscan.com"
|
|
1299
|
+
},
|
|
1300
|
+
"start": 57746,
|
|
1301
|
+
"logo": "ipfs://bafkreibfiyvhqnme2vbxxfcku7qkxgjpkg6ywdkplxh4oxlkqsbznyorfm"
|
|
1302
|
+
},
|
|
1245
1303
|
"1116": {
|
|
1246
1304
|
"key": "1116",
|
|
1247
1305
|
"name": "Core Chain Mainnet ",
|
|
@@ -1359,6 +1417,7 @@
|
|
|
1359
1417
|
"shortName": "Gobi",
|
|
1360
1418
|
"chainId": 1663,
|
|
1361
1419
|
"network": "testnet",
|
|
1420
|
+
"testnet": true,
|
|
1362
1421
|
"multicall": "0xC743e4910Bdd4e5aBacCA38F74cdA270281C5eef",
|
|
1363
1422
|
"rpc": [
|
|
1364
1423
|
"https://gobi-testnet.horizenlabs.io/ethv1"
|
|
@@ -1391,7 +1450,6 @@
|
|
|
1391
1450
|
"shortName": "cube",
|
|
1392
1451
|
"chainId": 1818,
|
|
1393
1452
|
"network": "mainnet",
|
|
1394
|
-
"testnet": false,
|
|
1395
1453
|
"multicall": "0x28d2ebdb36369db1c51355cdc0898754d1a1c3c5",
|
|
1396
1454
|
"rpc": [
|
|
1397
1455
|
"https://http-mainnet-archive.cube.network"
|
|
@@ -1532,6 +1590,20 @@
|
|
|
1532
1590
|
"start": 2607889,
|
|
1533
1591
|
"logo": "ipfs://QmPXPCBho3kGLt5rhG9JGkKmzdtLvqZmJqGzzijVCuggWY"
|
|
1534
1592
|
},
|
|
1593
|
+
"4337": {
|
|
1594
|
+
"key": "4337",
|
|
1595
|
+
"name": "Beam",
|
|
1596
|
+
"shortName": "Beam",
|
|
1597
|
+
"chainId": 4337,
|
|
1598
|
+
"network": "mainnet",
|
|
1599
|
+
"multicall": "0x4956F15eFdc3dC16645e90Cc356eAFA65fFC65Ec",
|
|
1600
|
+
"rpc": [],
|
|
1601
|
+
"explorer": {
|
|
1602
|
+
"url": "https://subnets.avax.network/beam/"
|
|
1603
|
+
},
|
|
1604
|
+
"start": 1,
|
|
1605
|
+
"logo": "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF"
|
|
1606
|
+
},
|
|
1535
1607
|
"4689": {
|
|
1536
1608
|
"key": "4689",
|
|
1537
1609
|
"name": "IoTeX Mainnet",
|
|
@@ -1616,6 +1688,7 @@
|
|
|
1616
1688
|
"name": "Ontology Testnet",
|
|
1617
1689
|
"chainId": 5851,
|
|
1618
1690
|
"network": "testnet",
|
|
1691
|
+
"testnet": true,
|
|
1619
1692
|
"multicall": "0x381445710b5e73d34aF196c53A3D5cDa58EDBf7A",
|
|
1620
1693
|
"rpc": [
|
|
1621
1694
|
"https://polaris1.ont.io:10339",
|
|
@@ -1667,7 +1740,6 @@
|
|
|
1667
1740
|
"shortName": "Shyft",
|
|
1668
1741
|
"chainId": 7341,
|
|
1669
1742
|
"network": "mainnet",
|
|
1670
|
-
"testnet": false,
|
|
1671
1743
|
"multicall": "0xceb10e9133D771cA93c8002Be527A465E85381a2",
|
|
1672
1744
|
"rpc": [
|
|
1673
1745
|
"https://rpc.shyft.network"
|
|
@@ -1724,7 +1796,7 @@
|
|
|
1724
1796
|
"wss://archive-en.cypress.klaytn.net/ws"
|
|
1725
1797
|
],
|
|
1726
1798
|
"explorer": {
|
|
1727
|
-
"url": "https://scope.klaytn.com
|
|
1799
|
+
"url": "https://scope.klaytn.com"
|
|
1728
1800
|
},
|
|
1729
1801
|
"logo": "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
|
|
1730
1802
|
},
|
|
@@ -1768,7 +1840,6 @@
|
|
|
1768
1840
|
"shortName": "Evmos",
|
|
1769
1841
|
"chainId": 9001,
|
|
1770
1842
|
"network": "mainnet",
|
|
1771
|
-
"testnet": false,
|
|
1772
1843
|
"multicall": "0x37763d16f8dBf6F185368E0f256350cAb7E24b26",
|
|
1773
1844
|
"rpc": [
|
|
1774
1845
|
"https://eth.bd.evmos.org:8545"
|
|
@@ -1881,6 +1952,21 @@
|
|
|
1881
1952
|
"start": 79516,
|
|
1882
1953
|
"logo": "ipfs://QmTogMDLmDgJjDjUKDHDuc2KVTVDbXf8bXJLFiVe8PRxgo"
|
|
1883
1954
|
},
|
|
1955
|
+
"13337": {
|
|
1956
|
+
"key": "13337",
|
|
1957
|
+
"name": "Beam Testnet",
|
|
1958
|
+
"shortName": "testnet",
|
|
1959
|
+
"chainId": 13337,
|
|
1960
|
+
"network": "testnet",
|
|
1961
|
+
"multicall": "0x9BF49b704EE2A095b95c1f2D4EB9010510c41C9E",
|
|
1962
|
+
"rpc": [],
|
|
1963
|
+
"explorer": {
|
|
1964
|
+
"url": "https://subnets-test.avax.network/beam/"
|
|
1965
|
+
},
|
|
1966
|
+
"start": 3,
|
|
1967
|
+
"logo": "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF",
|
|
1968
|
+
"testnet": true
|
|
1969
|
+
},
|
|
1884
1970
|
"16718": {
|
|
1885
1971
|
"key": "16718",
|
|
1886
1972
|
"name": "AirDAO Mainnet",
|
|
@@ -2119,6 +2205,7 @@
|
|
|
2119
2205
|
"shortName": "ThinkiumTest1",
|
|
2120
2206
|
"chainId": 60001,
|
|
2121
2207
|
"network": "thinkiumtest1",
|
|
2208
|
+
"testnet": true,
|
|
2122
2209
|
"multicall": "0xc49bc485d4f943b287edadbce45eb1a1220ffdfe",
|
|
2123
2210
|
"rpc": [
|
|
2124
2211
|
"https://test1.thinkiumrpc.net"
|
|
@@ -2216,7 +2303,7 @@
|
|
|
2216
2303
|
},
|
|
2217
2304
|
"80001": {
|
|
2218
2305
|
"key": "80001",
|
|
2219
|
-
"name": "
|
|
2306
|
+
"name": "Polygon Mumbai",
|
|
2220
2307
|
"chainId": 80001,
|
|
2221
2308
|
"network": "testnet",
|
|
2222
2309
|
"testnet": true,
|
|
@@ -2233,7 +2320,7 @@
|
|
|
2233
2320
|
"apiUrl": "https://api-mumbai.polygonscan.com"
|
|
2234
2321
|
},
|
|
2235
2322
|
"start": 12011090,
|
|
2236
|
-
"logo": "ipfs://
|
|
2323
|
+
"logo": "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
|
|
2237
2324
|
},
|
|
2238
2325
|
"84531": {
|
|
2239
2326
|
"key": "84531",
|
|
@@ -2289,6 +2376,7 @@
|
|
|
2289
2376
|
"shortName": "Vpioneer",
|
|
2290
2377
|
"chainId": 666666,
|
|
2291
2378
|
"network": "testnet",
|
|
2379
|
+
"testnet": true,
|
|
2292
2380
|
"multicall": "0xb6E748D6632305E1c12D8369CC6B3eF4AA8A3c85",
|
|
2293
2381
|
"rpc": [
|
|
2294
2382
|
"https://vpioneer.infragrid.v.network/ethereum/compatible"
|
package/src/sign/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
2
2
|
import { Web3Provider } from '@ethersproject/providers';
|
|
3
3
|
import { Wallet } from '@ethersproject/wallet';
|
|
4
4
|
import { getAddress } from '@ethersproject/address';
|
|
@@ -89,18 +89,16 @@ export default class Client {
|
|
|
89
89
|
Accept: 'application/json',
|
|
90
90
|
'Content-Type': 'application/json'
|
|
91
91
|
},
|
|
92
|
-
|
|
93
|
-
body: envelop
|
|
92
|
+
body: JSON.stringify(envelop)
|
|
94
93
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
e.
|
|
102
|
-
|
|
103
|
-
}
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
fetch(address, init)
|
|
96
|
+
.then((res) => {
|
|
97
|
+
if (res.ok) return resolve(res.json());
|
|
98
|
+
throw res;
|
|
99
|
+
})
|
|
100
|
+
.catch((e) => e.json().then((json) => reject(json)));
|
|
101
|
+
});
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
async space(web3: Web3Provider | Wallet, address: string, message: Space) {
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
2
2
|
import { Interface } from '@ethersproject/abi';
|
|
3
3
|
import { Contract } from '@ethersproject/contracts';
|
|
4
4
|
import { isAddress } from '@ethersproject/address';
|
|
@@ -19,8 +19,6 @@ import voting from './voting';
|
|
|
19
19
|
|
|
20
20
|
interface Options {
|
|
21
21
|
url?: string;
|
|
22
|
-
timeout?: number;
|
|
23
|
-
headers?: any;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
interface Strategy {
|
|
@@ -137,56 +135,38 @@ export async function multicall(
|
|
|
137
135
|
}
|
|
138
136
|
}
|
|
139
137
|
|
|
140
|
-
export async function subgraphRequest(url: string, query, options
|
|
138
|
+
export async function subgraphRequest(url: string, query, options: any = {}) {
|
|
139
|
+
const res = await fetch(url, {
|
|
140
|
+
method: 'POST',
|
|
141
|
+
headers: {
|
|
142
|
+
Accept: 'application/json',
|
|
143
|
+
'Content-Type': 'application/json',
|
|
144
|
+
...options?.headers
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify({ query: jsonToGraphQLQuery({ query }) })
|
|
147
|
+
});
|
|
148
|
+
let responseData: any = await res.text();
|
|
141
149
|
try {
|
|
142
|
-
|
|
143
|
-
method: 'POST',
|
|
144
|
-
headers: {
|
|
145
|
-
Accept: 'application/json',
|
|
146
|
-
'Content-Type': 'application/json',
|
|
147
|
-
...options?.headers
|
|
148
|
-
},
|
|
149
|
-
timeout: options?.timeout || 20e3,
|
|
150
|
-
body: { query: jsonToGraphQLQuery({ query }) }
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const body = await fetch(url, init);
|
|
154
|
-
|
|
155
|
-
if (typeof body === 'string') {
|
|
156
|
-
return Promise.reject({
|
|
157
|
-
errors: [
|
|
158
|
-
{
|
|
159
|
-
message: 'Body is not a JSON object',
|
|
160
|
-
extensions: { code: 'INVALID_JSON' }
|
|
161
|
-
}
|
|
162
|
-
]
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (body.errors) {
|
|
167
|
-
return Promise.reject(body);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return body.data;
|
|
150
|
+
responseData = JSON.parse(responseData);
|
|
171
151
|
} catch (e) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
]
|
|
184
|
-
}
|
|
152
|
+
throw new Error(
|
|
153
|
+
`Errors found in subgraphRequest: URL: ${url}, Status: ${
|
|
154
|
+
res.status
|
|
155
|
+
}, Response: ${responseData.substring(0, 400)}`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
if (responseData.errors) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
`Errors found in subgraphRequest: URL: ${url}, Status: ${
|
|
161
|
+
res.status
|
|
162
|
+
}, Response: ${JSON.stringify(responseData.errors).substring(0, 400)}`
|
|
185
163
|
);
|
|
186
164
|
}
|
|
165
|
+
const { data } = responseData;
|
|
166
|
+
return data || {};
|
|
187
167
|
}
|
|
188
168
|
|
|
189
|
-
export function getUrl(uri
|
|
169
|
+
export function getUrl(uri, gateway = gateways[0]) {
|
|
190
170
|
const ipfsGateway = `https://${gateway}`;
|
|
191
171
|
if (!uri) return null;
|
|
192
172
|
if (
|
|
@@ -204,40 +184,18 @@ export function getUrl(uri: string, gateway = gateways[0]) {
|
|
|
204
184
|
return uri;
|
|
205
185
|
}
|
|
206
186
|
|
|
207
|
-
export async function getJSON(
|
|
208
|
-
uri
|
|
209
|
-
|
|
210
|
-
) {
|
|
211
|
-
const url = getUrl(uri, options.gateways) || '';
|
|
212
|
-
const body = await fetch(url, {
|
|
213
|
-
timeout: options.timeout || 30e3,
|
|
214
|
-
headers: {
|
|
215
|
-
Accept: 'application/json',
|
|
216
|
-
'Content-Type': 'application/json',
|
|
217
|
-
...options?.headers
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
return typeof body === 'string' ? JSON.parse(body) : body;
|
|
187
|
+
export async function getJSON(uri, options: any = {}) {
|
|
188
|
+
const url = getUrl(uri, options.gateways);
|
|
189
|
+
return fetch(url).then((res) => res.json());
|
|
222
190
|
}
|
|
223
191
|
|
|
224
192
|
export async function ipfsGet(
|
|
225
193
|
gateway: string,
|
|
226
194
|
ipfsHash: string,
|
|
227
|
-
protocolType = 'ipfs'
|
|
228
|
-
options: Options = {}
|
|
195
|
+
protocolType = 'ipfs'
|
|
229
196
|
) {
|
|
230
197
|
const url = `https://${gateway}/${protocolType}/${ipfsHash}`;
|
|
231
|
-
|
|
232
|
-
timeout: options.timeout || 20e3,
|
|
233
|
-
headers: {
|
|
234
|
-
Accept: 'application/json',
|
|
235
|
-
'Content-Type': 'application/json',
|
|
236
|
-
...options.headers
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
return typeof body === 'string' ? JSON.parse(body) : body;
|
|
198
|
+
return fetch(url).then((res) => res.json());
|
|
241
199
|
}
|
|
242
200
|
|
|
243
201
|
export async function sendTransaction(
|
|
@@ -262,10 +220,10 @@ export async function getScores(
|
|
|
262
220
|
addresses: string[],
|
|
263
221
|
snapshot: number | string = 'latest',
|
|
264
222
|
scoreApiUrl = 'https://score.snapshot.org',
|
|
265
|
-
options:
|
|
223
|
+
options: any = {}
|
|
266
224
|
) {
|
|
267
225
|
const url = new URL(scoreApiUrl);
|
|
268
|
-
url.pathname =
|
|
226
|
+
url.pathname = '/api/scores';
|
|
269
227
|
scoreApiUrl = url.toString();
|
|
270
228
|
|
|
271
229
|
try {
|
|
@@ -276,25 +234,25 @@ export async function getScores(
|
|
|
276
234
|
strategies,
|
|
277
235
|
addresses
|
|
278
236
|
};
|
|
279
|
-
|
|
280
|
-
const body = await fetch(scoreApiUrl, {
|
|
237
|
+
const res = await fetch(scoreApiUrl, {
|
|
281
238
|
method: 'POST',
|
|
282
239
|
headers: scoreApiHeaders,
|
|
283
|
-
|
|
284
|
-
body: { params }
|
|
240
|
+
body: JSON.stringify({ params })
|
|
285
241
|
});
|
|
242
|
+
const obj = await res.json();
|
|
243
|
+
|
|
244
|
+
if (obj.error) {
|
|
245
|
+
return Promise.reject(obj.error);
|
|
246
|
+
}
|
|
286
247
|
|
|
287
248
|
return options.returnValue === 'all'
|
|
288
|
-
?
|
|
289
|
-
:
|
|
249
|
+
? obj.result
|
|
250
|
+
: obj.result[options.returnValue || 'scores'];
|
|
290
251
|
} catch (e) {
|
|
291
|
-
|
|
292
|
-
e.data
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
data: e.data || ''
|
|
296
|
-
}
|
|
297
|
-
);
|
|
252
|
+
if (e.errno) {
|
|
253
|
+
return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
|
|
254
|
+
}
|
|
255
|
+
return Promise.reject(e);
|
|
298
256
|
}
|
|
299
257
|
}
|
|
300
258
|
|
|
@@ -305,14 +263,14 @@ export async function getVp(
|
|
|
305
263
|
snapshot: number | 'latest',
|
|
306
264
|
space: string,
|
|
307
265
|
delegation: boolean,
|
|
308
|
-
options
|
|
266
|
+
options?: Options
|
|
309
267
|
) {
|
|
310
|
-
|
|
268
|
+
if (!options) options = {};
|
|
269
|
+
if (!options.url) options.url = 'https://score.snapshot.org';
|
|
311
270
|
const init = {
|
|
312
271
|
method: 'POST',
|
|
313
272
|
headers: scoreApiHeaders,
|
|
314
|
-
|
|
315
|
-
body: {
|
|
273
|
+
body: JSON.stringify({
|
|
316
274
|
jsonrpc: '2.0',
|
|
317
275
|
method: 'get_vp',
|
|
318
276
|
params: {
|
|
@@ -323,20 +281,19 @@ export async function getVp(
|
|
|
323
281
|
space,
|
|
324
282
|
delegation
|
|
325
283
|
}
|
|
326
|
-
}
|
|
284
|
+
})
|
|
327
285
|
};
|
|
328
286
|
|
|
329
287
|
try {
|
|
330
|
-
const
|
|
331
|
-
|
|
288
|
+
const res = await fetch(options.url, init);
|
|
289
|
+
const json = await res.json();
|
|
290
|
+
if (json.error) return Promise.reject(json.error);
|
|
291
|
+
if (json.result) return json.result;
|
|
332
292
|
} catch (e) {
|
|
333
|
-
|
|
334
|
-
e.data
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
data: e.data || ''
|
|
338
|
-
}
|
|
339
|
-
);
|
|
293
|
+
if (e.errno) {
|
|
294
|
+
return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
|
|
295
|
+
}
|
|
296
|
+
return Promise.reject(e);
|
|
340
297
|
}
|
|
341
298
|
}
|
|
342
299
|
|
|
@@ -347,14 +304,14 @@ export async function validate(
|
|
|
347
304
|
network: string,
|
|
348
305
|
snapshot: number | 'latest',
|
|
349
306
|
params: any,
|
|
350
|
-
options:
|
|
307
|
+
options: any
|
|
351
308
|
) {
|
|
352
|
-
|
|
309
|
+
if (!options) options = {};
|
|
310
|
+
if (!options.url) options.url = 'https://score.snapshot.org';
|
|
353
311
|
const init = {
|
|
354
312
|
method: 'POST',
|
|
355
313
|
headers: scoreApiHeaders,
|
|
356
|
-
|
|
357
|
-
body: {
|
|
314
|
+
body: JSON.stringify({
|
|
358
315
|
jsonrpc: '2.0',
|
|
359
316
|
method: 'validate',
|
|
360
317
|
params: {
|
|
@@ -365,20 +322,19 @@ export async function validate(
|
|
|
365
322
|
snapshot,
|
|
366
323
|
params
|
|
367
324
|
}
|
|
368
|
-
}
|
|
325
|
+
})
|
|
369
326
|
};
|
|
370
327
|
|
|
371
328
|
try {
|
|
372
|
-
const
|
|
373
|
-
|
|
329
|
+
const res = await fetch(options.url, init);
|
|
330
|
+
const json = await res.json();
|
|
331
|
+
if (json.error) return Promise.reject(json.error);
|
|
332
|
+
return json.result;
|
|
374
333
|
} catch (e) {
|
|
375
|
-
|
|
376
|
-
e.data
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
data: e.data || ''
|
|
380
|
-
}
|
|
381
|
-
);
|
|
334
|
+
if (e.errno) {
|
|
335
|
+
return Promise.reject({ code: e.errno, message: e.toString(), data: '' });
|
|
336
|
+
}
|
|
337
|
+
return Promise.reject(e);
|
|
382
338
|
}
|
|
383
339
|
}
|
|
384
340
|
|