@sentio/sdk 1.40.3-rc.1 → 1.40.3-rc.2

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.
@@ -1,3 +1,4 @@
1
+ import { CoinID } from '@sentio/protos/lib/service/price/protos/price';
1
2
  import { RetryOptions } from 'nice-grpc-client-middleware-retry';
2
3
  export declare function getPriceClient(address?: string): import("nice-grpc").RawClient<import("nice-grpc/lib/service-definitions/ts-proto").FromTsProtoServiceDefinition<{
3
4
  readonly name: "PriceService";
@@ -37,13 +38,7 @@ export declare function getPriceClient(address?: string): import("nice-grpc").Ra
37
38
  };
38
39
  };
39
40
  }>, RetryOptions>;
40
- /**
41
- *
42
- * @param chainId chain id refers to CHAIN_MAP
43
- * @param coinType
44
- * @param date
45
- */
46
- export declare function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number>;
41
+ export declare function getPriceByTypeOrSymbol(date: Date, coinId: CoinID): Promise<number>;
47
42
  /**
48
43
  *
49
44
  * @param symbol token symbol like BTC, etc
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPriceBySymbol = exports.getPriceByType = exports.getPriceClient = void 0;
3
+ exports.getPriceBySymbol = exports.getPriceByTypeOrSymbol = exports.getPriceClient = void 0;
4
4
  const price_1 = require("@sentio/protos/lib/service/price/protos/price");
5
5
  const nice_grpc_1 = require("nice-grpc");
6
6
  const nice_grpc_client_middleware_retry_1 = require("nice-grpc-client-middleware-retry");
@@ -15,70 +15,67 @@ function getPriceClient(address) {
15
15
  exports.getPriceClient = getPriceClient;
16
16
  const priceMap = new Map();
17
17
  let priceClient;
18
- /**
19
- *
20
- * @param chainId chain id refers to CHAIN_MAP
21
- * @param coinType
22
- * @param date
23
- */
24
- async function getPriceByType(chainId, coinType, date) {
18
+ async function getPriceByTypeOrSymbol(date, coinId) {
25
19
  if (!priceClient) {
26
20
  priceClient = getPriceClient();
27
21
  }
28
22
  const dateStr = dateString(date);
29
- const key = `${coinType}-${dateStr}`;
23
+ const todayDateString = dateString(new Date());
24
+ let key;
25
+ if (coinId.symbol) {
26
+ key = `${coinId.symbol}-${dateStr}`;
27
+ }
28
+ else {
29
+ key = `${coinId.address?.address}-${coinId.address?.chain}-${dateStr}`;
30
+ }
30
31
  let price = priceMap.get(key);
31
32
  if (price) {
32
33
  return price;
33
34
  }
34
- const response = await priceClient.getPrice({
35
+ const response = priceClient.getPrice({
35
36
  timestamp: date,
36
- coinId: {
37
- address: {
38
- chain: chainId,
39
- address: coinType,
40
- },
41
- },
37
+ coinId,
42
38
  }, {
43
39
  retry: true,
44
40
  retryMaxAttempts: 8,
45
41
  });
46
- price = response.price;
47
- if (response.timestamp && dateString(response.timestamp) === dateStr) {
48
- priceMap.set(key, price);
49
- }
42
+ price = response.then((res) => {
43
+ if (res.timestamp) {
44
+ const responseDateString = dateString(res.timestamp);
45
+ if (responseDateString !== dateStr || responseDateString !== todayDateString) {
46
+ priceMap.delete(key);
47
+ }
48
+ }
49
+ else {
50
+ priceMap.delete(key);
51
+ }
52
+ return res.price;
53
+ });
54
+ priceMap.set(key, price);
50
55
  return price;
51
56
  }
52
- exports.getPriceByType = getPriceByType;
57
+ exports.getPriceByTypeOrSymbol = getPriceByTypeOrSymbol;
53
58
  /**
54
59
  *
55
- * @param symbol token symbol like BTC, etc
60
+ * @param chainId chain id refers to CHAIN_MAP
61
+ * @param coinType
56
62
  * @param date
57
63
  */
58
- async function getPriceBySymbol(symbol, date) {
59
- if (!priceClient) {
60
- priceClient = getPriceClient();
61
- }
62
- const dateStr = dateString(date);
63
- const key = `${symbol}-${dateStr}`;
64
- let price = priceMap.get(key);
65
- if (price) {
66
- return price;
67
- }
68
- const response = await priceClient.getPrice({
69
- timestamp: date,
70
- coinId: {
71
- symbol,
64
+ async function getPriceByType(chainId, coinType, date) {
65
+ return getPriceByTypeOrSymbol(date, {
66
+ address: {
67
+ chain: chainId,
68
+ address: coinType,
72
69
  },
73
- }, {
74
- retry: true,
75
- retryMaxAttempts: 8,
76
70
  });
77
- price = response.price;
78
- if (response.timestamp && dateString(response.timestamp) === dateStr) {
79
- priceMap.set(key, price);
80
- }
81
- return price;
71
+ }
72
+ /**
73
+ *
74
+ * @param symbol token symbol like BTC, etc
75
+ * @param date
76
+ */
77
+ async function getPriceBySymbol(symbol, date) {
78
+ return getPriceByTypeOrSymbol(date, { symbol });
82
79
  }
83
80
  exports.getPriceBySymbol = getPriceBySymbol;
84
81
  function dateString(date) {
@@ -1 +1 @@
1
- {"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":";;;AAAA,yEAA0G;AAC1G,yCAA8D;AAC9D,yFAAiF;AACjF,6CAA2C;AAE3C,SAAgB,cAAc,CAAC,OAAgB;IAC7C,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,GAAG,mBAAS,CAAC,QAAQ,CAAC,YAAY,CAAA;KAC1C;IACD,MAAM,OAAO,GAAG,IAAA,yBAAa,EAAC,OAAO,CAAC,CAAA;IAEtC,OAAO,IAAA,+BAAmB,GAAE,CAAC,GAAG,CAAC,mDAAe,CAAC,CAAC,MAAM,CAAC,8BAAsB,EAAE,OAAO,CAAC,CAAA;AAC3F,CAAC;AAPD,wCAOC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;AAC1C,IAAI,WAA6C,CAAA;AAEjD;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAAC,OAAe,EAAE,QAAgB,EAAE,IAAU;IAChF,IAAI,CAAC,WAAW,EAAE;QAChB,WAAW,GAAG,cAAc,EAAE,CAAA;KAC/B;IAED,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAChC,MAAM,GAAG,GAAG,GAAG,QAAQ,IAAI,OAAO,EAAE,CAAA;IACpC,IAAI,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,KAAK,EAAE;QACT,OA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AG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;KACzB;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AA7BD,4CA6BC;AAED,SAAS,UAAU,CAAC,IAAU;IAC5B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACrF,CAAC","sourcesContent":["import { PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/lib/service/price/protos/price'\nimport { createChannel, createClientFactory } from 'nice-grpc'\nimport { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'\nimport { Endpoints } from '@sentio/runtime'\n\nexport function getPriceClient(address?: string) {\n if (!address) {\n address = Endpoints.INSTANCE.priceFeedAPI\n }\n const channel = createChannel(address)\n\n return createClientFactory().use(retryMiddleware).create(PriceServiceDefinition, channel)\n}\n\nconst priceMap = new Map<string, number>()\nlet priceClient: PriceServiceClient<RetryOptions>\n\n/**\n *\n * @param chainId chain id refers to CHAIN_MAP\n * @param coinType\n * @param date\n */\nexport async function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number> {\n if (!priceClient) {\n priceClient = getPriceClient()\n }\n\n const dateStr = dateString(date)\n const key = `${coinType}-${dateStr}`\n let price = priceMap.get(key)\n if (price) {\n return price\n }\n\n const response = await priceClient.getPrice(\n {\n timestamp: date,\n coinId: {\n address: {\n chain: chainId,\n address: coinType,\n },\n },\n },\n {\n retry: true,\n retryMaxAttempts: 8,\n }\n )\n price = response.price\n if (response.timestamp && dateString(response.timestamp) === dateStr) {\n priceMap.set(key, price)\n }\n return price\n}\n\n/**\n *\n * @param symbol token symbol like BTC, etc\n * @param date\n */\nexport async function getPriceBySymbol(symbol: string, date: Date): Promise<number> {\n if (!priceClient) {\n priceClient = getPriceClient()\n }\n\n const dateStr = dateString(date)\n const key = `${symbol}-${dateStr}`\n let price = priceMap.get(key)\n if (price) {\n return price\n }\n\n const response = await priceClient.getPrice(\n {\n timestamp: date,\n coinId: {\n symbol,\n },\n },\n {\n retry: true,\n retryMaxAttempts: 8,\n }\n )\n price = response.price\n if (response.timestamp && dateString(response.timestamp) === dateStr) {\n priceMap.set(key, price)\n }\n return price\n}\n\nfunction dateString(date: Date) {\n return [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')\n}\n"]}
1
+ {"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":";;;AAAA,yEAAkH;AAClH,yCAA8D;AAC9D,yFAAiF;AACjF,6CAA2C;AAE3C,SAAgB,cAAc,CAAC,OAAgB;IAC7C,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,GAAG,mBAAS,CAAC,QAAQ,CAAC,YAAY,CAAA;KAC1C;IACD,MAAM,OAAO,GAAG,IAAA,yBAAa,EAAC,OAAO,CAAC,CAAA;IAEtC,OAAO,IAAA,+BAAmB,GAAE,CAAC,GAAG,CAAC,mDAAe,CAAC,CAAC,MAAM,CAAC,8BAAsB,EAAE,OAAO,CAAC,CAAA;AAC3F,CAAC;AAPD,wCAOC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA2B,CAAA;AACnD,IAAI,WAA6C,CAAA;AAE1C,KAAK,UAAU,sBAAsB,CAAC,IAAU,EAAE,MAAc;IACrE,IAAI,CAAC,WAAW,EAAE;QAChB,WAAW,GAAG,cAAc,EAAE,CAAA;KAC/B;IAED,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAChC,MAAM,eAAe,GAAG,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;IAE9C,IAAI,GAAW,CAAA;IACf,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,GAAG,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,EAAE,CAAA;KACpC;SAAM;QACL,GAAG,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,OAA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C;AAFD,4CAEC;AAED,SAAS,UAAU,CAAC,IAAU;IAC5B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACrF,CAAC","sourcesContent":["import { CoinID, PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/lib/service/price/protos/price'\nimport { createChannel, createClientFactory } from 'nice-grpc'\nimport { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'\nimport { Endpoints } from '@sentio/runtime'\n\nexport function getPriceClient(address?: string) {\n if (!address) {\n address = Endpoints.INSTANCE.priceFeedAPI\n }\n const channel = createChannel(address)\n\n return createClientFactory().use(retryMiddleware).create(PriceServiceDefinition, channel)\n}\n\nconst priceMap = new Map<string, Promise<number>>()\nlet priceClient: PriceServiceClient<RetryOptions>\n\nexport async function getPriceByTypeOrSymbol(date: Date, coinId: CoinID): Promise<number> {\n if (!priceClient) {\n priceClient = getPriceClient()\n }\n\n const dateStr = dateString(date)\n const todayDateString = dateString(new Date())\n\n let key: string\n if (coinId.symbol) {\n key = `${coinId.symbol}-${dateStr}`\n } else {\n key = `${coinId.address?.address}-${coinId.address?.chain}-${dateStr}`\n }\n let price = priceMap.get(key)\n if (price) {\n return price\n }\n\n const response = priceClient.getPrice(\n {\n timestamp: date,\n coinId,\n },\n {\n retry: true,\n retryMaxAttempts: 8,\n }\n )\n price = response.then((res) => {\n if (res.timestamp) {\n const responseDateString = dateString(res.timestamp)\n if (responseDateString !== dateStr || responseDateString !== todayDateString) {\n priceMap.delete(key)\n }\n } else {\n priceMap.delete(key)\n }\n return res.price\n })\n priceMap.set(key, price)\n return price\n}\n\n/**\n *\n * @param chainId chain id refers to CHAIN_MAP\n * @param coinType\n * @param date\n */\nasync function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number> {\n return getPriceByTypeOrSymbol(date, {\n address: {\n chain: chainId,\n address: coinType,\n },\n })\n}\n\n/**\n *\n * @param symbol token symbol like BTC, etc\n * @param date\n */\nexport async function getPriceBySymbol(symbol: string, date: Date): Promise<number> {\n return getPriceByTypeOrSymbol(date, { symbol })\n}\n\nfunction dateString(date: Date) {\n return [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "1.40.3-rc.1",
4
+ "version": "1.40.3-rc.2",
5
5
  "scripts": {
6
6
  "compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
7
7
  "compile": "tsc -p . && cp src/utils/*.csv lib/utils",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@ethersproject/providers": "~5.7.0",
21
- "@sentio/protos": "^1.40.3-rc.1",
22
- "@sentio/runtime": "^1.40.3-rc.1",
21
+ "@sentio/protos": "^1.40.3-rc.2",
22
+ "@sentio/runtime": "^1.40.3-rc.2",
23
23
  "@typechain/ethers-v5": "^10.0.0",
24
24
  "bignumber.js": "^9.1.0",
25
25
  "command-line-args": "^5.2.1",
@@ -51,5 +51,5 @@
51
51
  "typedoc": {
52
52
  "entryPoint": "./src/index.ts"
53
53
  },
54
- "gitHead": "f6ee979f5b6c6c1fac64b3bbaef24ccf4a2570f5"
54
+ "gitHead": "0b4f1ccc0717ddeabddff5cfec3e9a8b4e3c99c3"
55
55
  }
@@ -1,4 +1,4 @@
1
- import { PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/lib/service/price/protos/price'
1
+ import { CoinID, PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/lib/service/price/protos/price'
2
2
  import { createChannel, createClientFactory } from 'nice-grpc'
3
3
  import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'
4
4
  import { Endpoints } from '@sentio/runtime'
@@ -12,83 +12,75 @@ export function getPriceClient(address?: string) {
12
12
  return createClientFactory().use(retryMiddleware).create(PriceServiceDefinition, channel)
13
13
  }
14
14
 
15
- const priceMap = new Map<string, number>()
15
+ const priceMap = new Map<string, Promise<number>>()
16
16
  let priceClient: PriceServiceClient<RetryOptions>
17
17
 
18
- /**
19
- *
20
- * @param chainId chain id refers to CHAIN_MAP
21
- * @param coinType
22
- * @param date
23
- */
24
- export async function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number> {
18
+ export async function getPriceByTypeOrSymbol(date: Date, coinId: CoinID): Promise<number> {
25
19
  if (!priceClient) {
26
20
  priceClient = getPriceClient()
27
21
  }
28
22
 
29
23
  const dateStr = dateString(date)
30
- const key = `${coinType}-${dateStr}`
24
+ const todayDateString = dateString(new Date())
25
+
26
+ let key: string
27
+ if (coinId.symbol) {
28
+ key = `${coinId.symbol}-${dateStr}`
29
+ } else {
30
+ key = `${coinId.address?.address}-${coinId.address?.chain}-${dateStr}`
31
+ }
31
32
  let price = priceMap.get(key)
32
33
  if (price) {
33
34
  return price
34
35
  }
35
36
 
36
- const response = await priceClient.getPrice(
37
+ const response = priceClient.getPrice(
37
38
  {
38
39
  timestamp: date,
39
- coinId: {
40
- address: {
41
- chain: chainId,
42
- address: coinType,
43
- },
44
- },
40
+ coinId,
45
41
  },
46
42
  {
47
43
  retry: true,
48
44
  retryMaxAttempts: 8,
49
45
  }
50
46
  )
51
- price = response.price
52
- if (response.timestamp && dateString(response.timestamp) === dateStr) {
53
- priceMap.set(key, price)
54
- }
47
+ price = response.then((res) => {
48
+ if (res.timestamp) {
49
+ const responseDateString = dateString(res.timestamp)
50
+ if (responseDateString !== dateStr || responseDateString !== todayDateString) {
51
+ priceMap.delete(key)
52
+ }
53
+ } else {
54
+ priceMap.delete(key)
55
+ }
56
+ return res.price
57
+ })
58
+ priceMap.set(key, price)
55
59
  return price
56
60
  }
57
61
 
62
+ /**
63
+ *
64
+ * @param chainId chain id refers to CHAIN_MAP
65
+ * @param coinType
66
+ * @param date
67
+ */
68
+ async function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number> {
69
+ return getPriceByTypeOrSymbol(date, {
70
+ address: {
71
+ chain: chainId,
72
+ address: coinType,
73
+ },
74
+ })
75
+ }
76
+
58
77
  /**
59
78
  *
60
79
  * @param symbol token symbol like BTC, etc
61
80
  * @param date
62
81
  */
63
82
  export async function getPriceBySymbol(symbol: string, date: Date): Promise<number> {
64
- if (!priceClient) {
65
- priceClient = getPriceClient()
66
- }
67
-
68
- const dateStr = dateString(date)
69
- const key = `${symbol}-${dateStr}`
70
- let price = priceMap.get(key)
71
- if (price) {
72
- return price
73
- }
74
-
75
- const response = await priceClient.getPrice(
76
- {
77
- timestamp: date,
78
- coinId: {
79
- symbol,
80
- },
81
- },
82
- {
83
- retry: true,
84
- retryMaxAttempts: 8,
85
- }
86
- )
87
- price = response.price
88
- if (response.timestamp && dateString(response.timestamp) === dateStr) {
89
- priceMap.set(key, price)
90
- }
91
- return price
83
+ return getPriceByTypeOrSymbol(date, { symbol })
92
84
  }
93
85
 
94
86
  function dateString(date: Date) {