@snapshot-labs/snapshot.js 0.4.106 → 0.4.107
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/snapshot.cjs.js +18 -10
- package/dist/snapshot.esm.js +18 -10
- package/dist/snapshot.min.js +5 -16
- package/package.json +2 -2
- package/src/utils/blockfinder.ts +19 -5
- package/src/utils.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snapshot-labs/snapshot.js",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.107",
|
|
4
4
|
"repository": "snapshot-labs/snapshot.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/snapshot.cjs.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@ethersproject/address": "^5.6.1",
|
|
14
14
|
"@ethersproject/bytes": "^5.6.1",
|
|
15
15
|
"@ethersproject/contracts": "^5.6.2",
|
|
16
|
-
"@ethersproject/hash": "^5.
|
|
16
|
+
"@ethersproject/hash": "^5.7.0",
|
|
17
17
|
"@ethersproject/providers": "^5.6.8",
|
|
18
18
|
"@ethersproject/units": "^5.7.0",
|
|
19
19
|
"@ethersproject/wallet": "^5.6.2",
|
package/src/utils/blockfinder.ts
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { subgraphRequest } from '../utils';
|
|
2
2
|
|
|
3
|
-
let cache = {};
|
|
3
|
+
let cache: Record<string, any> = {};
|
|
4
|
+
let expirationTime = 0;
|
|
5
|
+
|
|
4
6
|
export async function getSnapshots(network, snapshot, provider, networks) {
|
|
5
|
-
|
|
6
|
-
if (cache[cacheKey]) return cache[cacheKey];
|
|
7
|
+
// If snapshot is latest, return all latest
|
|
7
8
|
const snapshots = {};
|
|
8
9
|
networks.forEach((n) => (snapshots[n] = 'latest'));
|
|
9
10
|
if (snapshot === 'latest') return snapshots;
|
|
11
|
+
|
|
12
|
+
// Check if cache is valid
|
|
13
|
+
const cacheKey = `${network}-${snapshot}-${networks.join('-')}`;
|
|
14
|
+
const cachedEntry = cache[cacheKey];
|
|
15
|
+
const now = Date.now();
|
|
16
|
+
if (cachedEntry && expirationTime > now) {
|
|
17
|
+
return cachedEntry;
|
|
18
|
+
}
|
|
19
|
+
// Reset cache every hour
|
|
20
|
+
if (expirationTime < now) {
|
|
21
|
+
cache = {};
|
|
22
|
+
// Set expiration time to next hour
|
|
23
|
+
expirationTime = now + 60 * 60 * 1000 - (now % (60 * 60 * 1000));
|
|
24
|
+
}
|
|
25
|
+
|
|
10
26
|
snapshots[network] = snapshot;
|
|
11
27
|
const networkIn = Object.keys(snapshots).filter((s) => network !== s);
|
|
12
28
|
if (networkIn.length === 0) return snapshots;
|
|
@@ -29,5 +45,3 @@ export async function getSnapshots(network, snapshot, provider, networks) {
|
|
|
29
45
|
cache[cacheKey] = snapshots;
|
|
30
46
|
return snapshots;
|
|
31
47
|
}
|
|
32
|
-
|
|
33
|
-
setInterval(() => (cache = {}), 1000 * 60 * 60 * 1); // Clear cache every 1 hour
|
package/src/utils.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Interface } from '@ethersproject/abi';
|
|
|
3
3
|
import { Contract } from '@ethersproject/contracts';
|
|
4
4
|
import { isAddress } from '@ethersproject/address';
|
|
5
5
|
import { parseUnits } from '@ethersproject/units';
|
|
6
|
-
import {
|
|
6
|
+
import { namehash, ensNormalize } from '@ethersproject/hash';
|
|
7
7
|
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
|
|
8
8
|
import Ajv from 'ajv';
|
|
9
9
|
import addFormats from 'ajv-formats';
|
|
@@ -324,7 +324,7 @@ export async function getEnsTextRecord(
|
|
|
324
324
|
) {
|
|
325
325
|
const ensResolvers =
|
|
326
326
|
networks[network].ensResolvers || networks['1'].ensResolvers;
|
|
327
|
-
const ensHash =
|
|
327
|
+
const ensHash = namehash(ensNormalize(ens));
|
|
328
328
|
const provider = getProvider(network);
|
|
329
329
|
|
|
330
330
|
const result = await multicall(
|
|
@@ -360,7 +360,7 @@ export async function getEnsOwner(
|
|
|
360
360
|
provider
|
|
361
361
|
);
|
|
362
362
|
const ensNameWrapper = networks[network].ensNameWrapper;
|
|
363
|
-
const ensHash =
|
|
363
|
+
const ensHash = namehash(ensNormalize(ens));
|
|
364
364
|
let owner = await ensRegistry.owner(ensHash);
|
|
365
365
|
// If owner is the ENSNameWrapper contract, resolve the owner of the name
|
|
366
366
|
if (owner === ensNameWrapper) {
|