@sentio/sdk 1.29.1 → 1.30.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 (58) hide show
  1. package/lib/aptos/context.d.ts +3 -3
  2. package/lib/aptos/context.js +7 -6
  3. package/lib/aptos/context.js.map +1 -1
  4. package/lib/cli/webpack.config.js +3 -2
  5. package/lib/core/base-context.d.ts +2 -2
  6. package/lib/core/base-context.js.map +1 -1
  7. package/lib/core/context.d.ts +4 -4
  8. package/lib/core/context.js +14 -13
  9. package/lib/core/context.js.map +1 -1
  10. package/lib/core/event-tracker.d.ts +2 -2
  11. package/lib/core/event-tracker.js +4 -5
  12. package/lib/core/event-tracker.js.map +1 -1
  13. package/lib/core/exporter.d.ts +2 -2
  14. package/lib/core/exporter.js +4 -5
  15. package/lib/core/exporter.js.map +1 -1
  16. package/lib/core/index.d.ts +1 -1
  17. package/lib/core/index.js +2 -2
  18. package/lib/core/index.js.map +1 -1
  19. package/lib/core/logger.d.ts +2 -2
  20. package/lib/core/logger.js +3 -4
  21. package/lib/core/logger.js.map +1 -1
  22. package/lib/core/metadata.d.ts +3 -6
  23. package/lib/core/metadata.js +6 -16
  24. package/lib/core/metadata.js.map +1 -1
  25. package/lib/core/meter.d.ts +14 -7
  26. package/lib/core/meter.js +16 -25
  27. package/lib/core/meter.js.map +1 -1
  28. package/lib/gen/chainquery/protos/chainquery.d.ts +48 -1
  29. package/lib/gen/chainquery/protos/chainquery.js +16 -0
  30. package/lib/gen/chainquery/protos/chainquery.js.map +1 -1
  31. package/lib/gen/processor/protos/processor.d.ts +20 -0
  32. package/lib/gen/processor/protos/processor.js +138 -2
  33. package/lib/gen/processor/protos/processor.js.map +1 -1
  34. package/lib/service.js +1 -1
  35. package/lib/service.js.map +1 -1
  36. package/lib/testing/metric-utils.d.ts +1 -2
  37. package/lib/testing/metric-utils.js +2 -2
  38. package/lib/testing/metric-utils.js.map +1 -1
  39. package/lib/utils/price.d.ts +45 -3
  40. package/lib/utils/price.js +47 -27
  41. package/lib/utils/price.js.map +1 -1
  42. package/package.json +3 -1
  43. package/src/aptos/context.ts +6 -6
  44. package/src/cli/webpack.config.js +3 -2
  45. package/src/core/base-context.ts +2 -2
  46. package/src/core/context.ts +13 -13
  47. package/src/core/event-tracker.ts +4 -4
  48. package/src/core/exporter.ts +5 -5
  49. package/src/core/index.ts +1 -1
  50. package/src/core/logger.ts +4 -5
  51. package/src/core/metadata.ts +4 -15
  52. package/src/core/meter.ts +19 -28
  53. package/src/gen/chainquery/protos/chainquery.ts +37 -1
  54. package/src/gen/processor/protos/processor.ts +156 -0
  55. package/src/service.ts +1 -2
  56. package/src/testing/metric-utils.ts +3 -4
  57. package/src/utils/price.ts +54 -25
  58. package/templates/evm/src/processor.ts +1 -1
@@ -1,17 +1,18 @@
1
1
  import { PriceServiceClient, PriceServiceDefinition } from '../gen/service/price/protos/price'
2
- import { createChannel, createClient } from 'nice-grpc'
2
+ import { createChannel, createClientFactory } from 'nice-grpc'
3
+ import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'
3
4
 
4
- export function getPriceClient(address?: string): PriceServiceClient {
5
+ export function getPriceClient(address?: string) {
5
6
  if (!address) {
6
7
  address = global.ENDPOINTS.priceFeedAPI
7
8
  }
8
9
  const channel = createChannel(address)
9
10
 
10
- return createClient(PriceServiceDefinition, channel)
11
+ return createClientFactory().use(retryMiddleware).create(PriceServiceDefinition, channel)
11
12
  }
12
13
 
13
14
  const priceMap = new Map<string, number>()
14
- let priceClient: PriceServiceClient
15
+ let priceClient: PriceServiceClient<RetryOptions>
15
16
 
16
17
  /**
17
18
  *
@@ -26,33 +27,61 @@ export async function getPriceByType(chainId: string, coinType: string, date: Da
26
27
 
27
28
  const dateStr = [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')
28
29
  const key = `${coinType}-${dateStr}`
29
- const price = priceMap.get(key)
30
+ let price = priceMap.get(key)
30
31
  if (price) {
31
32
  return price
32
33
  }
33
34
 
34
- /*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
35
- while (true) {
36
- try {
37
- const response = await priceClient.getPrice({
38
- timestamp: date,
39
- coinId: {
40
- address: {
41
- chain: chainId,
42
- address: coinType,
43
- },
35
+ const response = await priceClient.getPrice(
36
+ {
37
+ timestamp: date,
38
+ coinId: {
39
+ address: {
40
+ chain: chainId,
41
+ address: coinType,
44
42
  },
45
- })
46
- const price = response.price
47
- priceMap.set(key, price)
48
- return price
49
- } catch (e) {
50
- console.log('error getting price', e, dateStr, coinType)
51
- await delay(1000)
43
+ },
44
+ },
45
+ {
46
+ retry: true,
47
+ retryMaxAttempts: 8,
52
48
  }
53
- }
49
+ )
50
+ price = response.price
51
+ priceMap.set(key, price)
52
+ return price
54
53
  }
55
54
 
56
- export function delay(ms: number) {
57
- return new Promise((resolve) => setTimeout(resolve, ms))
55
+ /**
56
+ *
57
+ * @param symbol token symbol like BTC, etc
58
+ * @param date
59
+ */
60
+ export async function getPriceBySymbol(symbol: string, date: Date): Promise<number> {
61
+ if (!priceClient) {
62
+ priceClient = getPriceClient()
63
+ }
64
+
65
+ const dateStr = [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')
66
+ const key = `${symbol}-${dateStr}`
67
+ let price = priceMap.get(key)
68
+ if (price) {
69
+ return price
70
+ }
71
+
72
+ const response = await priceClient.getPrice(
73
+ {
74
+ timestamp: date,
75
+ coinId: {
76
+ symbol,
77
+ },
78
+ },
79
+ {
80
+ retry: true,
81
+ retryMaxAttempts: 8,
82
+ }
83
+ )
84
+ price = response.price
85
+ priceMap.set(key, price)
86
+ return price
58
87
  }
@@ -3,7 +3,7 @@ import { token } from '@sentio/sdk/lib/utils'
3
3
  import { ERC20Processor } from '@sentio/sdk/lib/builtin/erc20'
4
4
  import { X2y2Processor } from './types/x2y2'
5
5
 
6
- const rewardPerBlock = new Gauge('reward_per_block', {
6
+ const rewardPerBlock = Gauge.register('reward_per_block', {
7
7
  description: 'rewards for each block grouped by phase',
8
8
  unit: 'x2y2',
9
9
  })