@snapshot-labs/snapshot.js 0.5.5 → 0.5.6
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/dist/sign/eip1271.d.ts +1 -1
- package/dist/sign/utils.d.ts +1 -1
- package/dist/snapshot.cjs.js +42 -28
- package/dist/snapshot.esm.js +42 -28
- package/dist/snapshot.min.js +1 -1
- package/dist/utils/blockfinder.d.ts +1 -1
- package/dist/utils/provider.d.ts +6 -2
- package/dist/utils.d.ts +6 -6
- package/package.json +1 -1
- package/src/sign/eip1271.ts +2 -2
- package/src/sign/utils.ts +2 -2
- package/src/utils/blockfinder.ts +8 -2
- package/src/utils/provider.ts +10 -4
- package/src/utils.ts +31 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getSnapshots(network: any, snapshot: any, provider: any, networks: any): Promise<any>;
|
|
1
|
+
export declare function getSnapshots(network: any, snapshot: any, provider: any, networks: any, options?: any): Promise<any>;
|
package/dist/utils/provider.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export default function getProvider(network: any
|
|
2
|
-
|
|
1
|
+
export default function getProvider(network: any, { broviderUrl }?: {
|
|
2
|
+
broviderUrl?: string | undefined;
|
|
3
|
+
}): any;
|
|
4
|
+
export declare function getBatchedProvider(network: any, { broviderUrl }?: {
|
|
5
|
+
broviderUrl?: string | undefined;
|
|
6
|
+
}): any;
|
package/dist/utils.d.ts
CHANGED
|
@@ -25,18 +25,18 @@ export declare function call(provider: any, abi: any[], call: any[], options?: a
|
|
|
25
25
|
export declare function multicall(network: string, provider: any, abi: any[], calls: any[], options?: any): Promise<any>;
|
|
26
26
|
export declare function subgraphRequest(url: string, query: any, options?: any): Promise<any>;
|
|
27
27
|
export declare function getUrl(uri: any, gateway?: string): any;
|
|
28
|
-
export declare function getJSON(uri: any): Promise<any>;
|
|
28
|
+
export declare function getJSON(uri: any, options?: any): Promise<any>;
|
|
29
29
|
export declare function ipfsGet(gateway: string, ipfsHash: string, protocolType?: string): Promise<any>;
|
|
30
30
|
export declare function sendTransaction(web3: any, contractAddress: string, abi: any[], action: string, params: any[], overrides?: {}): Promise<any>;
|
|
31
31
|
export declare function getScores(space: string, strategies: Strategy[], network: string, addresses: string[], snapshot?: number | string, scoreApiUrl?: string, options?: any): Promise<any>;
|
|
32
32
|
export declare function getVp(address: string, network: string, strategies: Strategy[], snapshot: number | 'latest', space: string, delegation: boolean, options?: Options): Promise<any>;
|
|
33
33
|
export declare function validate(validation: string, author: string, space: string, network: string, snapshot: number | 'latest', params: any, options: any): Promise<any>;
|
|
34
34
|
export declare function validateSchema(schema: any, data: any): true | import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | null | undefined;
|
|
35
|
-
export declare function getEnsTextRecord(ens: string, record: string, network?: string): Promise<any>;
|
|
36
|
-
export declare function getSpaceUri(id: string, network?: string): Promise<string | null>;
|
|
37
|
-
export declare function getEnsOwner(ens: string, network?: string): Promise<string | null>;
|
|
38
|
-
export declare function getSpaceController(id: string, network?: string): Promise<string | null>;
|
|
39
|
-
export declare function getDelegatesBySpace(network: string, space: string, snapshot?: string): Promise<never[]>;
|
|
35
|
+
export declare function getEnsTextRecord(ens: string, record: string, network?: string, options?: any): Promise<any>;
|
|
36
|
+
export declare function getSpaceUri(id: string, network?: string, options?: any): Promise<string | null>;
|
|
37
|
+
export declare function getEnsOwner(ens: string, network?: string, options?: any): Promise<string | null>;
|
|
38
|
+
export declare function getSpaceController(id: string, network?: string, options?: any): Promise<string | null>;
|
|
39
|
+
export declare function getDelegatesBySpace(network: string, space: string, snapshot?: string, options?: any): Promise<never[]>;
|
|
40
40
|
export declare function clone(item: any): any;
|
|
41
41
|
export declare function sleep(time: any): Promise<unknown>;
|
|
42
42
|
export declare function getNumberWithOrdinal(n: any): string;
|
package/package.json
CHANGED
package/src/sign/eip1271.ts
CHANGED
|
@@ -48,8 +48,8 @@ export async function verifyOldVersion(
|
|
|
48
48
|
return returnValue.toLowerCase() === magicValue.toLowerCase();
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export async function verify(address, sig, hash, network = '1') {
|
|
52
|
-
const provider = getProvider(network);
|
|
51
|
+
export async function verify(address, sig, hash, network = '1', options = {}) {
|
|
52
|
+
const provider = getProvider(network, options);
|
|
53
53
|
if (await verifyDefault(address, sig, hash, provider)) return true;
|
|
54
54
|
return await verifyOldVersion(address, sig, hash, provider);
|
|
55
55
|
}
|
package/src/sign/utils.ts
CHANGED
|
@@ -7,7 +7,7 @@ export function getHash(data) {
|
|
|
7
7
|
return _TypedDataEncoder.hash(domain, types, message);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export async function verify(address, sig, data, network = '1') {
|
|
10
|
+
export async function verify(address, sig, data, network = '1', options = {}) {
|
|
11
11
|
const { domain, types, message } = data;
|
|
12
12
|
|
|
13
13
|
const hash = getHash(data);
|
|
@@ -23,5 +23,5 @@ export async function verify(address, sig, data, network = '1') {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// console.log('Check EIP1271 signature');
|
|
26
|
-
return await verifyEIP1271(address, sig, hash, network);
|
|
26
|
+
return await verifyEIP1271(address, sig, hash, network, options);
|
|
27
27
|
}
|
package/src/utils/blockfinder.ts
CHANGED
|
@@ -3,7 +3,13 @@ import { subgraphRequest } from '../utils';
|
|
|
3
3
|
let cache: Record<string, any> = {};
|
|
4
4
|
let expirationTime = 0;
|
|
5
5
|
|
|
6
|
-
export async function getSnapshots(
|
|
6
|
+
export async function getSnapshots(
|
|
7
|
+
network,
|
|
8
|
+
snapshot,
|
|
9
|
+
provider,
|
|
10
|
+
networks,
|
|
11
|
+
options: any = {}
|
|
12
|
+
) {
|
|
7
13
|
// If snapshot is latest, return all latest
|
|
8
14
|
const snapshots = {};
|
|
9
15
|
networks.forEach((n) => (snapshots[n] = 'latest'));
|
|
@@ -39,7 +45,7 @@ export async function getSnapshots(network, snapshot, provider, networks) {
|
|
|
39
45
|
number: true
|
|
40
46
|
}
|
|
41
47
|
};
|
|
42
|
-
const url = 'https://blockfinder.snapshot.org';
|
|
48
|
+
const url = options.blockFinderUrl || 'https://blockfinder.snapshot.org';
|
|
43
49
|
const data = await subgraphRequest(url, query);
|
|
44
50
|
data.blocks.forEach((block) => (snapshots[block.network] = block.number));
|
|
45
51
|
cache[cacheKey] = snapshots;
|
package/src/utils/provider.ts
CHANGED
|
@@ -6,8 +6,11 @@ import {
|
|
|
6
6
|
const providers = {};
|
|
7
7
|
const batchedProviders = {};
|
|
8
8
|
|
|
9
|
-
export default function getProvider(
|
|
10
|
-
|
|
9
|
+
export default function getProvider(
|
|
10
|
+
network,
|
|
11
|
+
{ broviderUrl = 'https://rpc.snapshot.org' } = {}
|
|
12
|
+
) {
|
|
13
|
+
const url = `${broviderUrl}/${network}`;
|
|
11
14
|
if (!providers[network])
|
|
12
15
|
providers[network] = new StaticJsonRpcProvider(
|
|
13
16
|
{
|
|
@@ -20,8 +23,11 @@ export default function getProvider(network) {
|
|
|
20
23
|
return providers[network];
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
export function getBatchedProvider(
|
|
24
|
-
|
|
26
|
+
export function getBatchedProvider(
|
|
27
|
+
network,
|
|
28
|
+
{ broviderUrl = 'https://rpc.snapshot.org' } = {}
|
|
29
|
+
) {
|
|
30
|
+
const url = `${broviderUrl}/${network}`;
|
|
25
31
|
if (!batchedProviders[network])
|
|
26
32
|
batchedProviders[network] = new JsonRpcBatchProvider({
|
|
27
33
|
url,
|
package/src/utils.ts
CHANGED
|
@@ -104,11 +104,9 @@ export async function multicall(
|
|
|
104
104
|
const multicallAbi = [
|
|
105
105
|
'function aggregate(tuple(address target, bytes callData)[] calls) view returns (uint256 blockNumber, bytes[] returnData)'
|
|
106
106
|
];
|
|
107
|
-
const
|
|
108
|
-
networks[network].multicall
|
|
109
|
-
|
|
110
|
-
provider
|
|
111
|
-
);
|
|
107
|
+
const multicallAddress =
|
|
108
|
+
options?.multicallAddress || networks[network].multicall;
|
|
109
|
+
const multi = new Contract(multicallAddress, multicallAbi, provider);
|
|
112
110
|
const itf = new Interface(abi);
|
|
113
111
|
try {
|
|
114
112
|
const max = options?.limit || 500;
|
|
@@ -184,8 +182,8 @@ export function getUrl(uri, gateway = gateways[0]) {
|
|
|
184
182
|
return uri;
|
|
185
183
|
}
|
|
186
184
|
|
|
187
|
-
export async function getJSON(uri) {
|
|
188
|
-
const url = getUrl(uri);
|
|
185
|
+
export async function getJSON(uri, options: any = {}) {
|
|
186
|
+
const url = getUrl(uri, options.gateways);
|
|
189
187
|
return fetch(url).then((res) => res.json());
|
|
190
188
|
}
|
|
191
189
|
|
|
@@ -323,28 +321,33 @@ export function validateSchema(schema, data) {
|
|
|
323
321
|
export async function getEnsTextRecord(
|
|
324
322
|
ens: string,
|
|
325
323
|
record: string,
|
|
326
|
-
network = '1'
|
|
324
|
+
network = '1',
|
|
325
|
+
options: any = {}
|
|
327
326
|
) {
|
|
328
327
|
const ensResolvers =
|
|
329
|
-
|
|
328
|
+
options.ensResolvers ||
|
|
329
|
+
networks[network].ensResolvers ||
|
|
330
|
+
networks['1'].ensResolvers;
|
|
330
331
|
const ensHash = namehash(ensNormalize(ens));
|
|
331
|
-
const provider = getProvider(network);
|
|
332
|
+
const provider = getProvider(network, options);
|
|
332
333
|
|
|
333
334
|
const result = await multicall(
|
|
334
335
|
network,
|
|
335
336
|
provider,
|
|
336
337
|
ENS_RESOLVER_ABI,
|
|
337
|
-
ensResolvers.map((address: any) => [address, 'text', [ensHash, record]])
|
|
338
|
+
ensResolvers.map((address: any) => [address, 'text', [ensHash, record]]),
|
|
339
|
+
options
|
|
338
340
|
);
|
|
339
341
|
return result.flat().find((r: string) => r) || '';
|
|
340
342
|
}
|
|
341
343
|
|
|
342
344
|
export async function getSpaceUri(
|
|
343
345
|
id: string,
|
|
344
|
-
network = '1'
|
|
346
|
+
network = '1',
|
|
347
|
+
options: any = {}
|
|
345
348
|
): Promise<string | null> {
|
|
346
349
|
try {
|
|
347
|
-
return await getEnsTextRecord(id, 'snapshot', network);
|
|
350
|
+
return await getEnsTextRecord(id, 'snapshot', network, options);
|
|
348
351
|
} catch (e) {
|
|
349
352
|
console.log(e);
|
|
350
353
|
return null;
|
|
@@ -353,16 +356,18 @@ export async function getSpaceUri(
|
|
|
353
356
|
|
|
354
357
|
export async function getEnsOwner(
|
|
355
358
|
ens: string,
|
|
356
|
-
network = '1'
|
|
359
|
+
network = '1',
|
|
360
|
+
options: any = {}
|
|
357
361
|
): Promise<string | null> {
|
|
358
362
|
const registryAddress = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
|
|
359
|
-
const provider = getProvider(network);
|
|
363
|
+
const provider = getProvider(network, options);
|
|
360
364
|
const ensRegistry = new Contract(
|
|
361
365
|
registryAddress,
|
|
362
366
|
['function owner(bytes32) view returns (address)'],
|
|
363
367
|
provider
|
|
364
368
|
);
|
|
365
|
-
const ensNameWrapper =
|
|
369
|
+
const ensNameWrapper =
|
|
370
|
+
options.ensNameWrapper || networks[network].ensNameWrapper;
|
|
366
371
|
const ensHash = namehash(ensNormalize(ens));
|
|
367
372
|
let owner = await ensRegistry.owner(ensHash);
|
|
368
373
|
// If owner is the ENSNameWrapper contract, resolve the owner of the name
|
|
@@ -379,9 +384,10 @@ export async function getEnsOwner(
|
|
|
379
384
|
|
|
380
385
|
export async function getSpaceController(
|
|
381
386
|
id: string,
|
|
382
|
-
network = '1'
|
|
387
|
+
network = '1',
|
|
388
|
+
options: any = {}
|
|
383
389
|
): Promise<string | null> {
|
|
384
|
-
const spaceUri = await getSpaceUri(id, network);
|
|
390
|
+
const spaceUri = await getSpaceUri(id, network, options);
|
|
385
391
|
if (spaceUri) {
|
|
386
392
|
let isUriAddress = isAddress(spaceUri);
|
|
387
393
|
if (isUriAddress) return spaceUri;
|
|
@@ -392,15 +398,18 @@ export async function getSpaceController(
|
|
|
392
398
|
isUriAddress = isAddress(address);
|
|
393
399
|
if (isUriAddress) return address;
|
|
394
400
|
}
|
|
395
|
-
return await getEnsOwner(id, network);
|
|
401
|
+
return await getEnsOwner(id, network, options);
|
|
396
402
|
}
|
|
397
403
|
|
|
398
404
|
export async function getDelegatesBySpace(
|
|
399
405
|
network: string,
|
|
400
406
|
space: string,
|
|
401
|
-
snapshot = 'latest'
|
|
407
|
+
snapshot = 'latest',
|
|
408
|
+
options: any = {}
|
|
402
409
|
) {
|
|
403
|
-
|
|
410
|
+
const subgraphUrl =
|
|
411
|
+
options.subgraphUrl || SNAPSHOT_SUBGRAPH_URL[network];
|
|
412
|
+
if (!subgraphUrl) {
|
|
404
413
|
return Promise.reject(
|
|
405
414
|
`Delegation subgraph not available for network ${network}`
|
|
406
415
|
);
|
|
@@ -432,10 +441,7 @@ export async function getDelegatesBySpace(
|
|
|
432
441
|
while (true) {
|
|
433
442
|
params.delegations.__args.skip = page * PAGE_SIZE;
|
|
434
443
|
|
|
435
|
-
const pageResult = await subgraphRequest(
|
|
436
|
-
delegationSubgraphs[network],
|
|
437
|
-
params
|
|
438
|
-
);
|
|
444
|
+
const pageResult = await subgraphRequest(subgraphUrl, params);
|
|
439
445
|
const pageDelegations = pageResult.delegations || [];
|
|
440
446
|
result = result.concat(pageDelegations);
|
|
441
447
|
page++;
|