@certik/skynet 0.8.3 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.7
4
+
5
+ - Change polygon node endpoint
6
+
7
+ ## 0.8.6
8
+
9
+ - Fixed a const.js error
10
+ - support more options in snowflake.js
11
+
12
+ ## 0.8.5
13
+
14
+ - Improve cross-OS compatibility of `detectDirectory` function
15
+
16
+ ## 0.8.4
17
+
18
+ - Added `every` tool to make it easier to build schedule parameter
19
+
3
20
  ## 0.8.2 && 0.8.3
4
21
 
5
22
  - Made check optional for new indexer/producer app
@@ -22,7 +39,7 @@
22
39
 
23
40
  ## 0.7.18
24
41
 
25
- - Added the configurability for getTokenPriceAt function in `token` library
42
+ - Added the configurability for getTokenPriceAt function in `token` library
26
43
 
27
44
  ## 0.7.17
28
45
 
package/app.js CHANGED
@@ -540,4 +540,23 @@ function consumer({ name, selector, consume, check, env = {}, region = "us-east-
540
540
 
541
541
  const SENSITIVE_VALUE = null;
542
542
 
543
- module.exports = { indexer, modeIndexer, producer, consumer, SENSITIVE_VALUE, ERROR_LEVEL };
543
+ const every = (n = 1) => {
544
+ if (n === 1) {
545
+ return {
546
+ second: "*/1 * * * * * *",
547
+ minute: "0 * * * * * *",
548
+ hour: "0 0 * * * * *",
549
+ day: "0 0 0 * * * *",
550
+ week: "0 0 0 * * 0 *",
551
+ };
552
+ }
553
+
554
+ return {
555
+ seconds: `*/${n} * * * * * *`,
556
+ minutes: `0 */${n} * * * * *`,
557
+ hours: `0 0 */${n} * * * *`,
558
+ days: `0 0 0 */${n} * * *`,
559
+ };
560
+ };
561
+
562
+ module.exports = { indexer, modeIndexer, producer, consumer, every, SENSITIVE_VALUE, ERROR_LEVEL };
package/cli.js CHANGED
@@ -16,22 +16,24 @@ function detectWorkingDirectory() {
16
16
  const wd = detectDirectory(process.argv[1], "package.json");
17
17
  const skynetd = detectDirectory(process.argv[1], "SkynetAPIDefinitions.yml");
18
18
 
19
- return wd.slice(skynetd.length + path.sep.length);
19
+ return wd.slice(skynetd.length + path.sep.length).replace(path.sep, "/");
20
20
  }
21
21
 
22
22
  function detectDirectory(fullBinPath, sentinel = "package.json") {
23
- const binaryNameParts = fullBinPath.split(path.sep);
23
+ let parentFolder = path.dirname(fullBinPath);
24
24
 
25
- const parentFolders = [];
26
-
27
- for (let i = binaryNameParts.length - 1; i > 1; i--) {
28
- parentFolders.push(path.join(path.sep, ...binaryNameParts.slice(0, i)));
29
- }
30
-
31
- for (let folder of parentFolders) {
32
- if (fs.existsSync(path.join(folder, sentinel))) {
33
- return folder;
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;
34
35
  }
36
+ parentFolder = newParentFolder;
35
37
  }
36
38
 
37
39
  throw new Error("Cannot detect current working directory");
@@ -40,7 +42,7 @@ function detectDirectory(fullBinPath, sentinel = "package.json") {
40
42
  function detectBin() {
41
43
  const wd = detectDirectory(process.argv[1], "package.json");
42
44
 
43
- return process.argv[1].slice(wd.length + path.sep.length);
45
+ return process.argv[1].slice(wd.length + path.sep.length).replace(path.sep, "/");
44
46
  }
45
47
 
46
48
  module.exports = {
package/const.js CHANGED
@@ -1,4 +1,10 @@
1
- const { getEtherScanApiKey, getBscScanApiKey, getPolygonScanApiKey, getGetBlockApiKey } = require("./env");
1
+ const {
2
+ getEtherScanApiKey,
3
+ getBscScanApiKey,
4
+ getPolygonScanApiKey,
5
+ getGetBlockApiKey,
6
+ getAlchemyApiKey,
7
+ } = require("./env");
2
8
 
3
9
  const SKYNET_API_PREFIX = "https://api.certik-skynet.com";
4
10
 
@@ -42,8 +48,9 @@ const PROTOCOLS = {
42
48
  nativeTokenAddress: "polygon:0x0000000000000000000000000000000000000000",
43
49
  nativeTokenLogo: `https://token-logo.certik-assets.com/polygon:0x0000000000000000000000000000000000000000.png`,
44
50
  nativeTokenCoinGeckoId: "matic-network",
45
- endpoint: `https://matic.getblock.io/mainnet/?api_key=${getGetBlockApiKey()}`,
46
- archiveEndpoint: `https://matic.getblock.io/mainnet/?api_key=${getGetBlockApiKey()}`,
51
+ endpoint: `https://polygon-mainnet.g.alchemy.com/v2/${getAlchemyApiKey("POLYGON")}`,
52
+ backupEndpoint: `https://matic.getblock.io/mainnet/?api_key=${getGetBlockApiKey()}`,
53
+ archiveEndpoint: `https://polygon-mainnet.g.alchemy.com/v2/${getAlchemyApiKey("POLYGON")}`,
47
54
  tokenStandard: "ERC20",
48
55
  scanApi: {
49
56
  endpoint: "https://api.polygonscan.com/api",
@@ -53,70 +60,6 @@ const PROTOCOLS = {
53
60
  },
54
61
  };
55
62
 
56
- const DEXES = {
57
- pancakeswap: {
58
- protocol: "bsc",
59
- factory: {
60
- addr: "0xbcfccbde45ce874adcb698cc183debcf17952812",
61
- topics: ["0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9"],
62
- lbl: "PancakeSwap LP",
63
- createdAt: 586851,
64
- },
65
- router: {
66
- addr: "bsc:0x05ff2b0db69458a0750badebc4f9e13add608c7f",
67
- createdAt: 586899,
68
- },
69
- },
70
- "pancakeswap-v2": {
71
- protocol: "bsc",
72
- factory: {
73
- addr: "0xca143ce32fe78f1f7019d7d551a6402fc5350c73",
74
- topics: ["0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9"],
75
- lbl: "PancakeSwap V2 LP",
76
- createdAt: 6809737,
77
- },
78
- router: {
79
- addr: "bsc:0x10ed43c718714eb63d5aa57b78b54704e256024e",
80
- createdAt: 6810080,
81
- },
82
- },
83
- uniswap: {
84
- protocol: "eth",
85
- factory: {
86
- addr: "0xc0a47dfe034b400b47bdad5fecda2621de6c4d95",
87
- topics: ["0x9d42cb017eb05bd8944ab536a8b35bc68085931dd5f4356489801453923953f9"],
88
- lbl: "Uniswap LP",
89
- createdAt: 6627917,
90
- },
91
- },
92
- "uniswap-v2": {
93
- protocol: "eth",
94
- factory: {
95
- addr: "0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f",
96
- topics: ["0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9"],
97
- lbl: "Uniswap V2 LP",
98
- createdAt: 10000835,
99
- },
100
- router: {
101
- addr: "eth:0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
102
- createdAt: 10207858,
103
- },
104
- },
105
- sushiswap: {
106
- protocol: "eth",
107
- factory: {
108
- addr: "0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac",
109
- topics: ["0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9"],
110
- lbl: "SushiSwap LP",
111
- createdAt: 10794229,
112
- },
113
- router: {
114
- addr: "eth:0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f",
115
- createdAt: 10794261,
116
- },
117
- },
118
- };
119
-
120
63
  const TIME = {
121
64
  BY_MS: {
122
65
  SECOND: 1000,
@@ -124,20 +67,19 @@ const TIME = {
124
67
  HOUR: 1000 * 60 * 60,
125
68
  DAY: 1000 * 60 * 60 * 24,
126
69
  WEEK: 1000 * 60 * 60 * 24 * 7,
127
- YEAR: 1000 * 60 * 60 * 24 * 365
70
+ YEAR: 1000 * 60 * 60 * 24 * 365,
128
71
  },
129
72
  BY_S: {
130
73
  MINUTE: 60,
131
74
  HOUR: 60 * 60,
132
75
  DAY: 60 * 60 * 24,
133
76
  WEEK: 60 * 60 * 24 * 7,
134
- YEAR: 60 * 60 * 24 * 365
135
- }
136
- }
77
+ YEAR: 60 * 60 * 24 * 365,
78
+ },
79
+ };
137
80
 
138
81
  module.exports = {
139
82
  SKYNET_API_PREFIX,
140
83
  PROTOCOLS,
141
- DEXES,
142
- TIME
84
+ TIME,
143
85
  };
package/env.js CHANGED
@@ -30,6 +30,11 @@ function getGetBlockApiKey() {
30
30
  return ensureAndGet("SKYNET_GETBLOCK_API_KEY");
31
31
  }
32
32
 
33
+ function getAlchemyApiKey(identifier) {
34
+ // Alchemy API keys are different for each alchemy app
35
+ return ensureAndGet(`SKYNET_ALCHEMY_API_${identifier.toUpperCase()}_KEY`);
36
+ }
37
+
33
38
  function ensureAndGet(envName, defaultValue) {
34
39
  if (Array.isArray(envName)) {
35
40
  for (let name of envName) {
@@ -75,4 +80,5 @@ module.exports = {
75
80
  getBscScanApiKey,
76
81
  getPolygonScanApiKey,
77
82
  getGetBlockApiKey,
83
+ getAlchemyApiKey,
78
84
  };
package/examples/consumer CHANGED
@@ -8,7 +8,7 @@
8
8
  // $ examples/consumer deploy --protocol eth
9
9
  // $ examples/consumer --help
10
10
 
11
- const { consumer, ERROR_LEVEL } = require("../app");
11
+ const { consumer, every, ERROR_LEVEL } = require("../app");
12
12
 
13
13
  async function consume({ protocol, messages, verbose }) {
14
14
  console.log("consume called with", protocol, messages, verbose);
@@ -39,7 +39,7 @@ const app = consumer({
39
39
 
40
40
  check: {
41
41
  func: check,
42
- schedule: "@minutely",
42
+ schedule: every(1).minute,
43
43
  slackChannel: "skynet-notifications-local-dev",
44
44
  },
45
45
  });
package/examples/indexer CHANGED
@@ -8,7 +8,7 @@
8
8
  // $ examples/indexer deploy --protocol eth
9
9
  // $ examples/indexer --help
10
10
 
11
- const { indexer, ERROR_LEVEL } = require("../app");
11
+ const { indexer, every, ERROR_LEVEL } = require("../app");
12
12
 
13
13
  async function build({ protocol, verbose }) {
14
14
  console.log("build called with", protocol, verbose);
@@ -40,14 +40,14 @@ const app = indexer({
40
40
 
41
41
  build: {
42
42
  func: build,
43
- schedule: "@minutely",
43
+ schedule: every(1).minute,
44
44
  cpu: 600,
45
45
  mem: 200,
46
46
  },
47
47
 
48
48
  check: {
49
49
  func: check,
50
- schedule: "@minutely",
50
+ schedule: every(2).minutes,
51
51
  maxRetry: 0,
52
52
  slackChannel: "skynet-notifications-local-dev",
53
53
  },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -9,7 +9,7 @@
9
9
  // $ examples/mode-indexer deploy --protocol eth
10
10
  // $ examples/mode-indexer --help
11
11
 
12
- const { modeIndexer, SENSITIVE_VALUE } = require("../app");
12
+ const { modeIndexer, every, SENSITIVE_VALUE } = require("../app");
13
13
 
14
14
  async function build({ protocol, from, to, verbose }) {
15
15
  console.log("build called with", protocol, from, to, verbose);
@@ -48,7 +48,7 @@ const app = modeIndexer({
48
48
  batchSize: 5,
49
49
  concurrency: 2, // default is 1, no concurrency
50
50
 
51
- schedule: "@minutely",
51
+ schedule: every(1).minute,
52
52
  cpu: 800,
53
53
  mem: 400,
54
54
  },
@@ -58,14 +58,14 @@ const app = modeIndexer({
58
58
  batchSize: 2,
59
59
  concurrency: 2, // default is 1, no concurrency
60
60
 
61
- schedule: "@hourly",
61
+ schedule: every(1).hour,
62
62
  cpu: 600,
63
63
  mem: 200,
64
64
  },
65
65
 
66
66
  check: {
67
67
  func: check,
68
- schedule: "@minutely",
68
+ schedule: every(2).minutes,
69
69
  slackChannel: "skynet-notifications-local-dev",
70
70
  },
71
71
  });
package/examples/producer CHANGED
@@ -8,7 +8,7 @@
8
8
  // $ examples/producer deploy --protocol eth
9
9
  // $ examples/producer --help
10
10
 
11
- const { producer, SENSITIVE_VALUE, ERROR_LEVEL } = require("../app");
11
+ const { producer, every, SENSITIVE_VALUE, ERROR_LEVEL } = require("../app");
12
12
 
13
13
  async function produce({ protocol, from, to, verbose, send }) {
14
14
  console.log("produce called with", protocol, from, to, verbose);
@@ -72,7 +72,7 @@ const app = producer({
72
72
 
73
73
  check: {
74
74
  func: check,
75
- schedule: "@minutely",
75
+ schedule: every(2).minutes,
76
76
  slackChannel: "skynet-notifications-local-dev",
77
77
  },
78
78
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.8.3",
3
+ "version": "0.8.7",
4
4
  "description": "Skynet Shared JS library",
5
5
  "main": "index.js",
6
6
  "author": "CertiK Engineering",
@@ -29,4 +29,4 @@
29
29
  "sinon": "^11.1.2"
30
30
  },
31
31
  "license": "MIT"
32
- }
32
+ }
package/snowflake.js CHANGED
@@ -3,15 +3,11 @@ const { promisify } = require("util");
3
3
  const { ensureAndGet } = require("./env");
4
4
 
5
5
  async function getConnection(options) {
6
- const { account, username, password, database, schema, warehouse } = options;
7
-
8
6
  const connection = snowflake.createConnection({
9
- account: account ?? ensureAndGet("SKYNET_SNOWFLAKE_ACCOUNT"),
10
- username: username ?? ensureAndGet("SKYNET_SNOWFLAKE_USERNAME"),
11
- password: password ?? ensureAndGet("SKYNET_SNOWFLAKE_PASSWORD"),
12
- database,
13
- schema,
14
- warehouse
7
+ account: ensureAndGet("SKYNET_SNOWFLAKE_ACCOUNT"),
8
+ username: ensureAndGet("SKYNET_SNOWFLAKE_USERNAME"),
9
+ password: ensureAndGet("SKYNET_SNOWFLAKE_PASSWORD"),
10
+ ...options,
15
11
  });
16
12
  return await promisify(connection.connect).bind(connection)();
17
13
  }
@@ -36,5 +32,5 @@ async function executeSql(options, sql, binds) {
36
32
 
37
33
  module.exports = {
38
34
  getConnection,
39
- executeSql
40
- }
35
+ executeSql,
36
+ };