Skip to content

Commit 2d17a8e

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents f4bec9c + 33d9b74 commit 2d17a8e

File tree

7 files changed

+41
-140
lines changed

7 files changed

+41
-140
lines changed

package-lock.json

Lines changed: 1 addition & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.2.18",
3+
"version": "0.3.0",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",
@@ -9,14 +9,10 @@
99
"types": "dist/index.d.ts",
1010
"dependencies": {
1111
"@ethersproject/abi": "^5.0.4",
12-
"@ethersproject/address": "^5.0.4",
13-
"@ethersproject/bignumber": "^5.0.12",
1412
"@ethersproject/bytes": "^5.0.8",
1513
"@ethersproject/contracts": "^5.0.3",
1614
"@ethersproject/hash": "^5.0.9",
1715
"@ethersproject/providers": "^5.3.1",
18-
"@ethersproject/solidity": "^5.0.10",
19-
"@ethersproject/strings": "^5.0.5",
2016
"@ethersproject/wallet": "^5.4.0",
2117
"ajv": "^8.6.0",
2218
"ajv-formats": "^2.1.0",

src/networks.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,12 @@
437437
},
438438
"42161": {
439439
"key": "42161",
440-
"disabled": true,
441440
"name": "Arbitrum One",
442441
"chainId": 42161,
443442
"network": "Arbitrum mainnet",
444443
"multicall": "0x7A7443F8c577d537f1d8cD4a629d40a3148Dd7ee",
445444
"rpc": [
446-
"https://arb-mainnet.g.alchemy.com/v2/m_ihy38lo1YvShY4RP8JMJncWLudTCQY"
445+
"https://arb-mainnet.g.alchemy.com/v2/JDvtNGwnHhTltIwfnxQocKwKkCTKA1DL"
447446
],
448447
"explorer": "https://arbiscan.io"
449448
},

src/sign/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class Client {
5050
if (web3 instanceof Wallet) signer = web3;
5151
if (web3 instanceof Web3Provider) signer = web3.getSigner();
5252
if (!message.from) message.from = address;
53-
if (!message.timestamp) message.timestamp = ~~(Date.now() / 1e3);
53+
if (!message.timestamp) message.timestamp = parseInt((Date.now() / 1e3).toFixed());
5454
const data: any = { domain, types, message };
5555
const sig = await signer._signTypedData(domain, data.types, message);
5656
console.log('Sign', { address, sig, data });

src/utils.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fetch from 'cross-fetch';
22
import { Interface } from '@ethersproject/abi';
33
import { Contract } from '@ethersproject/contracts';
4-
import { StaticJsonRpcProvider } from '@ethersproject/providers';
4+
import { namehash } from '@ethersproject/hash';
55
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
66
import Ajv from 'ajv';
77
import addFormats from 'ajv-formats';
@@ -19,8 +19,6 @@ export const SNAPSHOT_SUBGRAPH_URL = {
1919
'42': 'https://api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-kovan'
2020
};
2121

22-
export const SNAPSHOT_SCORE_API = 'https://score.snapshot.org/api/scores';
23-
2422
export async function call(provider, abi: any[], call: any[], options?) {
2523
const contract = new Contract(call[0], abi, provider);
2624
try {
@@ -116,9 +114,9 @@ export async function getScores(
116114
space: string,
117115
strategies: any[],
118116
network: string,
119-
provider: StaticJsonRpcProvider | string,
120117
addresses: string[],
121-
snapshot: number | string = 'latest'
118+
snapshot: number | string = 'latest',
119+
scoreApiUrl = 'https://score.snapshot.org/api/scores'
122120
) {
123121
try {
124122
const params = {
@@ -128,7 +126,7 @@ export async function getScores(
128126
strategies,
129127
addresses
130128
};
131-
const res = await fetch(SNAPSHOT_SCORE_API, {
129+
const res = await fetch(scoreApiUrl, {
132130
method: 'POST',
133131
headers: { 'Content-Type': 'application/json' },
134132
body: JSON.stringify({ params })
@@ -149,6 +147,36 @@ export function validateSchema(schema, data) {
149147
return valid ? valid : validate.errors;
150148
}
151149

150+
export async function getSpaceUri(id) {
151+
const abi =
152+
'function text(bytes32 node, string calldata key) external view returns (string memory)';
153+
const address = '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41';
154+
155+
let uri: any = false;
156+
try {
157+
const hash = namehash(id);
158+
const provider = getProvider('1');
159+
uri = await call(
160+
provider,
161+
[abi],
162+
[address, 'text', [hash, 'snapshot']]
163+
);
164+
} catch (e) {
165+
console.log('getSpaceUriFromTextRecord failed', id, e);
166+
}
167+
return uri;
168+
}
169+
170+
export function clone(item) {
171+
return JSON.parse(JSON.stringify(item));
172+
}
173+
174+
export async function sleep(time) {
175+
return new Promise(resolve => {
176+
setTimeout(resolve, time);
177+
});
178+
}
179+
152180
export default {
153181
call,
154182
multicall,
@@ -158,6 +186,9 @@ export default {
158186
sendTransaction,
159187
getScores,
160188
validateSchema,
189+
getSpaceUri,
190+
clone,
191+
sleep,
161192
getProvider,
162193
signMessage,
163194
getBlockNumber,

src/validations/aave/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export default async function validate(
4242
space.id || space.key,
4343
strategies,
4444
space.network,
45-
'',
4645
[author]
4746
);
4847
const totalScore: any = scores

src/validations/basic/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export default async function validate(
2020
space.id || space.key,
2121
strategies,
2222
space.network,
23-
'',
2423
[author]
2524
);
2625
const totalScore: any = scores

0 commit comments

Comments
 (0)