Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Phyloiota authored Aug 5, 2023
2 parents 560ae70 + e393078 commit 6ec615c
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/snapshot.js",
"version": "0.4.106",
"version": "0.4.109",
"repository": "snapshot-labs/snapshot.js",
"license": "MIT",
"main": "dist/snapshot.cjs.js",
Expand All @@ -13,7 +13,7 @@
"@ethersproject/address": "^5.6.1",
"@ethersproject/bytes": "^5.6.1",
"@ethersproject/contracts": "^5.6.2",
"@ethersproject/hash": "^5.6.1",
"@ethersproject/hash": "^5.7.0",
"@ethersproject/providers": "^5.6.8",
"@ethersproject/units": "^5.7.0",
"@ethersproject/wallet": "^5.6.2",
Expand Down
19 changes: 16 additions & 3 deletions src/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -1625,8 +1625,7 @@
"chainId": 7332,
"network": "mainnet",
"multicall": "0xC743e4910Bdd4e5aBacCA38F74cdA270281C5eef",
"rpc": [
],
"rpc": [],
"explorer": {
"url": "https://eon-explorer.horizenlabs.io"
},
Expand Down Expand Up @@ -1700,6 +1699,20 @@
},
"logo": "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
},
"8453": {
"key": "8453",
"name": "Base",
"shortName": "mainnet",
"chainId": 8453,
"network": "mainnet",
"multicall": "0xca11bde05977b3631167028862be2a173976ca11",
"rpc": [],
"explorer": {
"url": "https://basescan.org/"
},
"start": 5022,
"logo": "ipfs://QmaxRoHpxZd8PqccAynherrMznMufG6sdmHZLihkECXmZv"
},
"9000": {
"key": "9000",
"name": "Evmos Network Testnet",
Expand Down Expand Up @@ -2193,7 +2206,7 @@
"url": "https://goerli.basescan.org/"
},
"start": 1151797,
"logo": "ipfs://QmQqrze3W1uSYWq2cGSYDeDwtjGXohTjWPnQ87EVJGeq2P"
"logo": "ipfs://QmaxRoHpxZd8PqccAynherrMznMufG6sdmHZLihkECXmZv"
},
"333888": {
"key": "333888",
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Interface } from '@ethersproject/abi';
import { Contract } from '@ethersproject/contracts';
import { isAddress } from '@ethersproject/address';
import { parseUnits } from '@ethersproject/units';
import { hash, normalize } from '@ensdomains/eth-ens-namehash';
import { namehash, ensNormalize } from '@ethersproject/hash';
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
Expand Down Expand Up @@ -324,7 +324,7 @@ export async function getEnsTextRecord(
) {
const ensResolvers =
networks[network].ensResolvers || networks['1'].ensResolvers;
const ensHash = hash(normalize(ens));
const ensHash = namehash(ensNormalize(ens));
const provider = getProvider(network);

const result = await multicall(
Expand Down Expand Up @@ -360,7 +360,7 @@ export async function getEnsOwner(
provider
);
const ensNameWrapper = networks[network].ensNameWrapper;
const ensHash = hash(normalize(ens));
const ensHash = namehash(ensNormalize(ens));
let owner = await ensRegistry.owner(ensHash);
// If owner is the ENSNameWrapper contract, resolve the owner of the name
if (owner === ensNameWrapper) {
Expand Down
24 changes: 19 additions & 5 deletions src/utils/blockfinder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { subgraphRequest } from '../utils';

let cache = {};
let cache: Record<string, any> = {};
let expirationTime = 0;

export async function getSnapshots(network, snapshot, provider, networks) {
const cacheKey = `${network}-${snapshot}-${networks.join('-')}`;
if (cache[cacheKey]) return cache[cacheKey];
// If snapshot is latest, return all latest
const snapshots = {};
networks.forEach((n) => (snapshots[n] = 'latest'));
if (snapshot === 'latest') return snapshots;

// Check if cache is valid
const cacheKey = `${network}-${snapshot}-${networks.join('-')}`;
const cachedEntry = cache[cacheKey];
const now = Date.now();
if (cachedEntry && expirationTime > now) {
return cachedEntry;
}
// Reset cache every hour
if (expirationTime < now) {
cache = {};
// Set expiration time to next hour
expirationTime = now + 60 * 60 * 1000 - (now % (60 * 60 * 1000));
}

snapshots[network] = snapshot;
const networkIn = Object.keys(snapshots).filter((s) => network !== s);
if (networkIn.length === 0) return snapshots;
Expand All @@ -29,5 +45,3 @@ export async function getSnapshots(network, snapshot, provider, networks) {
cache[cacheKey] = snapshots;
return snapshots;
}

setInterval(() => (cache = {}), 1000 * 60 * 60 * 1); // Clear cache every 1 hour
24 changes: 24 additions & 0 deletions test/e2e/utils/blockfinder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test, expect, describe } from 'vitest';
import { getSnapshots } from '../../../src/utils/blockfinder';
import getProvider from '../../../src/utils/provider';

describe('Test block finder', () => {
const provider = getProvider('1');
test('getSnapshots should work without errors and return object', async () => {
expect(
await getSnapshots('1', 17789783, provider, ['5', '137'])
).toMatchObject({
'1': 17789783,
'137': 45609596,
'5': 9421169
});
});
test('getSnapshots should return all latest if snapshot is latest', async () => {
expect(
await getSnapshots('1', 'latest', provider, ['5', '137'])
).toMatchObject({
'137': 'latest',
'5': 'latest'
});
});
});
134 changes: 134 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@
"@ethersproject/transactions" "^5.6.2"
"@ethersproject/web" "^5.6.1"

"@ethersproject/abstract-provider@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.7.0.tgz#b0a8550f88b6bf9d51f90e4795d48294630cb9ef"
integrity sha512-R41c9UkchKCpAqStMYUpdunjo3pkEvZC3FAwZn5S5MGbXoMQOHIdHItezTETxAO5bevtMApSyEhn9+CHcDsWBw==
dependencies:
"@ethersproject/bignumber" "^5.7.0"
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/logger" "^5.7.0"
"@ethersproject/networks" "^5.7.0"
"@ethersproject/properties" "^5.7.0"
"@ethersproject/transactions" "^5.7.0"
"@ethersproject/web" "^5.7.0"

"@ethersproject/abstract-signer@^5.6.2":
version "5.6.2"
resolved "https://registry.yarnpkg.com/@ethersproject/abstract-signer/-/abstract-signer-5.6.2.tgz#491f07fc2cbd5da258f46ec539664713950b0b33"
Expand All @@ -218,6 +231,17 @@
"@ethersproject/logger" "^5.6.0"
"@ethersproject/properties" "^5.6.0"

"@ethersproject/abstract-signer@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/abstract-signer/-/abstract-signer-5.7.0.tgz#13f4f32117868452191a4649723cb086d2b596b2"
integrity sha512-a16V8bq1/Cz+TGCkE2OPMTOUDLS3grCpdjoJCYNnVBbdYEMSgKrU0+B90s8b6H+ByYTBZN7a3g76jdIJi7UfKQ==
dependencies:
"@ethersproject/abstract-provider" "^5.7.0"
"@ethersproject/bignumber" "^5.7.0"
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/logger" "^5.7.0"
"@ethersproject/properties" "^5.7.0"

"@ethersproject/address@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/address/-/address-5.6.1.tgz#ab57818d9aefee919c5721d28cd31fd95eff413d"
Expand All @@ -229,13 +253,31 @@
"@ethersproject/logger" "^5.6.0"
"@ethersproject/rlp" "^5.6.1"

"@ethersproject/address@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/address/-/address-5.7.0.tgz#19b56c4d74a3b0a46bfdbb6cfcc0a153fc697f37"
integrity sha512-9wYhYt7aghVGo758POM5nqcOMaE168Q6aRLJZwUmiqSrAungkG74gSSeKEIR7ukixesdRZGPgVqme6vmxs1fkA==
dependencies:
"@ethersproject/bignumber" "^5.7.0"
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/keccak256" "^5.7.0"
"@ethersproject/logger" "^5.7.0"
"@ethersproject/rlp" "^5.7.0"

"@ethersproject/base64@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/base64/-/base64-5.6.1.tgz#2c40d8a0310c9d1606c2c37ae3092634b41d87cb"
integrity sha512-qB76rjop6a0RIYYMiB4Eh/8n+Hxu2NIZm8S/Q7kNo5pmZfXhHGHmS4MinUainiBC54SCyRnwzL+KZjj8zbsSsw==
dependencies:
"@ethersproject/bytes" "^5.6.1"

"@ethersproject/base64@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/base64/-/base64-5.7.0.tgz#ac4ee92aa36c1628173e221d0d01f53692059e1c"
integrity sha512-Dr8tcHt2mEbsZr/mwTPIQAf3Ai0Bks/7gTw9dSqk1mQvhW3XvRlmDJr/4n+wg1JmCl16NZue17CDh8xb/vZ0sQ==
dependencies:
"@ethersproject/bytes" "^5.7.0"

"@ethersproject/basex@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/basex/-/basex-5.6.1.tgz#badbb2f1d4a6f52ce41c9064f01eab19cc4c5305"
Expand Down Expand Up @@ -320,6 +362,21 @@
"@ethersproject/properties" "^5.6.0"
"@ethersproject/strings" "^5.6.1"

"@ethersproject/hash@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/hash/-/hash-5.7.0.tgz#eb7aca84a588508369562e16e514b539ba5240a7"
integrity sha512-qX5WrQfnah1EFnO5zJv1v46a8HW0+E5xuBBDTwMFZLuVTx0tbU2kkx15NqdjxecrLGatQN9FGQKpb1FKdHCt+g==
dependencies:
"@ethersproject/abstract-signer" "^5.7.0"
"@ethersproject/address" "^5.7.0"
"@ethersproject/base64" "^5.7.0"
"@ethersproject/bignumber" "^5.7.0"
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/keccak256" "^5.7.0"
"@ethersproject/logger" "^5.7.0"
"@ethersproject/properties" "^5.7.0"
"@ethersproject/strings" "^5.7.0"

"@ethersproject/hdnode@^5.6.2":
version "5.6.2"
resolved "https://registry.yarnpkg.com/@ethersproject/hdnode/-/hdnode-5.6.2.tgz#26f3c83a3e8f1b7985c15d1db50dc2903418b2d2"
Expand Down Expand Up @@ -365,6 +422,14 @@
"@ethersproject/bytes" "^5.6.1"
js-sha3 "0.8.0"

"@ethersproject/keccak256@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/keccak256/-/keccak256-5.7.0.tgz#3186350c6e1cd6aba7940384ec7d6d9db01f335a"
integrity sha512-2UcPboeL/iW+pSg6vZ6ydF8tCnv3Iu/8tUmLLzWWGzxWKFFqOBQFLo6uLUv6BDrLgCDfN28RJ/wtByx+jZ4KBg==
dependencies:
"@ethersproject/bytes" "^5.7.0"
js-sha3 "0.8.0"

"@ethersproject/logger@^5.6.0":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.6.0.tgz#d7db1bfcc22fd2e4ab574cba0bb6ad779a9a3e7a"
Expand All @@ -382,6 +447,13 @@
dependencies:
"@ethersproject/logger" "^5.6.0"

"@ethersproject/networks@^5.7.0":
version "5.7.1"
resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.7.1.tgz#118e1a981d757d45ccea6bb58d9fd3d9db14ead6"
integrity sha512-n/MufjFYv3yFcUyfhnXotyDlNdFb7onmkSy8aQERi2PjNcnWQ66xXxa3XlS8nCcA8aJKJjIIMNJTC7tu80GwpQ==
dependencies:
"@ethersproject/logger" "^5.7.0"

"@ethersproject/pbkdf2@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/pbkdf2/-/pbkdf2-5.6.1.tgz#f462fe320b22c0d6b1d72a9920a3963b09eb82d1"
Expand All @@ -397,6 +469,13 @@
dependencies:
"@ethersproject/logger" "^5.6.0"

"@ethersproject/properties@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/properties/-/properties-5.7.0.tgz#a6e12cb0439b878aaf470f1902a176033067ed30"
integrity sha512-J87jy8suntrAkIZtecpxEPxY//szqr1mlBaYlQ0r4RCaiD2hjheqF9s1LVE8vVuJCXisjIP+JgtK/Do54ej4Sw==
dependencies:
"@ethersproject/logger" "^5.7.0"

"@ethersproject/providers@^5.6.8":
version "5.6.8"
resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.6.8.tgz#22e6c57be215ba5545d3a46cf759d265bb4e879d"
Expand Down Expand Up @@ -439,6 +518,14 @@
"@ethersproject/bytes" "^5.6.1"
"@ethersproject/logger" "^5.6.0"

"@ethersproject/rlp@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/rlp/-/rlp-5.7.0.tgz#de39e4d5918b9d74d46de93af80b7685a9c21304"
integrity sha512-rBxzX2vK8mVF7b0Tol44t5Tb8gomOHkj5guL+HhzQ1yBh/ydjGnpw6at+X6Iw0Kp3OzzzkcKp8N9r0W4kYSs9w==
dependencies:
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/logger" "^5.7.0"

"@ethersproject/sha2@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/sha2/-/sha2-5.6.1.tgz#211f14d3f5da5301c8972a8827770b6fd3e51656"
Expand All @@ -460,6 +547,18 @@
elliptic "6.5.4"
hash.js "1.1.7"

"@ethersproject/signing-key@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/signing-key/-/signing-key-5.7.0.tgz#06b2df39411b00bc57c7c09b01d1e41cf1b16ab3"
integrity sha512-MZdy2nL3wO0u7gkB4nA/pEf8lu1TlFswPNmy8AiYkfKTdO6eXBJyUdmHO/ehm/htHw9K/qF8ujnTyUAD+Ry54Q==
dependencies:
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/logger" "^5.7.0"
"@ethersproject/properties" "^5.7.0"
bn.js "^5.2.1"
elliptic "6.5.4"
hash.js "1.1.7"

"@ethersproject/strings@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/strings/-/strings-5.6.1.tgz#dbc1b7f901db822b5cafd4ebf01ca93c373f8952"
Expand All @@ -469,6 +568,15 @@
"@ethersproject/constants" "^5.6.1"
"@ethersproject/logger" "^5.6.0"

"@ethersproject/strings@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/strings/-/strings-5.7.0.tgz#54c9d2a7c57ae8f1205c88a9d3a56471e14d5ed2"
integrity sha512-/9nu+lj0YswRNSH0NXYqrh8775XNyEdUQAuf3f+SmOrnVewcJ5SBNAjF7lpgehKi4abvNNXyf+HX86czCdJ8Mg==
dependencies:
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/constants" "^5.7.0"
"@ethersproject/logger" "^5.7.0"

"@ethersproject/transactions@^5.6.2":
version "5.6.2"
resolved "https://registry.yarnpkg.com/@ethersproject/transactions/-/transactions-5.6.2.tgz#793a774c01ced9fe7073985bb95a4b4e57a6370b"
Expand All @@ -484,6 +592,21 @@
"@ethersproject/rlp" "^5.6.1"
"@ethersproject/signing-key" "^5.6.2"

"@ethersproject/transactions@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/transactions/-/transactions-5.7.0.tgz#91318fc24063e057885a6af13fdb703e1f993d3b"
integrity sha512-kmcNicCp1lp8qanMTC3RIikGgoJ80ztTyvtsFvCYpSCfkjhD0jZ2LOrnbcuxuToLIUYYf+4XwD1rP+B/erDIhQ==
dependencies:
"@ethersproject/address" "^5.7.0"
"@ethersproject/bignumber" "^5.7.0"
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/constants" "^5.7.0"
"@ethersproject/keccak256" "^5.7.0"
"@ethersproject/logger" "^5.7.0"
"@ethersproject/properties" "^5.7.0"
"@ethersproject/rlp" "^5.7.0"
"@ethersproject/signing-key" "^5.7.0"

"@ethersproject/units@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/units/-/units-5.7.0.tgz#637b563d7e14f42deeee39245275d477aae1d8b1"
Expand Down Expand Up @@ -525,6 +648,17 @@
"@ethersproject/properties" "^5.6.0"
"@ethersproject/strings" "^5.6.1"

"@ethersproject/web@^5.7.0":
version "5.7.1"
resolved "https://registry.yarnpkg.com/@ethersproject/web/-/web-5.7.1.tgz#de1f285b373149bee5928f4eb7bcb87ee5fbb4ae"
integrity sha512-Gueu8lSvyjBWL4cYsWsjh6MtMwM0+H4HvqFPZfB6dV8ctbP9zFAO73VG1cMWae0FLPCtz0peKPpZY8/ugJJX2w==
dependencies:
"@ethersproject/base64" "^5.7.0"
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/logger" "^5.7.0"
"@ethersproject/properties" "^5.7.0"
"@ethersproject/strings" "^5.7.0"

"@ethersproject/wordlists@^5.6.1":
version "5.6.1"
resolved "https://registry.yarnpkg.com/@ethersproject/wordlists/-/wordlists-5.6.1.tgz#1e78e2740a8a21e9e99947e47979d72e130aeda1"
Expand Down

0 comments on commit 6ec615c

Please sign in to comment.