@snapshot-labs/snapshot.js 0.8.0-beta.0 → 0.8.0
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 +212 -165
- package/dist/snapshot.esm.js +211 -165
- package/dist/snapshot.min.js +5 -5
- package/dist/utils.d.ts +6 -13
- package/package.json +3 -3
- package/src/networks.json +77 -6
- 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.0
|
|
3
|
+
"version": "0.8.0",
|
|
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
|
@@ -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",
|
|
@@ -1190,7 +1218,7 @@
|
|
|
1190
1218
|
"wss://archive-en.baobab.klaytn.net/ws"
|
|
1191
1219
|
],
|
|
1192
1220
|
"explorer": {
|
|
1193
|
-
"url": "https://baobab.scope.klaytn.com
|
|
1221
|
+
"url": "https://baobab.scope.klaytn.com"
|
|
1194
1222
|
},
|
|
1195
1223
|
"logo": "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
|
|
1196
1224
|
},
|
|
@@ -1242,6 +1270,20 @@
|
|
|
1242
1270
|
"start": 451,
|
|
1243
1271
|
"logo": "ipfs://QmYeskHqrEvWHqeAuqett64LxfH52HUXZi2T9BAMmgKvBF"
|
|
1244
1272
|
},
|
|
1273
|
+
"1101": {
|
|
1274
|
+
"key": "1101",
|
|
1275
|
+
"name": "Polygon zkEVM",
|
|
1276
|
+
"shortName": "mainnet",
|
|
1277
|
+
"chainId": 1101,
|
|
1278
|
+
"network": "mainnet",
|
|
1279
|
+
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
1280
|
+
"rpc": [],
|
|
1281
|
+
"explorer": {
|
|
1282
|
+
"url": "https://zkevm.polygonscan.com"
|
|
1283
|
+
},
|
|
1284
|
+
"start": 57746,
|
|
1285
|
+
"logo": "ipfs://bafkreibfiyvhqnme2vbxxfcku7qkxgjpkg6ywdkplxh4oxlkqsbznyorfm"
|
|
1286
|
+
},
|
|
1245
1287
|
"1116": {
|
|
1246
1288
|
"key": "1116",
|
|
1247
1289
|
"name": "Core Chain Mainnet ",
|
|
@@ -1532,6 +1574,20 @@
|
|
|
1532
1574
|
"start": 2607889,
|
|
1533
1575
|
"logo": "ipfs://QmPXPCBho3kGLt5rhG9JGkKmzdtLvqZmJqGzzijVCuggWY"
|
|
1534
1576
|
},
|
|
1577
|
+
"4337": {
|
|
1578
|
+
"key": "4337",
|
|
1579
|
+
"name": "Beam",
|
|
1580
|
+
"shortName": "Beam",
|
|
1581
|
+
"chainId": 4337,
|
|
1582
|
+
"network": "mainnet",
|
|
1583
|
+
"multicall": "0x4956F15eFdc3dC16645e90Cc356eAFA65fFC65Ec",
|
|
1584
|
+
"rpc": [],
|
|
1585
|
+
"explorer": {
|
|
1586
|
+
"url": "https://subnets.avax.network/beam/"
|
|
1587
|
+
},
|
|
1588
|
+
"start": 1,
|
|
1589
|
+
"logo": "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF"
|
|
1590
|
+
},
|
|
1535
1591
|
"4689": {
|
|
1536
1592
|
"key": "4689",
|
|
1537
1593
|
"name": "IoTeX Mainnet",
|
|
@@ -1724,7 +1780,7 @@
|
|
|
1724
1780
|
"wss://archive-en.cypress.klaytn.net/ws"
|
|
1725
1781
|
],
|
|
1726
1782
|
"explorer": {
|
|
1727
|
-
"url": "https://scope.klaytn.com
|
|
1783
|
+
"url": "https://scope.klaytn.com"
|
|
1728
1784
|
},
|
|
1729
1785
|
"logo": "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
|
|
1730
1786
|
},
|
|
@@ -1881,6 +1937,21 @@
|
|
|
1881
1937
|
"start": 79516,
|
|
1882
1938
|
"logo": "ipfs://QmTogMDLmDgJjDjUKDHDuc2KVTVDbXf8bXJLFiVe8PRxgo"
|
|
1883
1939
|
},
|
|
1940
|
+
"13337": {
|
|
1941
|
+
"key": "13337",
|
|
1942
|
+
"name": "Beam Testnet",
|
|
1943
|
+
"shortName": "testnet",
|
|
1944
|
+
"chainId": 13337,
|
|
1945
|
+
"network": "testnet",
|
|
1946
|
+
"multicall": "0x9BF49b704EE2A095b95c1f2D4EB9010510c41C9E",
|
|
1947
|
+
"rpc": [],
|
|
1948
|
+
"explorer": {
|
|
1949
|
+
"url": "https://subnets-test.avax.network/beam/"
|
|
1950
|
+
},
|
|
1951
|
+
"start": 3,
|
|
1952
|
+
"logo": "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF",
|
|
1953
|
+
"testnet": true
|
|
1954
|
+
},
|
|
1884
1955
|
"16718": {
|
|
1885
1956
|
"key": "16718",
|
|
1886
1957
|
"name": "AirDAO Mainnet",
|
|
@@ -2216,7 +2287,7 @@
|
|
|
2216
2287
|
},
|
|
2217
2288
|
"80001": {
|
|
2218
2289
|
"key": "80001",
|
|
2219
|
-
"name": "
|
|
2290
|
+
"name": "Polygon Mumbai",
|
|
2220
2291
|
"chainId": 80001,
|
|
2221
2292
|
"network": "testnet",
|
|
2222
2293
|
"testnet": true,
|
|
@@ -2233,7 +2304,7 @@
|
|
|
2233
2304
|
"apiUrl": "https://api-mumbai.polygonscan.com"
|
|
2234
2305
|
},
|
|
2235
2306
|
"start": 12011090,
|
|
2236
|
-
"logo": "ipfs://
|
|
2307
|
+
"logo": "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
|
|
2237
2308
|
},
|
|
2238
2309
|
"84531": {
|
|
2239
2310
|
"key": "84531",
|
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
|
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
exports.__esModule = true;
|
|
14
|
-
exports.getBatchedProvider = void 0;
|
|
15
|
-
var providers_1 = require("@ethersproject/providers");
|
|
16
|
-
var networks_json_1 = require("../networks.json");
|
|
17
|
-
var providers = {};
|
|
18
|
-
function getProvider(network, type) {
|
|
19
|
-
var _a;
|
|
20
|
-
if (type === void 0) { type = 'archive'; }
|
|
21
|
-
var url = networks_json_1["default"][network].rpc[0];
|
|
22
|
-
if (type === 'light' && ((_a = networks_json_1["default"][network].light) === null || _a === void 0 ? void 0 : _a.length))
|
|
23
|
-
url = networks_json_1["default"][network].light[0];
|
|
24
|
-
var connectionInfo = typeof url === 'object'
|
|
25
|
-
? __assign(__assign({}, url), { timeout: 25000 }) : { url: url, timeout: 25000 };
|
|
26
|
-
if (!providers[network] || !providers[network][type]) {
|
|
27
|
-
providers[network] = __assign({}, providers[network]);
|
|
28
|
-
providers[network][type] = new providers_1.StaticJsonRpcProvider(connectionInfo);
|
|
29
|
-
}
|
|
30
|
-
return providers[network][type];
|
|
31
|
-
}
|
|
32
|
-
exports["default"] = getProvider;
|
|
33
|
-
function getBatchedProvider(network, type) {
|
|
34
|
-
var _a;
|
|
35
|
-
if (type === void 0) { type = 'archive'; }
|
|
36
|
-
var url = networks_json_1["default"][network].rpc[0];
|
|
37
|
-
if (type === 'light' && ((_a = networks_json_1["default"][network].light) === null || _a === void 0 ? void 0 : _a.length))
|
|
38
|
-
url = networks_json_1["default"][network].light[0];
|
|
39
|
-
var connectionInfo = typeof url === 'object'
|
|
40
|
-
? __assign(__assign({}, url), { timeout: 25000 }) : { url: url, timeout: 25000 };
|
|
41
|
-
if (!providers[network] || !providers[network][type]) {
|
|
42
|
-
providers[network] = __assign({}, providers[network]);
|
|
43
|
-
providers[network][type] = new providers_1.JsonRpcBatchProvider(connectionInfo);
|
|
44
|
-
}
|
|
45
|
-
return providers[network][type];
|
|
46
|
-
}
|
|
47
|
-
exports.getBatchedProvider = getBatchedProvider;
|
|
File without changes
|