@sentio/sdk 1.40.3-rc.2 → 1.40.4-rc.1
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.d.ts +7 -2
- package/lib/utils/price.js +2 -2
- package/lib/utils/price.js.map +1 -1
- package/package.json +4 -4
- package/src/utils/price.ts +2 -2
package/lib/utils/price.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CoinID } from '@sentio/protos/lib/service/price/protos/price';
|
|
2
1
|
import { RetryOptions } from 'nice-grpc-client-middleware-retry';
|
|
3
2
|
export declare function getPriceClient(address?: string): import("nice-grpc").RawClient<import("nice-grpc/lib/service-definitions/ts-proto").FromTsProtoServiceDefinition<{
|
|
4
3
|
readonly name: "PriceService";
|
|
@@ -38,7 +37,13 @@ export declare function getPriceClient(address?: string): import("nice-grpc").Ra
|
|
|
38
37
|
};
|
|
39
38
|
};
|
|
40
39
|
}>, RetryOptions>;
|
|
41
|
-
|
|
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>;
|
|
42
47
|
/**
|
|
43
48
|
*
|
|
44
49
|
* @param symbol token symbol like BTC, etc
|
package/lib/utils/price.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPriceBySymbol = exports.
|
|
3
|
+
exports.getPriceBySymbol = exports.getPriceByType = 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");
|
|
@@ -54,7 +54,6 @@ async function getPriceByTypeOrSymbol(date, coinId) {
|
|
|
54
54
|
priceMap.set(key, price);
|
|
55
55
|
return price;
|
|
56
56
|
}
|
|
57
|
-
exports.getPriceByTypeOrSymbol = getPriceByTypeOrSymbol;
|
|
58
57
|
/**
|
|
59
58
|
*
|
|
60
59
|
* @param chainId chain id refers to CHAIN_MAP
|
|
@@ -69,6 +68,7 @@ async function getPriceByType(chainId, coinType, date) {
|
|
|
69
68
|
},
|
|
70
69
|
});
|
|
71
70
|
}
|
|
71
|
+
exports.getPriceByType = getPriceByType;
|
|
72
72
|
/**
|
|
73
73
|
*
|
|
74
74
|
* @param symbol token symbol like BTC, etc
|
package/lib/utils/price.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,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AC,SAAS,CAAC,CAAA;YACpD,IAAI,kBAAkB,KAAK,OAAO,IAAI,kBAAkB,KAAK,eAAe,EAAE;gBAC5E,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;aACrB;SACF;aAAM;YACL,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;SACrB;QACD,OAAO,GAAG,CAAC,KAAK,CAAA;IAClB,CAAC,CAAC,CAAA;IACF,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACxB,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAAC,OAAe,EAAE,QAAgB,EAAE,IAAU;IAChF,OAAO,sBAAsB,CAAC,IAAI,EAAE;QAClC,OAAO,EAAE;YACP,KAAK,EAAE,OAAO;YACd,OAAO,EAAE,QAAQ;SAClB;KACF,CAAC,CAAA;AACJ,CAAC;AAPD,wCAOC;AAED;;;;GAIG;AACI,KAAK,UAAU,gBAAgB,CAAC,MAAc,EAAE,IAAU;IAC/D,OAAO,sBAAsB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;AACjD,CAAC;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\nasync 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 */\nexport async 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.
|
|
4
|
+
"version": "1.40.4-rc.1",
|
|
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.
|
|
22
|
-
"@sentio/runtime": "^1.40.
|
|
21
|
+
"@sentio/protos": "^1.40.4-rc.1",
|
|
22
|
+
"@sentio/runtime": "^1.40.4-rc.1",
|
|
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": "
|
|
54
|
+
"gitHead": "93804001f117bac7ad9ab921f4f123cb2c1cfe79"
|
|
55
55
|
}
|
package/src/utils/price.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function getPriceClient(address?: string) {
|
|
|
15
15
|
const priceMap = new Map<string, Promise<number>>()
|
|
16
16
|
let priceClient: PriceServiceClient<RetryOptions>
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
async function getPriceByTypeOrSymbol(date: Date, coinId: CoinID): Promise<number> {
|
|
19
19
|
if (!priceClient) {
|
|
20
20
|
priceClient = getPriceClient()
|
|
21
21
|
}
|
|
@@ -65,7 +65,7 @@ export async function getPriceByTypeOrSymbol(date: Date, coinId: CoinID): Promis
|
|
|
65
65
|
* @param coinType
|
|
66
66
|
* @param date
|
|
67
67
|
*/
|
|
68
|
-
async function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number> {
|
|
68
|
+
export async function getPriceByType(chainId: string, coinType: string, date: Date): Promise<number> {
|
|
69
69
|
return getPriceByTypeOrSymbol(date, {
|
|
70
70
|
address: {
|
|
71
71
|
chain: chainId,
|