@sentio/sdk 2.57.12 → 2.57.13-rc.10

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 (50) hide show
  1. package/lib/aptos/ext/aptos-dex.d.ts +1 -1
  2. package/lib/aptos/ext/aptos-dex.d.ts.map +1 -1
  3. package/lib/aptos/ext/aptos-dex.js +2 -2
  4. package/lib/aptos/ext/aptos-dex.js.map +1 -1
  5. package/lib/core/template.d.ts +1 -5
  6. package/lib/core/template.d.ts.map +1 -1
  7. package/lib/core/template.js +1 -4
  8. package/lib/core/template.js.map +1 -1
  9. package/lib/eth/base-processor-template.d.ts +1 -1
  10. package/lib/eth/base-processor-template.d.ts.map +1 -1
  11. package/lib/eth/base-processor-template.js +2 -2
  12. package/lib/eth/base-processor-template.js.map +1 -1
  13. package/lib/move/ext/coin.d.ts +1 -1
  14. package/lib/move/ext/coin.d.ts.map +1 -1
  15. package/lib/move/ext/move-dex.d.ts +1 -1
  16. package/lib/move/ext/move-dex.d.ts.map +1 -1
  17. package/lib/move/ext/move-dex.js +11 -11
  18. package/lib/move/ext/move-dex.js.map +1 -1
  19. package/lib/store/codegen.js +52 -19
  20. package/lib/store/codegen.js.map +1 -1
  21. package/lib/store/store.d.ts +4 -3
  22. package/lib/store/store.d.ts.map +1 -1
  23. package/lib/store/store.js +22 -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/sui-object-processor.js +1 -1
  30. package/lib/sui/sui-object-processor.js.map +1 -1
  31. package/lib/testing/memory-database.d.ts.map +1 -1
  32. package/lib/testing/memory-database.js +7 -3
  33. package/lib/testing/memory-database.js.map +1 -1
  34. package/lib/utils/price.d.ts +4 -3
  35. package/lib/utils/price.d.ts.map +1 -1
  36. package/lib/utils/price.js +25 -20
  37. package/lib/utils/price.js.map +1 -1
  38. package/lib/utils/price.test.js.map +1 -1
  39. package/package.json +4 -4
  40. package/src/aptos/ext/aptos-dex.ts +2 -2
  41. package/src/core/template.ts +1 -6
  42. package/src/eth/base-processor-template.ts +2 -2
  43. package/src/move/ext/coin.ts +1 -1
  44. package/src/move/ext/move-dex.ts +11 -11
  45. package/src/store/codegen.ts +55 -19
  46. package/src/store/store.ts +32 -6
  47. package/src/store/types.ts +10 -1
  48. package/src/sui/sui-object-processor.ts +1 -1
  49. package/src/testing/memory-database.ts +8 -3
  50. package/src/utils/price.ts +26 -20
@@ -208,16 +208,17 @@ export class MemoryDatabase {
208
208
  return entities
209
209
  }
210
210
 
211
- let results = []
211
+ let results = entities
212
+ // filter combined with AND
212
213
  for (const f of filters ?? []) {
213
- results = entities.filter((e) => filter(e, f))
214
+ results = results.filter((e) => filter(e, f))
214
215
  }
215
216
  return results
216
217
  }
217
218
  }
218
219
 
219
220
  function filter(entity: RichStruct, filter: DBRequest_DBFilter) {
220
- const value = entity.fields[filter.field]
221
+ const value = getValue(entity, filter.field)
221
222
 
222
223
  switch (filter.op) {
223
224
  case DBRequest_DBOperator.EQ:
@@ -252,6 +253,10 @@ function filter(entity: RichStruct, filter: DBRequest_DBFilter) {
252
253
  }
253
254
  }
254
255
 
256
+ function getValue(entity: RichStruct, field: string) {
257
+ return entity.fields[field]
258
+ }
259
+
255
260
  function equal(field: RichValue, value?: RichValueList): boolean {
256
261
  if (field.stringValue !== undefined) {
257
262
  return field.stringValue === value?.values[0]?.stringValue
@@ -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
  })