Skip to content

Commit 56e484b

Browse files
committed
Add getScores function
1 parent 8f6b330 commit 56e484b

8 files changed

+289
-6
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
22
node_modules
3-
# dist
3+
dist
44

55
# Remove some common IDE working directories
66
.idea

package-lock.json

+225-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,29 @@
88
"browser": "dist/snapshot.min.js",
99
"dependencies": {
1010
"@ethersproject/abi": "^5.0.4",
11+
"@ethersproject/address": "^5.0.4",
1112
"@ethersproject/contracts": "^5.0.3",
1213
"@ethersproject/units": "^5.0.3",
1314
"json-to-graphql-query": "^2.0.0"
1415
},
1516
"devDependencies": {
17+
"@ethersproject/providers": "^5.0.9",
1618
"@types/node": "^13.9.5",
1719
"bluebird": "^3.7.2",
1820
"eslint": "^6.8.0",
1921
"eslint-config-airbnb-base": "^14.1.0",
2022
"eslint-plugin-import": "^2.20.2",
2123
"rollup": "^2.3.0",
2224
"rollup-plugin-filesize": "^6.2.1",
25+
"rollup-plugin-json": "^4.0.0",
2326
"rollup-plugin-terser": "^7.0.0",
2427
"rollup-plugin-typescript2": "^0.27.0",
2528
"typescript": "^3.8.3"
2629
},
2730
"scripts": {
2831
"build": "rollup -c",
2932
"dev": "rollup -c -w",
33+
"test": "node test/index.ts",
3034
"pretest": "npm run build"
3135
},
3236
"files": [

rollup.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import typescript from 'rollup-plugin-typescript2';
22
import { terser } from 'rollup-plugin-terser';
33
import filesize from 'rollup-plugin-filesize';
4+
import json from 'rollup-plugin-json';
45
import pkg from './package.json';
56

67
const name = 'snapshot';
@@ -17,6 +18,7 @@ export default [
1718
format: 'iife'
1819
},
1920
plugins: [
21+
json(),
2022
typescript({ clean: true }),
2123
terser(),
2224
filesize()
@@ -30,6 +32,7 @@ export default [
3032
{ file: pkg.module, format: 'es' }
3133
],
3234
plugins: [
35+
json(),
3336
typescript({ clean: true })
3437
]
3538
}

src/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import strategies from './strategies';
2+
import utils from './utils';
3+
4+
export default {
5+
strategies,
6+
utils
7+
}

src/utils.ts

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Interface } from '@ethersproject/abi';
22
import { Contract } from '@ethersproject/contracts';
33
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
44
import { abi as multicallAbi } from './abi/Multicall.json';
5+
import _strategies from './strategies';
56

67
const MULTICALL = {
78
1: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441',
@@ -44,3 +45,23 @@ export async function subgraphRequest(url, query) {
4445
const { data } = await res.json();
4546
return data || {};
4647
}
48+
49+
export async function getScores(strategies, network, provider, addresses, snapshot = 'latest') {
50+
return await Promise.all(
51+
strategies.map(strategy =>
52+
_strategies[strategy[0]](
53+
network,
54+
provider,
55+
addresses,
56+
strategy[1],
57+
snapshot
58+
)
59+
)
60+
);
61+
}
62+
63+
export default {
64+
multicall,
65+
subgraphRequest,
66+
getScores
67+
}

0 commit comments

Comments
 (0)