@sentio/sdk-bundle 2.44.0 → 2.44.1-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/aptos/builtin/0x1.js +1 -1
- package/lib/aptos/builtin/0x3.js +1 -1
- package/lib/aptos/builtin/index.js +1 -1
- package/lib/aptos/ext/index.js +1 -1
- package/lib/aptos/index.js +1 -1
- package/lib/chunk-F6O7Z5YC.js +6 -0
- package/lib/chunk-F6O7Z5YC.js.map +1 -0
- package/lib/{chunk-QTRTXIKL.js → chunk-FAZ3MF2Y.js} +2 -2
- package/lib/{chunk-TVLODLMF.js → chunk-KJU5FRRJ.js} +2 -2
- package/lib/{chunk-43AULYHS.js → chunk-NCOPZM3S.js} +2 -2
- package/lib/chunk-TTZSFKIM.js +16 -0
- package/lib/chunk-TTZSFKIM.js.map +1 -0
- package/lib/{chunk-HRWNB6TA.js → chunk-UNDTHQXJ.js} +2 -2
- package/lib/{chunk-FOPG6CCD.js → chunk-VQRG4IVB.js} +2 -2
- package/lib/{chunk-GJZNIDSI.js → chunk-Y5C3UST2.js} +2 -2
- package/lib/solana/builtin/types.d.ts +4 -4
- package/lib/sui/builtin/0x1.js +1 -1
- package/lib/sui/builtin/0x2.js +1 -1
- package/lib/sui/builtin/0x3.js +1 -1
- package/lib/sui/builtin/index.js +1 -1
- package/lib/sui/ext/index.js +1 -1
- package/lib/sui/index.js +1 -1
- package/lib/testing/index.js +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/price.d.ts +4 -338
- package/lib/utils/price.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/utils/price.ts +19 -27
- package/lib/chunk-GELZJPWE.js +0 -6
- package/lib/chunk-GELZJPWE.js.map +0 -1
- package/lib/chunk-RFCXI7MC.js +0 -16
- package/lib/chunk-RFCXI7MC.js.map +0 -1
- /package/lib/{chunk-QTRTXIKL.js.map → chunk-FAZ3MF2Y.js.map} +0 -0
- /package/lib/{chunk-TVLODLMF.js.map → chunk-KJU5FRRJ.js.map} +0 -0
- /package/lib/{chunk-43AULYHS.js.map → chunk-NCOPZM3S.js.map} +0 -0
- /package/lib/{chunk-HRWNB6TA.js.map → chunk-UNDTHQXJ.js.map} +0 -0
- /package/lib/{chunk-FOPG6CCD.js.map → chunk-VQRG4IVB.js.map} +0 -0
- /package/lib/{chunk-GJZNIDSI.js.map → chunk-Y5C3UST2.js.map} +0 -0
package/src/utils/price.ts
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import { PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/price'
|
|
2
1
|
import { CoinID } from '@sentio/protos'
|
|
3
|
-
import {
|
|
4
|
-
import { prometheusClientMiddleware } from 'nice-grpc-prometheus'
|
|
5
|
-
import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'
|
|
6
|
-
import { Endpoints } from '@sentio/runtime'
|
|
2
|
+
import { Status } from 'nice-grpc'
|
|
7
3
|
import { ChainId } from '@sentio/chain'
|
|
8
4
|
import { LRUCache } from 'lru-cache'
|
|
5
|
+
import { Configuration, PriceApi } from '@sentio/api'
|
|
9
6
|
|
|
10
7
|
export function getPriceClient(address?: string) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
return createClientFactory()
|
|
17
|
-
.use(prometheusClientMiddleware())
|
|
18
|
-
.use(retryMiddleware)
|
|
19
|
-
.create(PriceServiceDefinition, channel)
|
|
8
|
+
const config = new Configuration({
|
|
9
|
+
apiKey: process.env.SENTIO_API_KEY
|
|
10
|
+
})
|
|
11
|
+
const api = new PriceApi(config)
|
|
12
|
+
return api
|
|
20
13
|
}
|
|
21
14
|
|
|
22
15
|
const priceMap = new LRUCache<string, Promise<number | undefined>>({
|
|
@@ -24,7 +17,7 @@ const priceMap = new LRUCache<string, Promise<number | undefined>>({
|
|
|
24
17
|
ttl: 1000 * 60 * 60 // 1 hour
|
|
25
18
|
})
|
|
26
19
|
|
|
27
|
-
let priceClient:
|
|
20
|
+
let priceClient: PriceApi
|
|
28
21
|
|
|
29
22
|
interface PriceOptions {
|
|
30
23
|
toleranceInDays?: number
|
|
@@ -37,7 +30,7 @@ async function getPriceByTypeOrSymbol(date: Date, coinId: CoinID, options?: Pric
|
|
|
37
30
|
}
|
|
38
31
|
|
|
39
32
|
export async function getPriceByTypeOrSymbolInternal(
|
|
40
|
-
priceClient:
|
|
33
|
+
priceClient: PriceApi,
|
|
41
34
|
date: Date,
|
|
42
35
|
coinId: CoinID,
|
|
43
36
|
options?: PriceOptions
|
|
@@ -56,16 +49,12 @@ export async function getPriceByTypeOrSymbolInternal(
|
|
|
56
49
|
return price
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
const response = priceClient.getPrice(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
retry: true,
|
|
66
|
-
retryMaxAttempts: 5
|
|
67
|
-
}
|
|
68
|
-
)
|
|
52
|
+
const response = priceClient.getPrice({
|
|
53
|
+
timestamp: date,
|
|
54
|
+
coinIdSymbol: coinId.symbol,
|
|
55
|
+
coinIdAddressAddress: coinId.address?.address,
|
|
56
|
+
coinIdAddressChain: coinId.address?.chain
|
|
57
|
+
})
|
|
69
58
|
price = response
|
|
70
59
|
.then((res) => {
|
|
71
60
|
if (res.timestamp) {
|
|
@@ -154,11 +143,14 @@ export async function getCoinsThatHasPrice(chainId: ChainId) {
|
|
|
154
143
|
if (!priceClient) {
|
|
155
144
|
priceClient = getPriceClient()
|
|
156
145
|
}
|
|
157
|
-
const response = await priceClient.
|
|
146
|
+
const response = await priceClient.priceListCoins({
|
|
158
147
|
chain: chainId,
|
|
159
148
|
limit: 1000
|
|
160
149
|
})
|
|
161
150
|
|
|
151
|
+
if (!response.coinAddressesInChain) {
|
|
152
|
+
return []
|
|
153
|
+
}
|
|
162
154
|
return Object.entries(response.coinAddressesInChain).map(([symbol, coin]) => {
|
|
163
155
|
coin.symbol = symbol
|
|
164
156
|
return coin
|