diff --git a/internal/README.md b/internal/README.md new file mode 100644 index 00000000..af6c0b8e --- /dev/null +++ b/internal/README.md @@ -0,0 +1 @@ +Internal files used by Minswap team \ No newline at end of file diff --git a/internal/main.ts b/internal/main.ts new file mode 100644 index 00000000..fdef986e --- /dev/null +++ b/internal/main.ts @@ -0,0 +1,35 @@ +import { backOff } from "exponential-backoff"; +import fs from "fs"; + +import { SupplyFetcherResponse, supplyFetchers } from "../src"; + +async function main(): Promise { + const marketCapData: Record = {}; + 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(); diff --git a/package-lock.json b/package-lock.json index 33c3cf54..a62ffabc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@minswap/market-cap", - "version": "0.1.3", + "version": "0.1.12", "license": "MIT", "dependencies": { "@blockfrost/blockfrost-js": "^5.2.0", @@ -24,6 +24,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", @@ -5057,6 +5058,12 @@ "node": ">=0.10.0" } }, + "node_modules/exponential-backoff": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz", + "integrity": "sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==", + "dev": true + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -12746,6 +12753,12 @@ "resolved": "https://registry.npmjs.org/expected-node-version/-/expected-node-version-1.0.2.tgz", "integrity": "sha512-OSaCdgF02srujDqJz1JWGpqk8Rq3uNYHLmtpBHJrZN3BvuMvzijJMqRVxZN1qLJtKVwjXhmOp+lfsRUqx8n54w==" }, + "exponential-backoff": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz", + "integrity": "sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==", + "dev": true + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", diff --git a/package.json b/package.json index d7986062..94019d36 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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",