@certik/skynet 0.10.6 → 0.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/availability.js CHANGED
@@ -1,58 +1,58 @@
1
- async function wait(time) {
2
- return new Promise(resolve => {
3
- setTimeout(resolve, time);
4
- });
5
- }
6
-
7
- async function retry(times, verbose, func) {
8
- try {
9
- await func();
10
- } catch (err) {
11
- if (times <= 1) {
12
- console.log("failed to retry", err);
13
- throw err;
14
- } else {
15
- if (verbose) {
16
- console.log("retry catch error", err);
17
- console.log("retrying remaining times=", times - 1);
18
- }
19
- await wait(5000);
20
- await retry(times - 1, verbose, func);
21
- }
22
- }
23
- }
24
-
25
- async function exponentialRetry(
26
- func,
27
- { maxRetry, initialDuration, growFactor, test, verbose }
28
- ) {
29
- let retries = maxRetry;
30
- let duration = initialDuration || 5000;
31
- let growFactorFinal = growFactor || 2;
32
-
33
- let result = await func();
34
-
35
- while (!test(result) && retries > 0) {
36
- if (verbose) {
37
- console.log("failed attempt result", result);
38
- }
39
-
40
- console.log(
41
- `sleep for ${duration}s after failed attempt, remaining ${retries} attempts`
42
- );
43
- retries = retries - 1;
44
-
45
- await wait(duration);
46
-
47
- result = await func();
48
- duration = duration * growFactorFinal;
49
- }
50
-
51
- return result;
52
- }
53
-
54
- module.exports = {
55
- wait,
56
- retry,
57
- exponentialRetry
58
- };
1
+ async function wait(time) {
2
+ return new Promise(resolve => {
3
+ setTimeout(resolve, time);
4
+ });
5
+ }
6
+
7
+ async function retry(times, verbose, func) {
8
+ try {
9
+ await func();
10
+ } catch (err) {
11
+ if (times <= 1) {
12
+ console.log("failed to retry", err);
13
+ throw err;
14
+ } else {
15
+ if (verbose) {
16
+ console.log("retry catch error", err);
17
+ console.log("retrying remaining times=", times - 1);
18
+ }
19
+ await wait(5000);
20
+ await retry(times - 1, verbose, func);
21
+ }
22
+ }
23
+ }
24
+
25
+ async function exponentialRetry(
26
+ func,
27
+ { maxRetry, initialDuration, growFactor, test, verbose }
28
+ ) {
29
+ let retries = maxRetry;
30
+ let duration = initialDuration || 5000;
31
+ let growFactorFinal = growFactor || 2;
32
+
33
+ let result = await func();
34
+
35
+ while (!test(result) && retries > 0) {
36
+ if (verbose) {
37
+ console.log("failed attempt result", result);
38
+ }
39
+
40
+ console.log(
41
+ `sleep for ${duration}s after failed attempt, remaining ${retries} attempts`
42
+ );
43
+ retries = retries - 1;
44
+
45
+ await wait(duration);
46
+
47
+ result = await func();
48
+ duration = duration * growFactorFinal;
49
+ }
50
+
51
+ return result;
52
+ }
53
+
54
+ module.exports = {
55
+ wait,
56
+ retry,
57
+ exponentialRetry
58
+ };
package/block.js CHANGED
@@ -1,83 +1,83 @@
1
- const { getEnvironment } = require("./env");
2
- const { PROTOCOLS } = require("./const");
3
- const { readFile } = require("./s3");
4
- const { getRecordByKey } = require("./dynamodb");
5
- const fetch = require("node-fetch");
6
- const Web3 = require("web3");
7
-
8
- const S3_BUCKET_NAME =
9
- getEnvironment() === "prd" ? "certik-skynet" : "certik-skynet-dev";
10
- const INDEXER_STATE_TABLE = `skynet-${getEnvironment()}-indexer-state`;
11
-
12
- function leftPad3(num) {
13
- if (num === 0) {
14
- return "000";
15
- } else if (num < 10) {
16
- return "00" + String(num);
17
- } else if (num < 100) {
18
- return "0" + String(num);
19
- } else {
20
- return String(num);
21
- }
22
- }
23
-
24
- function getBlockS3Path(protocol, height) {
25
- return `chaindata/${protocol}/${Math.floor(height / 1_000_000)}/${leftPad3(
26
- Math.floor(height / 1_000) % 1000
27
- )}/${leftPad3(height % 1000)}.json`;
28
- }
29
-
30
- // We use this function instead of web3 because the gas limits on bsc exceed
31
- // the size supported by javascript numbers, and web3 does not support this
32
- async function getBlock(protocol, height) {
33
- const body = {
34
- jsonrpc: "2.0",
35
- method: "eth_getBlockByNumber",
36
- params: [`0x${height.toString(16)}`, true],
37
- id: 1
38
- };
39
- const response = await fetch(PROTOCOLS[protocol].endpoint, {
40
- method: "POST",
41
- headers: {
42
- "Content-Type": "application/json"
43
- },
44
- body: JSON.stringify(body)
45
- });
46
-
47
- const { result: block } = await response.json();
48
-
49
- return block;
50
- }
51
-
52
- async function getLatestBlockHeight(protocol) {
53
- const web3 = new Web3(PROTOCOLS[protocol].endpoint);
54
- const isSyncing = await web3.eth.isSyncing();
55
-
56
- if (isSyncing) {
57
- return isSyncing.currentBlock;
58
- } else {
59
- const latestBlock = await web3.eth.getBlock("latest");
60
-
61
- return latestBlock.number;
62
- }
63
- }
64
-
65
- async function getLatestS3BlockHeight(protocol) {
66
- const name = `AMLBlockIndexerSince(protocol=${protocol})`;
67
- const { value: height } = await getRecordByKey(INDEXER_STATE_TABLE, { name });
68
- return height;
69
- }
70
-
71
- async function getBlockFromS3(protocol, height) {
72
- const body = await readFile(S3_BUCKET_NAME, getBlockS3Path(protocol, height));
73
-
74
- return JSON.parse(body);
75
- }
76
-
77
- module.exports = {
78
- getLatestBlockHeight,
79
- getBlock,
80
- getBlockS3Path,
81
- getLatestS3BlockHeight,
82
- getBlockFromS3
83
- };
1
+ const { getEnvironment } = require("./env");
2
+ const { PROTOCOLS } = require("./const");
3
+ const { readFile } = require("./s3");
4
+ const { getRecordByKey } = require("./dynamodb");
5
+ const fetch = require("node-fetch");
6
+ const Web3 = require("web3");
7
+
8
+ const S3_BUCKET_NAME =
9
+ getEnvironment() === "prd" ? "certik-skynet" : "certik-skynet-dev";
10
+ const INDEXER_STATE_TABLE = `skynet-${getEnvironment()}-indexer-state`;
11
+
12
+ function leftPad3(num) {
13
+ if (num === 0) {
14
+ return "000";
15
+ } else if (num < 10) {
16
+ return "00" + String(num);
17
+ } else if (num < 100) {
18
+ return "0" + String(num);
19
+ } else {
20
+ return String(num);
21
+ }
22
+ }
23
+
24
+ function getBlockS3Path(protocol, height) {
25
+ return `chaindata/${protocol}/${Math.floor(height / 1_000_000)}/${leftPad3(
26
+ Math.floor(height / 1_000) % 1000
27
+ )}/${leftPad3(height % 1000)}.json`;
28
+ }
29
+
30
+ // We use this function instead of web3 because the gas limits on bsc exceed
31
+ // the size supported by javascript numbers, and web3 does not support this
32
+ async function getBlock(protocol, height) {
33
+ const body = {
34
+ jsonrpc: "2.0",
35
+ method: "eth_getBlockByNumber",
36
+ params: [`0x${height.toString(16)}`, true],
37
+ id: 1
38
+ };
39
+ const response = await fetch(PROTOCOLS[protocol].endpoint, {
40
+ method: "POST",
41
+ headers: {
42
+ "Content-Type": "application/json"
43
+ },
44
+ body: JSON.stringify(body)
45
+ });
46
+
47
+ const { result: block } = await response.json();
48
+
49
+ return block;
50
+ }
51
+
52
+ async function getLatestBlockHeight(protocol) {
53
+ const web3 = new Web3(PROTOCOLS[protocol].endpoint);
54
+ const isSyncing = await web3.eth.isSyncing();
55
+
56
+ if (isSyncing) {
57
+ return isSyncing.currentBlock;
58
+ } else {
59
+ const latestBlock = await web3.eth.getBlock("latest");
60
+
61
+ return latestBlock.number;
62
+ }
63
+ }
64
+
65
+ async function getLatestS3BlockHeight(protocol) {
66
+ const name = `AMLBlockIndexerSince(protocol=${protocol})`;
67
+ const { value: height } = await getRecordByKey(INDEXER_STATE_TABLE, { name });
68
+ return height;
69
+ }
70
+
71
+ async function getBlockFromS3(protocol, height) {
72
+ const body = await readFile(S3_BUCKET_NAME, getBlockS3Path(protocol, height));
73
+
74
+ return JSON.parse(body);
75
+ }
76
+
77
+ module.exports = {
78
+ getLatestBlockHeight,
79
+ getBlock,
80
+ getBlockS3Path,
81
+ getLatestS3BlockHeight,
82
+ getBlockFromS3
83
+ };
package/cli.js CHANGED
@@ -1,53 +1,53 @@
1
- const path = require("path");
2
- const fs = require("fs");
3
-
4
- function getBinaryName() {
5
- const binaryNameParts = process.argv[1].split(path.sep);
6
- const binaryName = binaryNameParts[binaryNameParts.length - 1];
7
-
8
- return binaryName;
9
- }
10
-
11
- function detectSkynetDirectory() {
12
- return detectDirectory(process.argv[1], "SkynetAPIDefinitions.yml");
13
- }
14
-
15
- function detectWorkingDirectory() {
16
- const wd = detectDirectory(process.argv[1], "package.json");
17
- const skynetd = detectDirectory(process.argv[1], "SkynetAPIDefinitions.yml");
18
-
19
- return wd.slice(skynetd.length + path.sep.length).replace(path.sep, "/");
20
- }
21
-
22
- function detectDirectory(fullBinPath, sentinel = "package.json") {
23
- let parentFolder = path.dirname(fullBinPath);
24
-
25
- while (parentFolder) {
26
- // check if parentFolder length is greater than 0
27
- const sentinelPath = path.join(parentFolder, sentinel);
28
- if (fs.existsSync(sentinelPath)) {
29
- return parentFolder;
30
- }
31
- const newParentFolder = path.dirname(parentFolder);
32
- if (newParentFolder === parentFolder) {
33
- // we have reached the root folder
34
- break;
35
- }
36
- parentFolder = newParentFolder;
37
- }
38
-
39
- throw new Error("Cannot detect current working directory");
40
- }
41
-
42
- function detectBin() {
43
- const wd = detectDirectory(process.argv[1], "package.json");
44
-
45
- return process.argv[1].slice(wd.length + path.sep.length).replace(path.sep, "/");
46
- }
47
-
48
- module.exports = {
49
- getBinaryName,
50
- detectSkynetDirectory,
51
- detectWorkingDirectory,
52
- detectBin,
53
- };
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+
4
+ function getBinaryName() {
5
+ const binaryNameParts = process.argv[1].split(path.sep);
6
+ const binaryName = binaryNameParts[binaryNameParts.length - 1];
7
+
8
+ return binaryName;
9
+ }
10
+
11
+ function detectSkynetDirectory() {
12
+ return detectDirectory(process.argv[1], "SkynetAPIDefinitions.yml");
13
+ }
14
+
15
+ function detectWorkingDirectory() {
16
+ const wd = detectDirectory(process.argv[1], "package.json");
17
+ const skynetd = detectDirectory(process.argv[1], "SkynetAPIDefinitions.yml");
18
+
19
+ return wd.slice(skynetd.length + path.sep.length).replace(path.sep, "/");
20
+ }
21
+
22
+ function detectDirectory(fullBinPath, sentinel = "package.json") {
23
+ let parentFolder = path.dirname(fullBinPath);
24
+
25
+ while (parentFolder) {
26
+ // check if parentFolder length is greater than 0
27
+ const sentinelPath = path.join(parentFolder, sentinel);
28
+ if (fs.existsSync(sentinelPath)) {
29
+ return parentFolder;
30
+ }
31
+ const newParentFolder = path.dirname(parentFolder);
32
+ if (newParentFolder === parentFolder) {
33
+ // we have reached the root folder
34
+ break;
35
+ }
36
+ parentFolder = newParentFolder;
37
+ }
38
+
39
+ throw new Error("Cannot detect current working directory");
40
+ }
41
+
42
+ function detectBin() {
43
+ const wd = detectDirectory(process.argv[1], "package.json");
44
+
45
+ return process.argv[1].slice(wd.length + path.sep.length).replace(path.sep, "/");
46
+ }
47
+
48
+ module.exports = {
49
+ getBinaryName,
50
+ detectSkynetDirectory,
51
+ detectWorkingDirectory,
52
+ detectBin,
53
+ };
package/const.js CHANGED
@@ -1,92 +1,92 @@
1
- const {
2
- getEtherScanApiKey,
3
- getBscScanApiKey,
4
- getPolygonScanApiKey,
5
- getGetBlockApiKey,
6
- getAlchemyApiKey,
7
- getNodeRealApiKey,
8
- } = require("./env");
9
-
10
- const SKYNET_API_PREFIX = "https://api.certik-skynet.com";
11
-
12
- const PROTOCOLS = {
13
- eth: {
14
- nativeTokenName: "Ethereum",
15
- nativeTokenSymbol: "ETH",
16
- nativeTokenDecimals: 18,
17
- nativeTokenAddress: "eth:0x0000000000000000000000000000000000000000",
18
- nativeTokenLogo: `https://token-logo.certik-assets.com/eth:0x0000000000000000000000000000000000000000.png`,
19
- nativeTokenCoinGeckoId: "ethereum",
20
- nativeTokenCmcId: 1027,
21
- endpoint: "https://eth-full-node.certik-skynet.com",
22
- archiveEndpoint: "https://eth-node.certik-skynet.com",
23
- tokenStandard: "ERC20",
24
- scanApi: {
25
- endpoint: "https://api.etherscan.io/api",
26
- key: getEtherScanApiKey(),
27
- },
28
- multiCallProvider: "0xCa731e0f33Afbcfa9363d6F7449d1f5447d10C80",
29
- scanUrl: "https://etherscan.io/",
30
- },
31
- bsc: {
32
- nativeTokenName: "Binance Coin",
33
- nativeTokenSymbol: "BNB",
34
- nativeTokenDecimals: 18,
35
- nativeTokenAddress: "bsc:0x0000000000000000000000000000000000000000",
36
- nativeTokenLogo: `https://token-logo.certik-assets.com/bsc:0x0000000000000000000000000000000000000000.png`,
37
- nativeTokenCoinGeckoId: "binance-coin",
38
- nativeTokenCmcId: 1839,
39
- endpoint: "https://bsc-full-node.certik-skynet.com",
40
- archiveEndpoint: `https://bsc-mainnet.nodereal.io/v1/${getNodeRealApiKey("BSC")}`,
41
- tokenStandard: "BEP20",
42
- scanApi: {
43
- endpoint: "https://api.bscscan.com/api",
44
- key: getBscScanApiKey(),
45
- },
46
- multiCallProvider: "0xe7144e57d832c9005D252f415d205b4b8D78228e",
47
- scanUrl: "https://bscscan.com/",
48
- },
49
- polygon: {
50
- nativeTokenName: "Polygon",
51
- nativeTokenSymbol: "MATIC",
52
- nativeTokenDecimals: 18,
53
- nativeTokenAddress: "polygon:0x0000000000000000000000000000000000000000",
54
- nativeTokenLogo: `https://token-logo.certik-assets.com/polygon:0x0000000000000000000000000000000000000000.png`,
55
- nativeTokenCoinGeckoId: "matic-network",
56
- nativeTokenCmcId: 3890,
57
- endpoint: `https://poly-full-node.certik-skynet.com`,
58
- backupEndpoint: `https://matic.getblock.io/mainnet/?api_key=${getGetBlockApiKey()}`,
59
- archiveEndpoint: `https://polygon-mainnet.g.alchemy.com/v2/${getAlchemyApiKey("POLYGON")}`,
60
- tokenStandard: "ERC20",
61
- scanApi: {
62
- endpoint: "https://api.polygonscan.com/api",
63
- key: getPolygonScanApiKey(),
64
- },
65
- multiCallProvider: "0x8eC86392e0aDB57d00fDffbA39b8870e107c0757",
66
- scanUrl: "https://polygonscan.com/",
67
- },
68
- };
69
-
70
- const TIME = {
71
- BY_MS: {
72
- SECOND: 1000,
73
- MINUTE: 1000 * 60,
74
- HOUR: 1000 * 60 * 60,
75
- DAY: 1000 * 60 * 60 * 24,
76
- WEEK: 1000 * 60 * 60 * 24 * 7,
77
- YEAR: 1000 * 60 * 60 * 24 * 365,
78
- },
79
- BY_S: {
80
- MINUTE: 60,
81
- HOUR: 60 * 60,
82
- DAY: 60 * 60 * 24,
83
- WEEK: 60 * 60 * 24 * 7,
84
- YEAR: 60 * 60 * 24 * 365,
85
- },
86
- };
87
-
88
- module.exports = {
89
- SKYNET_API_PREFIX,
90
- PROTOCOLS,
91
- TIME,
92
- };
1
+ const {
2
+ getEtherScanApiKey,
3
+ getBscScanApiKey,
4
+ getPolygonScanApiKey,
5
+ getGetBlockApiKey,
6
+ getAlchemyApiKey,
7
+ getNodeRealApiKey,
8
+ } = require("./env");
9
+
10
+ const SKYNET_API_PREFIX = "https://api.certik-skynet.com";
11
+
12
+ const PROTOCOLS = {
13
+ eth: {
14
+ nativeTokenName: "Ethereum",
15
+ nativeTokenSymbol: "ETH",
16
+ nativeTokenDecimals: 18,
17
+ nativeTokenAddress: "eth:0x0000000000000000000000000000000000000000",
18
+ nativeTokenLogo: `https://token-logo.certik-assets.com/eth:0x0000000000000000000000000000000000000000.png`,
19
+ nativeTokenCoinGeckoId: "ethereum",
20
+ nativeTokenCmcId: 1027,
21
+ endpoint: "https://eth-full-node.certik-skynet.com",
22
+ archiveEndpoint: "https://eth-node.certik-skynet.com",
23
+ tokenStandard: "ERC20",
24
+ scanApi: {
25
+ endpoint: "https://api.etherscan.io/api",
26
+ key: getEtherScanApiKey(),
27
+ },
28
+ multiCallProvider: "0xCa731e0f33Afbcfa9363d6F7449d1f5447d10C80",
29
+ scanUrl: "https://etherscan.io/",
30
+ },
31
+ bsc: {
32
+ nativeTokenName: "Binance Coin",
33
+ nativeTokenSymbol: "BNB",
34
+ nativeTokenDecimals: 18,
35
+ nativeTokenAddress: "bsc:0x0000000000000000000000000000000000000000",
36
+ nativeTokenLogo: `https://token-logo.certik-assets.com/bsc:0x0000000000000000000000000000000000000000.png`,
37
+ nativeTokenCoinGeckoId: "binance-coin",
38
+ nativeTokenCmcId: 1839,
39
+ endpoint: "https://bsc-full-node.certik-skynet.com",
40
+ archiveEndpoint: `https://bsc-mainnet.nodereal.io/v1/${getNodeRealApiKey("BSC")}`,
41
+ tokenStandard: "BEP20",
42
+ scanApi: {
43
+ endpoint: "https://api.bscscan.com/api",
44
+ key: getBscScanApiKey(),
45
+ },
46
+ multiCallProvider: "0xe7144e57d832c9005D252f415d205b4b8D78228e",
47
+ scanUrl: "https://bscscan.com/",
48
+ },
49
+ polygon: {
50
+ nativeTokenName: "Polygon",
51
+ nativeTokenSymbol: "MATIC",
52
+ nativeTokenDecimals: 18,
53
+ nativeTokenAddress: "polygon:0x0000000000000000000000000000000000000000",
54
+ nativeTokenLogo: `https://token-logo.certik-assets.com/polygon:0x0000000000000000000000000000000000000000.png`,
55
+ nativeTokenCoinGeckoId: "matic-network",
56
+ nativeTokenCmcId: 3890,
57
+ endpoint: `https://poly-full-node.certik-skynet.com`,
58
+ backupEndpoint: `https://matic.getblock.io/mainnet/?api_key=${getGetBlockApiKey()}`,
59
+ archiveEndpoint: `https://polygon-mainnet.g.alchemy.com/v2/${getAlchemyApiKey("POLYGON")}`,
60
+ tokenStandard: "ERC20",
61
+ scanApi: {
62
+ endpoint: "https://api.polygonscan.com/api",
63
+ key: getPolygonScanApiKey(),
64
+ },
65
+ multiCallProvider: "0x8eC86392e0aDB57d00fDffbA39b8870e107c0757",
66
+ scanUrl: "https://polygonscan.com/",
67
+ },
68
+ };
69
+
70
+ const TIME = {
71
+ BY_MS: {
72
+ SECOND: 1000,
73
+ MINUTE: 1000 * 60,
74
+ HOUR: 1000 * 60 * 60,
75
+ DAY: 1000 * 60 * 60 * 24,
76
+ WEEK: 1000 * 60 * 60 * 24 * 7,
77
+ YEAR: 1000 * 60 * 60 * 24 * 365,
78
+ },
79
+ BY_S: {
80
+ MINUTE: 60,
81
+ HOUR: 60 * 60,
82
+ DAY: 60 * 60 * 24,
83
+ WEEK: 60 * 60 * 24 * 7,
84
+ YEAR: 60 * 60 * 24 * 365,
85
+ },
86
+ };
87
+
88
+ module.exports = {
89
+ SKYNET_API_PREFIX,
90
+ PROTOCOLS,
91
+ TIME,
92
+ };