@sentio/sdk 2.57.13-rc.8 → 2.58.0-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.
Files changed (48) hide show
  1. package/lib/aptos/codegen/codegen.d.ts.map +1 -1
  2. package/lib/aptos/codegen/codegen.js +13 -6
  3. package/lib/aptos/codegen/codegen.js.map +1 -1
  4. package/lib/core/codegen.d.ts +2 -0
  5. package/lib/core/codegen.d.ts.map +1 -0
  6. package/lib/core/codegen.js +17 -0
  7. package/lib/core/codegen.js.map +1 -0
  8. package/lib/eth/codegen/codegen.d.ts.map +1 -1
  9. package/lib/eth/codegen/codegen.js +2 -1
  10. package/lib/eth/codegen/codegen.js.map +1 -1
  11. package/lib/fuel/codegen/codegen.d.ts.map +1 -1
  12. package/lib/fuel/codegen/codegen.js +6 -5
  13. package/lib/fuel/codegen/codegen.js.map +1 -1
  14. package/lib/solana/codegen/codegen.d.ts.map +1 -1
  15. package/lib/solana/codegen/codegen.js +7 -2
  16. package/lib/solana/codegen/codegen.js.map +1 -1
  17. package/lib/stark/codegen/codegen.d.ts.map +1 -1
  18. package/lib/stark/codegen/codegen.js +2 -1
  19. package/lib/stark/codegen/codegen.js.map +1 -1
  20. package/lib/store/codegen.js +52 -19
  21. package/lib/store/codegen.js.map +1 -1
  22. package/lib/store/store.d.ts +1 -1
  23. package/lib/store/store.d.ts.map +1 -1
  24. package/lib/store/store.js.map +1 -1
  25. package/lib/store/types.d.ts +2 -0
  26. package/lib/store/types.d.ts.map +1 -1
  27. package/lib/store/types.js +9 -1
  28. package/lib/store/types.js.map +1 -1
  29. package/lib/sui/codegen/codegen.d.ts.map +1 -1
  30. package/lib/sui/codegen/codegen.js +10 -3
  31. package/lib/sui/codegen/codegen.js.map +1 -1
  32. package/lib/utils/price.d.ts +4 -3
  33. package/lib/utils/price.d.ts.map +1 -1
  34. package/lib/utils/price.js +25 -20
  35. package/lib/utils/price.js.map +1 -1
  36. package/lib/utils/price.test.js.map +1 -1
  37. package/package.json +4 -4
  38. package/src/aptos/codegen/codegen.ts +16 -14
  39. package/src/core/codegen.ts +27 -0
  40. package/src/eth/codegen/codegen.ts +5 -1
  41. package/src/fuel/codegen/codegen.ts +6 -5
  42. package/src/solana/codegen/codegen.ts +9 -4
  43. package/src/stark/codegen/codegen.ts +2 -1
  44. package/src/store/codegen.ts +55 -19
  45. package/src/store/store.ts +3 -1
  46. package/src/store/types.ts +10 -1
  47. package/src/sui/codegen/codegen.ts +13 -3
  48. package/src/utils/price.ts +26 -20
@@ -2,7 +2,7 @@ import { CoinID } from '@sentio/protos'
2
2
  import { Endpoints, processMetrics } from '@sentio/runtime'
3
3
  import { ChainId } from '@sentio/chain'
4
4
  import { LRUCache } from 'lru-cache'
5
- import { Configuration, PriceApi } from '@sentio/api'
5
+ import { client, PriceService } from '@sentio/api'
6
6
  import path from 'path'
7
7
  import fs from 'fs'
8
8
  import os from 'os'
@@ -16,18 +16,17 @@ function getApiKey() {
16
16
  }
17
17
 
18
18
  export function getPriceClient(basePath = Endpoints.INSTANCE.priceFeedAPI) {
19
- if (!basePath.startsWith('http')) {
19
+ if (basePath && !basePath.startsWith('http')) {
20
20
  basePath = 'http://' + basePath
21
21
  }
22
22
  if (basePath.endsWith('/')) {
23
23
  basePath = basePath.slice(0, -1)
24
24
  }
25
- const config = new Configuration({
26
- basePath,
27
- apiKey: getApiKey()
25
+ client.setConfig({
26
+ baseUrl: basePath || 'https://app.sentio.xyz',
27
+ auth: getApiKey()
28
28
  })
29
- const api = new PriceApi(config)
30
- return api
29
+ return PriceService
31
30
  }
32
31
 
33
32
  const priceMap = new LRUCache<string, Promise<number | undefined>>({
@@ -35,6 +34,7 @@ const priceMap = new LRUCache<string, Promise<number | undefined>>({
35
34
  ttl: 1000 * 60 * 5 // 5 minutes
36
35
  })
37
36
 
37
+ type PriceApi = typeof PriceService
38
38
  let priceClient: PriceApi
39
39
 
40
40
  interface PriceOptions {
@@ -69,20 +69,24 @@ export async function getPriceByTypeOrSymbolInternal(
69
69
 
70
70
  processMetrics.process_pricecall_count.add(1)
71
71
  const response = priceClient.getPrice({
72
- timestamp: date,
73
- coinIdSymbol: coinId.symbol,
74
- coinIdAddressAddress: coinId.address?.address,
75
- coinIdAddressChain: coinId.address?.chain
72
+ query: {
73
+ timestamp: date.toISOString(),
74
+ 'coinId.symbol': coinId.symbol,
75
+ 'coinId.address.address': coinId.address?.address,
76
+ 'coinId.address.chain': coinId.address?.chain
77
+ }
76
78
  })
77
79
  price = response
78
80
  .then((res) => {
79
- if (res.timestamp) {
80
- const responseDateString = dateString(res.timestamp)
81
+ const { data } = res
82
+ if (data?.timestamp) {
83
+ const responseDate = new Date(data.timestamp)
84
+ const responseDateString = dateString(responseDate)
81
85
  if (responseDateString === todayDateString) {
82
86
  priceMap.delete(key)
83
87
  } else {
84
88
  // https://www.javatpoint.com/javascript-date-difference
85
- const diff = Math.abs(res.timestamp.getTime() - date.getTime())
89
+ const diff = Math.abs(responseDate.getTime() - date.getTime())
86
90
  const daysDiff = diff / (1000 * 60 * 60 * 24)
87
91
  const tolerance = options?.toleranceInDays || 2
88
92
  if (daysDiff > tolerance) {
@@ -93,7 +97,7 @@ export async function getPriceByTypeOrSymbolInternal(
93
97
  } else {
94
98
  priceMap.delete(key)
95
99
  }
96
- return res.price
100
+ return data?.price
97
101
  })
98
102
  .catch((e) => {
99
103
  setTimeout(() => {
@@ -162,15 +166,17 @@ export async function getCoinsThatHasPrice(chainId: ChainId) {
162
166
  if (!priceClient) {
163
167
  priceClient = getPriceClient()
164
168
  }
165
- const response = await priceClient.priceListCoins({
166
- chain: chainId,
167
- limit: 1000
169
+ const { data } = await priceClient.priceListCoins({
170
+ query: {
171
+ chain: chainId,
172
+ limit: 1000
173
+ }
168
174
  })
169
175
 
170
- if (!response.coinAddressesInChain) {
176
+ if (!data?.coinAddressesInChain) {
171
177
  return []
172
178
  }
173
- return Object.entries(response.coinAddressesInChain).map(([symbol, coin]) => {
179
+ return Object.entries(data.coinAddressesInChain).map(([symbol, coin]) => {
174
180
  coin.symbol = symbol
175
181
  return coin
176
182
  })