@sentio/sdk 4.1.0-rc.1 → 4.1.0-rc.3

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.
Files changed (41) hide show
  1. package/dist/core/base-context.d.ts.map +1 -1
  2. package/dist/core/base-context.js +0 -3
  3. package/dist/core/base-context.js.map +1 -1
  4. package/dist/core/event-logger.d.ts.map +1 -1
  5. package/dist/core/event-logger.js +3 -16
  6. package/dist/core/event-logger.js.map +1 -1
  7. package/dist/core/meter.d.ts.map +1 -1
  8. package/dist/core/meter.js +1 -18
  9. package/dist/core/meter.js.map +1 -1
  10. package/dist/core/normalization.d.ts +0 -3
  11. package/dist/core/normalization.d.ts.map +1 -1
  12. package/dist/core/normalization.js +0 -61
  13. package/dist/core/normalization.js.map +1 -1
  14. package/dist/solana/builtin/types.d.ts +20 -20
  15. package/dist/testing/index.d.ts +1 -1
  16. package/dist/testing/index.d.ts.map +1 -1
  17. package/dist/testing/index.js +1 -1
  18. package/dist/testing/index.js.map +1 -1
  19. package/dist/testing/metric-utils.d.ts +6 -1
  20. package/dist/testing/metric-utils.d.ts.map +1 -1
  21. package/dist/testing/metric-utils.js +111 -11
  22. package/dist/testing/metric-utils.js.map +1 -1
  23. package/dist/testing/test-processor-server.d.ts +0 -309
  24. package/dist/testing/test-processor-server.d.ts.map +1 -1
  25. package/dist/testing/test-processor-server.js +8 -0
  26. package/dist/testing/test-processor-server.js.map +1 -1
  27. package/dist/{tsdown.config.ts → tsdown.config.js} +8 -1
  28. package/dist/utils/price.d.ts +9 -5
  29. package/dist/utils/price.d.ts.map +1 -1
  30. package/dist/utils/price.js +20 -27
  31. package/dist/utils/price.js.map +1 -1
  32. package/package.json +6 -6
  33. package/src/core/base-context.ts +0 -3
  34. package/src/core/event-logger.ts +2 -18
  35. package/src/core/meter.ts +1 -18
  36. package/src/core/normalization.ts +0 -65
  37. package/src/testing/index.ts +10 -1
  38. package/src/testing/metric-utils.ts +126 -12
  39. package/src/testing/test-processor-server.ts +8 -0
  40. package/src/{tsdown.config.ts → tsdown.config.js} +8 -1
  41. package/src/utils/price.ts +22 -29
@@ -1,9 +1,11 @@
1
1
  import { type CoinID, CoinIDSchema } from '@sentio/protos'
2
2
  import { create } from '@bufbuild/protobuf'
3
+ import { timestampDate, timestampFromDate } from '@bufbuild/protobuf/wkt'
3
4
  import { Endpoints, processMetrics } from '@sentio/runtime'
4
5
  import { ChainId } from '@sentio/chain'
5
6
  import { LRUCache } from 'lru-cache'
6
- import { client, PriceService } from '@sentio/api'
7
+ import { type Client, createSentioClient, PriceService } from '@sentio/api'
8
+ import { Code, ConnectError } from '@connectrpc/connect'
7
9
  import path from 'path'
8
10
  import fs from 'fs'
9
11
  import os from 'os'
@@ -16,18 +18,17 @@ function getApiKey() {
16
18
  } catch (e) {}
17
19
  }
18
20
 
19
- export function getPriceClient(basePath = Endpoints.INSTANCE.priceFeedAPI) {
21
+ export function getPriceClient(basePath = Endpoints.INSTANCE.priceFeedAPI): PriceApi {
20
22
  if (basePath && !basePath.startsWith('http')) {
21
23
  basePath = 'http://' + basePath
22
24
  }
23
25
  if (basePath.endsWith('/')) {
24
26
  basePath = basePath.slice(0, -1)
25
27
  }
26
- client.setConfig({
28
+ return createSentioClient(PriceService, {
27
29
  baseUrl: basePath || 'https://api.sentio.xyz',
28
- auth: getApiKey()
30
+ apiKey: getApiKey()
29
31
  })
30
- return PriceService
31
32
  }
32
33
 
33
34
  const priceMap = new LRUCache<string, Promise<number | undefined>>({
@@ -35,7 +36,7 @@ const priceMap = new LRUCache<string, Promise<number | undefined>>({
35
36
  ttl: 1000 * 60 * 5 // 5 minutes
36
37
  })
37
38
 
38
- type PriceApi = typeof PriceService
39
+ type PriceApi = Client<typeof PriceService>
39
40
  let priceClient: PriceApi
40
41
 
41
42
  interface PriceOptions {
@@ -73,18 +74,17 @@ export async function getPriceByTypeOrSymbolInternal(
73
74
 
74
75
  processMetrics.process_pricecall_count.add(1)
75
76
  const response = priceClient.getPrice({
76
- query: {
77
- timestamp: date.toISOString(),
78
- 'coinId.symbol': symbol,
79
- 'coinId.address.address': address?.address,
80
- 'coinId.address.chain': address?.chain
77
+ timestamp: timestampFromDate(date),
78
+ coinId: {
79
+ id: symbol
80
+ ? { case: 'symbol', value: symbol }
81
+ : { case: 'address', value: { address: address?.address ?? '', chain: address?.chain ?? '' } }
81
82
  }
82
83
  })
83
84
  price = response
84
85
  .then((res) => {
85
- const { data } = res
86
- if (data?.timestamp) {
87
- const responseDate = new Date(data.timestamp)
86
+ if (res.timestamp) {
87
+ const responseDate = timestampDate(res.timestamp)
88
88
  const responseDateString = dateString(responseDate)
89
89
  if (responseDateString === todayDateString) {
90
90
  priceMap.delete(key)
@@ -101,14 +101,14 @@ export async function getPriceByTypeOrSymbolInternal(
101
101
  } else {
102
102
  priceMap.delete(key)
103
103
  }
104
- return data?.price
104
+ return res.price
105
105
  })
106
106
  .catch((e) => {
107
107
  setTimeout(() => {
108
108
  priceMap.delete(key)
109
109
  }, 1000)
110
110
 
111
- if (e.response?.status === 404) {
111
+ if (e instanceof ConnectError && e.code === Code.NotFound) {
112
112
  console.error('price not found for ', JSON.stringify(coinId), ' at ', dateStr)
113
113
  return undefined
114
114
  }
@@ -166,25 +166,18 @@ function dateString(date: Date) {
166
166
  }
167
167
 
168
168
  /**
169
- * get coins that has price, return results are list of coin id with both symbol and address field set
169
+ * get coins that has price, return results as a list of `{ symbol, coin }`
170
+ * pairs where `coin` is the address-keyed CoinID for that symbol on the chain
170
171
  * @param chainId
171
172
  */
172
173
  export async function getCoinsThatHasPrice(chainId: ChainId) {
173
174
  if (!priceClient) {
174
175
  priceClient = getPriceClient()
175
176
  }
176
- const { data } = await priceClient.priceListCoins({
177
- query: {
178
- chain: chainId,
179
- limit: 1000
180
- }
177
+ const res = await priceClient.listCoins({
178
+ chain: chainId,
179
+ limit: 1000
181
180
  })
182
181
 
183
- if (!data?.coinAddressesInChain) {
184
- return []
185
- }
186
- return Object.entries(data.coinAddressesInChain).map(([symbol, coin]) => {
187
- coin.symbol = symbol
188
- return coin
189
- })
182
+ return Object.entries(res.coinAddressesInChain).map(([symbol, coin]) => ({ symbol, coin }))
190
183
  }