Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add main function to fetch all market cap data #79

Merged
merged 4 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Internal files used by Minswap team
35 changes: 35 additions & 0 deletions internal/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { backOff } from "exponential-backoff";
import fs from "fs";

import { SupplyFetcherResponse, supplyFetchers } from "../src";

async function main(): Promise<void> {
const marketCapData: Record<string, SupplyFetcherResponse> = {};
for (const [key, supplyFetcher] of Object.entries(supplyFetchers)) {
try {
await backOff(
async () => {
const data = await supplyFetcher();
marketCapData[key] = data;
},
{
retry(err, attempt): boolean {
// eslint-disable-next-line no-console
console.error(
`fail to run fetcher for ${key}, retry ${attempt}...`,
err
);
return true;
},
numOfAttempts: 3,
}
);
} catch (err) {
// eslint-disable-next-line no-console
console.error(`fail to run fetcher for ${key}`, err);
}
}
fs.writeFileSync("/tmp/market-cap.json", JSON.stringify(marketCapData));
}

void main();
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"build": "rimraf build && rollup -c rollup.config.js",
"test": "jest",
"format": "prettier --write **/*.{ts,tsx} && eslint --fix --ext .ts,.tsx .",
"check-format": "prettier --check **/*.{ts,tsx} && eslint --ext .ts,.tsx ."
"check-format": "prettier --check **/*.{ts,tsx} && eslint --ext .ts,.tsx .",
"run-market-cap": "ts-node internal/main.ts"
},
"keywords": [
"minswap",
Expand Down Expand Up @@ -46,6 +47,7 @@
"eslint": "^8.34.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"exponential-backoff": "^3.1.1",
"jest": "^29.4.2",
"prettier": "^2.8.4",
"rollup": "^2.70.2",
Expand Down