@sentio/sdk 2.30.3-rc.1 → 2.31.0-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 (49) hide show
  1. package/lib/aptos/builtin/0x1.js +1 -1
  2. package/lib/aptos/builtin/0x1.js.map +1 -1
  3. package/lib/aptos/builtin/0x3.js +1 -1
  4. package/lib/aptos/builtin/0x3.js.map +1 -1
  5. package/lib/aptos/builtin/0x4.js +1 -1
  6. package/lib/aptos/builtin/0x4.js.map +1 -1
  7. package/lib/core/core-plugin.d.ts.map +1 -1
  8. package/lib/core/core-plugin.js +9 -3
  9. package/lib/core/core-plugin.js.map +1 -1
  10. package/lib/core/event-logger.d.ts +13 -2
  11. package/lib/core/event-logger.d.ts.map +1 -1
  12. package/lib/core/event-logger.js +43 -5
  13. package/lib/core/event-logger.js.map +1 -1
  14. package/lib/core/event-logger.test.d.ts +2 -0
  15. package/lib/core/event-logger.test.d.ts.map +1 -0
  16. package/lib/core/event-logger.test.js.map +1 -0
  17. package/lib/eth/eth.d.ts.map +1 -1
  18. package/lib/eth/eth.js +6 -5
  19. package/lib/eth/eth.js.map +1 -1
  20. package/lib/sui/builtin/0x1.js +1 -1
  21. package/lib/sui/builtin/0x1.js.map +1 -1
  22. package/lib/sui/builtin/0x2.js +1 -1
  23. package/lib/sui/builtin/0x2.js.map +1 -1
  24. package/lib/sui/builtin/0x3.js +1 -1
  25. package/lib/sui/builtin/0x3.js.map +1 -1
  26. package/lib/sui/sui-processor.d.ts.map +1 -1
  27. package/lib/sui/sui-processor.js +4 -0
  28. package/lib/sui/sui-processor.js.map +1 -1
  29. package/lib/utils/index.d.ts +1 -1
  30. package/lib/utils/index.d.ts.map +1 -1
  31. package/lib/utils/index.js +1 -1
  32. package/lib/utils/index.js.map +1 -1
  33. package/lib/utils/price.d.ts +27 -1
  34. package/lib/utils/price.d.ts.map +1 -1
  35. package/lib/utils/price.js +16 -0
  36. package/lib/utils/price.js.map +1 -1
  37. package/package.json +6 -6
  38. package/src/aptos/builtin/0x1.ts +1 -1
  39. package/src/aptos/builtin/0x3.ts +1 -1
  40. package/src/aptos/builtin/0x4.ts +1 -1
  41. package/src/core/core-plugin.ts +10 -3
  42. package/src/core/event-logger.ts +63 -5
  43. package/src/eth/eth.ts +6 -5
  44. package/src/sui/builtin/0x1.ts +1 -1
  45. package/src/sui/builtin/0x2.ts +1 -1
  46. package/src/sui/builtin/0x3.ts +1 -1
  47. package/src/sui/sui-processor.ts +4 -0
  48. package/src/utils/index.ts +1 -1
  49. package/src/utils/price.ts +20 -1
@@ -1,5 +1,13 @@
1
1
  import { BaseContext } from './base-context.js'
2
- import { EventTrackingResult, LogLevel } from '@sentio/protos'
2
+ import {
3
+ CoinID,
4
+ EventLogConfig,
5
+ EventLogConfig_BasicFieldType,
6
+ EventLogConfig_Field,
7
+ EventLogConfig_StructFieldType,
8
+ EventTrackingResult,
9
+ LogLevel
10
+ } from '@sentio/protos'
3
11
  import { normalizeAttribute } from './normalization.js'
4
12
  import { MapStateStorage } from '@sentio/runtime'
5
13
 
@@ -32,15 +40,65 @@ export class EventLoggerBinding {
32
40
  }
33
41
  }
34
42
 
43
+ export type BasicFieldType = EventLogConfig_BasicFieldType
44
+ export const BasicFieldType = EventLogConfig_BasicFieldType
45
+
46
+ export type FieldType = CoinID | BasicFieldType | Fields
47
+
48
+ export type Fields = { [key: string]: FieldType }
49
+
50
+ export interface EventLogOptions {
51
+ fields: Fields
52
+ }
53
+
54
+ export function fieldsToProtos(fields: Fields): EventLogConfig_Field[] {
55
+ const fieldsProto: EventLogConfig_Field[] = []
56
+ for (const [key, value] of Object.entries(fields)) {
57
+ let basicType: BasicFieldType | undefined
58
+ let coinType: CoinID | undefined
59
+ let structType: EventLogConfig_StructFieldType | undefined
60
+
61
+ if (typeof value === 'number') {
62
+ basicType = value
63
+ } else {
64
+ if (value.address || value.symbol) {
65
+ coinType = value
66
+ } else {
67
+ structType = EventLogConfig_StructFieldType.create({
68
+ fields: fieldsToProtos(value as Fields)
69
+ })
70
+ }
71
+ }
72
+ fieldsProto.push({
73
+ name: key,
74
+ basicType,
75
+ coinType,
76
+ structType
77
+ })
78
+ }
79
+ return fieldsProto
80
+ }
81
+
35
82
  export class EventLogger {
36
83
  private readonly eventName: string
84
+ config: EventLogConfig
37
85
 
38
- private constructor(eventName: string) {
86
+ private constructor(eventName: string, config: EventLogConfig) {
39
87
  this.eventName = eventName
88
+ this.config = config
40
89
  }
41
90
 
42
- static register(eventName: string): EventLogger {
43
- const logger = new EventLogger(eventName)
91
+ static register(eventName: string, options?: EventLogOptions): EventLogger {
92
+ let config = EventLogConfig.create()
93
+
94
+ if (options?.fields) {
95
+ config = EventLogConfig.create({
96
+ name: eventName,
97
+ fields: fieldsToProtos(options.fields)
98
+ })
99
+ }
100
+
101
+ const logger = new EventLogger(eventName, config)
44
102
  return EventLoggerState.INSTANCE.getOrSetValue(eventName, logger)
45
103
  }
46
104
 
@@ -59,7 +117,7 @@ function emit<T>(ctx: BaseContext, eventName: string, event: Event<T>) {
59
117
  distinctEntityId: distinctId || '',
60
118
  attributes: normalizeAttribute(payload),
61
119
  runtimeInfo: undefined,
62
- noMetric: true,
120
+ noMetric: true
63
121
  }
64
122
  ctx.update({ events: [res] })
65
123
  }
package/src/eth/eth.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  formatHash,
10
10
  formatReceiptLog,
11
11
  object,
12
- formatData,
12
+ formatData
13
13
  } from 'ethers/providers'
14
14
  import { CallExceptionError, LogDescription, Result, DeferredTopicFilter, BlockParams } from 'ethers'
15
15
  import { ContractContext } from './context.js'
@@ -109,13 +109,14 @@ const _formatTransactionReceipt = object(
109
109
  //confirmations: allowNull(getNumber, null),
110
110
  cumulativeGasUsed: getBigInt,
111
111
  effectiveGasPrice: allowNull(getBigInt),
112
+ gasPrice: allowNull(getBigInt),
112
113
  status: allowNull(getNumber),
113
- type: allowNull(getNumber, 0),
114
+ type: allowNull(getNumber, 0)
114
115
  },
115
116
  {
116
- effectiveGasPrice: ['gasPrice'],
117
+ // effectiveGasPrice: ['gasPrice'],
117
118
  hash: ['transactionHash'],
118
- index: ['transactionIndex'],
119
+ index: ['transactionIndex']
119
120
  }
120
121
  )
121
122
 
@@ -143,7 +144,7 @@ export function formatEthData(data: {
143
144
  block,
144
145
  trace,
145
146
  transaction,
146
- transactionReceipt,
147
+ transactionReceipt
147
148
  }
148
149
  }
149
150
 
@@ -251,7 +251,7 @@ const MODULES = JSON.parse(
251
251
 
252
252
  export function loadAllTypes(coder: MoveCoder) {
253
253
  for (const m of Object.values(MODULES)) {
254
- coder.load(m as any);
254
+ coder.load(m as any, "0x1");
255
255
  }
256
256
  }
257
257
 
@@ -2398,7 +2398,7 @@ const MODULES = JSON.parse(
2398
2398
  export function loadAllTypes(coder: MoveCoder) {
2399
2399
  _0x1.loadAllTypes(coder);
2400
2400
  for (const m of Object.values(MODULES)) {
2401
- coder.load(m as any);
2401
+ coder.load(m as any, "0x2");
2402
2402
  }
2403
2403
  }
2404
2404
 
@@ -1882,7 +1882,7 @@ export function loadAllTypes(coder: MoveCoder) {
1882
1882
  _0x1.loadAllTypes(coder);
1883
1883
  _0x2.loadAllTypes(coder);
1884
1884
  for (const m of Object.values(MODULES)) {
1885
- coder.load(m as any);
1885
+ coder.load(m as any, "0x3");
1886
1886
  }
1887
1887
  }
1888
1888
 
@@ -117,6 +117,10 @@ export class SuiBaseProcessor {
117
117
  processor.config.baseLabels
118
118
  )
119
119
 
120
+ // const parts = typeQname.split(SPLITTER)
121
+ // if (evt.packageId && parts[0] != evt.packageId) {
122
+ // evt.type = evt.type.replace(parts[0], evt.packageId)
123
+ // }
120
124
  const decoded = await processor.coder.decodeEvent<any>(evt)
121
125
  await handler(decoded || evt, ctx)
122
126
  processResults.push(ctx.stopAndGetResult())
@@ -1,5 +1,5 @@
1
1
  export * from './conversion.js'
2
2
  export * as token from './token.js'
3
3
  export * from './dex-price.js'
4
- export { getPriceByType, getPriceClient, getPriceBySymbol } from './price.js'
4
+ export { getPriceByType, getPriceClient, getPriceBySymbol, getCoinsThatHasPrice } from './price.js'
5
5
  export * from './call.js'
@@ -1,4 +1,5 @@
1
- import { CoinID, PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/price'
1
+ import { PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/price'
2
+ import { CoinID } from '@sentio/protos'
2
3
  import { createChannel, createClientFactory, Status } from 'nice-grpc'
3
4
  import { prometheusClientMiddleware } from 'nice-grpc-prometheus'
4
5
  import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'
@@ -142,3 +143,21 @@ export async function getPriceBySymbol(
142
143
  function dateString(date: Date) {
143
144
  return [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')
144
145
  }
146
+
147
+ /**
148
+ * get coins that has price, return results are list of coin id with both symbol and address field set
149
+ * @param chainId
150
+ */
151
+ export async function getCoinsThatHasPrice(chainId: ChainId) {
152
+ if (!priceClient) {
153
+ priceClient = getPriceClient()
154
+ }
155
+ const response = await priceClient.listCoins({
156
+ chain: chainId
157
+ })
158
+
159
+ return Object.entries(response.coinAddressesInChain).map(([symbol, coin]) => {
160
+ coin.symbol = symbol
161
+ return coin
162
+ })
163
+ }