@sentio/sdk 1.39.0-rc.1 → 1.39.0
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/lib/utils/price.js +5 -1
- package/lib/utils/price.js.map +1 -1
- package/package.json +4 -4
- package/src/utils/price.ts +5 -1
package/lib/utils/price.js
CHANGED
|
@@ -4,13 +4,17 @@ exports.getPriceBySymbol = exports.getPriceByType = exports.getPriceClient = voi
|
|
|
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");
|
|
7
|
+
const nice_grpc_error_details_1 = require("nice-grpc-error-details");
|
|
7
8
|
const runtime_1 = require("@sentio/runtime");
|
|
8
9
|
function getPriceClient(address) {
|
|
9
10
|
if (!address) {
|
|
10
11
|
address = runtime_1.Endpoints.INSTANCE.priceFeedAPI;
|
|
11
12
|
}
|
|
12
13
|
const channel = (0, nice_grpc_1.createChannel)(address);
|
|
13
|
-
return (0, nice_grpc_1.createClientFactory)()
|
|
14
|
+
return (0, nice_grpc_1.createClientFactory)()
|
|
15
|
+
.use(nice_grpc_error_details_1.errorDetailsClientMiddleware)
|
|
16
|
+
.use(nice_grpc_client_middleware_retry_1.retryMiddleware)
|
|
17
|
+
.create(price_1.PriceServiceDefinition, channel);
|
|
14
18
|
}
|
|
15
19
|
exports.getPriceClient = getPriceClient;
|
|
16
20
|
const priceMap = new Map();
|
package/lib/utils/price.js.map
CHANGED
|
@@ -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,Q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AAU;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 { errorDetailsClientMiddleware } from 'nice-grpc-error-details'\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()\n .use(errorDetailsClientMiddleware)\n .use(retryMiddleware)\n .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"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentio/sdk",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.39.0
|
|
4
|
+
"version": "1.39.0",
|
|
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.39.0
|
|
22
|
-
"@sentio/runtime": "^1.39.0
|
|
21
|
+
"@sentio/protos": "^1.39.0",
|
|
22
|
+
"@sentio/runtime": "^1.39.0",
|
|
23
23
|
"@typechain/ethers-v5": "^10.0.0",
|
|
24
24
|
"bignumber.js": "^9.1.0",
|
|
25
25
|
"command-line-args": "^5.2.1",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"typedoc": {
|
|
55
55
|
"entryPoint": "./src/index.ts"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "2f244c113057ec0273c9e25b2dc5003329015fe7"
|
|
58
58
|
}
|
package/src/utils/price.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { 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
|
+
import { errorDetailsClientMiddleware } from 'nice-grpc-error-details'
|
|
4
5
|
import { Endpoints } from '@sentio/runtime'
|
|
5
6
|
|
|
6
7
|
export function getPriceClient(address?: string) {
|
|
@@ -9,7 +10,10 @@ export function getPriceClient(address?: string) {
|
|
|
9
10
|
}
|
|
10
11
|
const channel = createChannel(address)
|
|
11
12
|
|
|
12
|
-
return createClientFactory()
|
|
13
|
+
return createClientFactory()
|
|
14
|
+
.use(errorDetailsClientMiddleware)
|
|
15
|
+
.use(retryMiddleware)
|
|
16
|
+
.create(PriceServiceDefinition, channel)
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
const priceMap = new Map<string, number>()
|