@sentio/sdk 2.14.4 → 2.15.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 (175) hide show
  1. package/lib/aptos/api.d.ts +1 -2
  2. package/lib/aptos/api.js +2 -2
  3. package/lib/aptos/api.js.map +1 -1
  4. package/lib/aptos/aptos-chain-adapter.d.ts +1 -1
  5. package/lib/aptos/aptos-chain-adapter.js +17 -13
  6. package/lib/aptos/aptos-chain-adapter.js.map +1 -1
  7. package/lib/aptos/aptos-processor.js +3 -3
  8. package/lib/aptos/aptos-processor.js.map +1 -1
  9. package/lib/aptos/context.d.ts +2 -2
  10. package/lib/aptos/context.js +3 -4
  11. package/lib/aptos/context.js.map +1 -1
  12. package/lib/aptos/ext/coin.js +2 -2
  13. package/lib/aptos/ext/coin.js.map +1 -1
  14. package/lib/aptos/network.d.ts +7 -7
  15. package/lib/aptos/network.js +6 -19
  16. package/lib/aptos/network.js.map +1 -1
  17. package/lib/core/base-context.d.ts +2 -1
  18. package/lib/core/base-context.js.map +1 -1
  19. package/lib/core/chain.d.ts +194 -93
  20. package/lib/core/chain.js +112 -96
  21. package/lib/core/chain.js.map +1 -1
  22. package/lib/core/yaml-contract-config.d.ts +2 -1
  23. package/lib/core/yaml-contract-config.js.map +1 -1
  24. package/lib/eth/account-processor.d.ts +3 -2
  25. package/lib/eth/account-processor.js +3 -3
  26. package/lib/eth/account-processor.js.map +1 -1
  27. package/lib/eth/base-processor-template.d.ts +2 -3
  28. package/lib/eth/base-processor-template.js +1 -2
  29. package/lib/eth/base-processor-template.js.map +1 -1
  30. package/lib/eth/base-processor.d.ts +5 -5
  31. package/lib/eth/base-processor.js +5 -5
  32. package/lib/eth/base-processor.js.map +1 -1
  33. package/lib/eth/bind-options.d.ts +3 -3
  34. package/lib/eth/bind-options.js +3 -4
  35. package/lib/eth/bind-options.js.map +1 -1
  36. package/lib/eth/binds.d.ts +3 -3
  37. package/lib/eth/binds.js +1 -3
  38. package/lib/eth/binds.js.map +1 -1
  39. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +2 -4
  40. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +2 -2
  41. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  42. package/lib/eth/builtin/internal/eacaggregatorproxy-test-utils.js +5 -4
  43. package/lib/eth/builtin/internal/eacaggregatorproxy-test-utils.js.map +1 -1
  44. package/lib/eth/builtin/internal/erc1155-processor.d.ts +2 -4
  45. package/lib/eth/builtin/internal/erc1155-processor.js +2 -2
  46. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  47. package/lib/eth/builtin/internal/erc1155-test-utils.js +5 -4
  48. package/lib/eth/builtin/internal/erc1155-test-utils.js.map +1 -1
  49. package/lib/eth/builtin/internal/erc20-processor.d.ts +2 -4
  50. package/lib/eth/builtin/internal/erc20-processor.js +2 -2
  51. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  52. package/lib/eth/builtin/internal/erc20-test-utils.js +4 -3
  53. package/lib/eth/builtin/internal/erc20-test-utils.js.map +1 -1
  54. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +2 -4
  55. package/lib/eth/builtin/internal/erc20bytes-processor.js +2 -2
  56. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  57. package/lib/eth/builtin/internal/erc20bytes-test-utils.js +3 -2
  58. package/lib/eth/builtin/internal/erc20bytes-test-utils.js.map +1 -1
  59. package/lib/eth/builtin/internal/erc721-processor.d.ts +2 -4
  60. package/lib/eth/builtin/internal/erc721-processor.js +2 -2
  61. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  62. package/lib/eth/builtin/internal/erc721-test-utils.js +4 -3
  63. package/lib/eth/builtin/internal/erc721-test-utils.js.map +1 -1
  64. package/lib/eth/builtin/internal/weth9-processor.d.ts +2 -4
  65. package/lib/eth/builtin/internal/weth9-processor.js +2 -2
  66. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  67. package/lib/eth/builtin/internal/weth9-test-utils.js +5 -4
  68. package/lib/eth/builtin/internal/weth9-test-utils.js.map +1 -1
  69. package/lib/eth/codegen/ethers-sentio.js +11 -4
  70. package/lib/eth/codegen/ethers-sentio.js.map +1 -1
  71. package/lib/eth/codegen/file.js +9 -6
  72. package/lib/eth/codegen/file.js.map +1 -1
  73. package/lib/eth/context.d.ts +6 -5
  74. package/lib/eth/context.js +2 -2
  75. package/lib/eth/context.js.map +1 -1
  76. package/lib/eth/eth-plugin.js +7 -9
  77. package/lib/eth/eth-plugin.js.map +1 -1
  78. package/lib/eth/index.d.ts +3 -1
  79. package/lib/eth/index.js +3 -1
  80. package/lib/eth/index.js.map +1 -1
  81. package/lib/eth/provider.d.ts +5 -5
  82. package/lib/eth/provider.js +12 -14
  83. package/lib/eth/provider.js.map +1 -1
  84. package/lib/eth/provider.test.js.map +1 -1
  85. package/lib/move/abstract-codegen.d.ts +1 -1
  86. package/lib/move/abstract-codegen.js +10 -3
  87. package/lib/move/abstract-codegen.js.map +1 -1
  88. package/lib/move/chain-adapter.d.ts +1 -1
  89. package/lib/move/chain-adapter.js.map +1 -1
  90. package/lib/solana/solana-context.d.ts +4 -3
  91. package/lib/solana/solana-context.js +3 -2
  92. package/lib/solana/solana-context.js.map +1 -1
  93. package/lib/solana/solana-options.d.ts +2 -1
  94. package/lib/solana/solana-options.js.map +1 -1
  95. package/lib/solana/solana-processor.d.ts +2 -1
  96. package/lib/solana/solana-processor.js +2 -2
  97. package/lib/solana/solana-processor.js.map +1 -1
  98. package/lib/sui/context.d.ts +2 -2
  99. package/lib/sui/context.js +4 -5
  100. package/lib/sui/context.js.map +1 -1
  101. package/lib/sui/network.d.ts +7 -7
  102. package/lib/sui/network.js +6 -19
  103. package/lib/sui/network.js.map +1 -1
  104. package/lib/sui/sui-chain-adapter.d.ts +1 -1
  105. package/lib/sui/sui-chain-adapter.js +8 -6
  106. package/lib/sui/sui-chain-adapter.js.map +1 -1
  107. package/lib/sui/sui-plugin.js +1 -2
  108. package/lib/sui/sui-plugin.js.map +1 -1
  109. package/lib/sui/sui-processor.js +3 -3
  110. package/lib/sui/sui-processor.js.map +1 -1
  111. package/lib/testing/aptos-facet.js +2 -3
  112. package/lib/testing/aptos-facet.js.map +1 -1
  113. package/lib/testing/eth-facet.d.ts +14 -13
  114. package/lib/testing/eth-facet.js +17 -17
  115. package/lib/testing/eth-facet.js.map +1 -1
  116. package/lib/testing/sui-facet.js +2 -3
  117. package/lib/testing/sui-facet.js.map +1 -1
  118. package/lib/utils/dex-price.d.ts +3 -2
  119. package/lib/utils/dex-price.js +3 -2
  120. package/lib/utils/dex-price.js.map +1 -1
  121. package/lib/utils/erc20.test.js.map +1 -1
  122. package/lib/utils/price.d.ts +2 -1
  123. package/lib/utils/price.js.map +1 -1
  124. package/lib/utils/token.d.ts +3 -4
  125. package/lib/utils/token.js +2 -2
  126. package/lib/utils/token.js.map +1 -1
  127. package/package.json +3 -3
  128. package/src/aptos/api.ts +2 -2
  129. package/src/aptos/aptos-chain-adapter.ts +17 -15
  130. package/src/aptos/aptos-processor.ts +3 -3
  131. package/src/aptos/context.ts +6 -6
  132. package/src/aptos/ext/coin.ts +2 -2
  133. package/src/aptos/network.ts +6 -19
  134. package/src/core/base-context.ts +2 -1
  135. package/src/core/chain.ts +113 -96
  136. package/src/core/yaml-contract-config.ts +3 -1
  137. package/src/eth/account-processor.ts +7 -7
  138. package/src/eth/base-processor-template.ts +3 -5
  139. package/src/eth/base-processor.ts +9 -10
  140. package/src/eth/bind-options.ts +4 -6
  141. package/src/eth/binds.ts +5 -7
  142. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +5 -5
  143. package/src/eth/builtin/internal/eacaggregatorproxy-test-utils.ts +17 -4
  144. package/src/eth/builtin/internal/erc1155-processor.ts +5 -5
  145. package/src/eth/builtin/internal/erc1155-test-utils.ts +5 -4
  146. package/src/eth/builtin/internal/erc20-processor.ts +5 -5
  147. package/src/eth/builtin/internal/erc20-test-utils.ts +4 -3
  148. package/src/eth/builtin/internal/erc20bytes-processor.ts +5 -5
  149. package/src/eth/builtin/internal/erc20bytes-test-utils.ts +3 -2
  150. package/src/eth/builtin/internal/erc721-processor.ts +5 -5
  151. package/src/eth/builtin/internal/erc721-test-utils.ts +4 -3
  152. package/src/eth/builtin/internal/weth9-processor.ts +5 -5
  153. package/src/eth/builtin/internal/weth9-test-utils.ts +5 -4
  154. package/src/eth/codegen/ethers-sentio.ts +12 -5
  155. package/src/eth/codegen/file.ts +9 -6
  156. package/src/eth/context.ts +8 -7
  157. package/src/eth/eth-plugin.ts +7 -10
  158. package/src/eth/index.ts +4 -1
  159. package/src/eth/provider.ts +13 -15
  160. package/src/move/abstract-codegen.ts +12 -3
  161. package/src/move/chain-adapter.ts +4 -2
  162. package/src/solana/solana-context.ts +12 -5
  163. package/src/solana/solana-options.ts +2 -1
  164. package/src/solana/solana-processor.ts +3 -3
  165. package/src/sui/context.ts +7 -7
  166. package/src/sui/network.ts +6 -19
  167. package/src/sui/sui-chain-adapter.ts +9 -6
  168. package/src/sui/sui-plugin.ts +1 -2
  169. package/src/sui/sui-processor.ts +3 -3
  170. package/src/testing/aptos-facet.ts +2 -3
  171. package/src/testing/eth-facet.ts +33 -18
  172. package/src/testing/sui-facet.ts +2 -3
  173. package/src/utils/dex-price.ts +5 -4
  174. package/src/utils/price.ts +2 -1
  175. package/src/utils/token.ts +5 -6
@@ -3,8 +3,8 @@ import { SolanaContext } from './solana-context.js'
3
3
  import { Instruction } from '@project-serum/anchor'
4
4
  import { SolanaBindOptions } from './solana-options.js'
5
5
  import { ListStateStorage } from '@sentio/runtime'
6
- import { CHAIN_IDS } from '@sentio/sdk'
7
6
  import { Labels } from '../core/index.js'
7
+ import { SolanaChainId } from '../core/chain.js'
8
8
 
9
9
  type IndexConfigure = {
10
10
  startSlot: bigint
@@ -27,7 +27,7 @@ export class SolanaBaseProcessor {
27
27
  endpoint: string
28
28
  contractName: string
29
29
  baseLabels?: Labels
30
- network: string
30
+ network: SolanaChainId
31
31
  processInnerInstruction: boolean
32
32
  config: IndexConfigure = { startSlot: 0n }
33
33
  instructionCoder: InstructionCoder
@@ -45,7 +45,7 @@ export class SolanaBaseProcessor {
45
45
  this.address = options.address
46
46
  this.contractName = options.name || ''
47
47
  this.processInnerInstruction = options.processInnerInstruction || false
48
- this.network = options.network || CHAIN_IDS.SOLANA_MAINNET
48
+ this.network = options.network || SolanaChainId.SOLANA_MAINNET
49
49
  if (options.instructionCoder) {
50
50
  this.instructionCoder = options.instructionCoder
51
51
  }
@@ -1,6 +1,6 @@
1
1
  import { RecordMetaData } from '@sentio/protos'
2
2
  import { type Labels, BaseContext, normalizeLabels } from '../index.js'
3
- import { SuiNetwork, getChainId } from './network.js'
3
+ import { SuiNetwork } from './network.js'
4
4
  import { SuiTransactionBlockResponse, JsonRpcProvider, Connection } from '@mysten/sui.js'
5
5
  import { MoveCoder, defaultMoveCoder } from './move-coder.js'
6
6
  import { Endpoints } from '@sentio/runtime'
@@ -39,8 +39,8 @@ export class SuiContext extends BaseContext {
39
39
  }
40
40
  }
41
41
 
42
- getChainId(): string {
43
- return getChainId(this.network)
42
+ getChainId() {
43
+ return this.network as any
44
44
  }
45
45
 
46
46
  getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
@@ -58,7 +58,7 @@ export class SuiContext extends BaseContext {
58
58
  }
59
59
 
60
60
  get client(): JsonRpcProvider {
61
- const chainServer = Endpoints.INSTANCE.chainServer.get(getChainId(this.network))
61
+ const chainServer = Endpoints.INSTANCE.chainServer.get(this.network)
62
62
  if (!chainServer) {
63
63
  throw new ServerError(Status.INTERNAL, 'RPC endpoint not provided')
64
64
  }
@@ -82,8 +82,8 @@ export class SuiObjectsContext extends BaseContext {
82
82
  this.coder = defaultMoveCoder(network)
83
83
  }
84
84
 
85
- getChainId(): string {
86
- return getChainId(this.network)
85
+ getChainId() {
86
+ return this.network as any
87
87
  }
88
88
 
89
89
  getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
@@ -101,7 +101,7 @@ export class SuiObjectsContext extends BaseContext {
101
101
  }
102
102
 
103
103
  get client(): JsonRpcProvider {
104
- const chainServer = Endpoints.INSTANCE.chainServer.get(getChainId(this.network))
104
+ const chainServer = Endpoints.INSTANCE.chainServer.get(this.network)
105
105
  if (!chainServer) {
106
106
  throw new ServerError(Status.INTERNAL, 'RPC endpoint not provided')
107
107
  }
@@ -1,23 +1,10 @@
1
- import { CHAIN_IDS, getChainName } from '../core/chain.js'
1
+ import { SuiChainId } from '../core/chain.js'
2
2
 
3
- export enum SuiNetwork {
4
- MAIN_NET = 1,
5
- TEST_NET = 2,
6
- DEV_NET = 3,
7
- }
8
-
9
- export function getChainId(network: SuiNetwork): string {
10
- switch (network) {
11
- case SuiNetwork.TEST_NET:
12
- return CHAIN_IDS.SUI_TESTNET
13
- case SuiNetwork.DEV_NET:
14
- return CHAIN_IDS.SUI_DEVNET
15
- }
16
- return CHAIN_IDS.SUI_MAINNET
17
- }
18
-
19
- export function getSuiChainName(network: SuiNetwork): string {
20
- return getChainName(getChainId(network))
3
+ export type SuiNetwork = SuiChainId
4
+ export const SuiNetwork = <const>{
5
+ MAIN_NET: SuiChainId.SUI_MAINNET,
6
+ TEST_NET: SuiChainId.SUI_TESTNET,
7
+ DEV_NET: SuiChainId.SUI_DEVNET,
21
8
  }
22
9
 
23
10
  export class SuiBindOptions {
@@ -38,14 +38,17 @@ export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedM
38
38
  return Object.values(modules).map(toInternalModule)
39
39
  }
40
40
 
41
- getEventStructs(module: InternalMoveModule) {
42
- const qname = moduleQname(module)
41
+ getAllEventStructs(modules: InternalMoveModule[]): Map<string, InternalMoveStruct> {
43
42
  const eventMap = new Map<string, InternalMoveStruct>()
44
43
 
45
- for (const struct of module.structs) {
46
- const abilities = new Set(struct.abilities)
47
- if (abilities.has('Drop') && abilities.has('Copy')) {
48
- eventMap.set(qname + SPLITTER + struct.name, struct)
44
+ for (const module of modules) {
45
+ const qname = moduleQname(module)
46
+
47
+ for (const struct of module.structs) {
48
+ const abilities = new Set(struct.abilities)
49
+ if (abilities.has('Drop') && abilities.has('Copy')) {
50
+ eventMap.set(qname + SPLITTER + struct.name, struct)
51
+ }
49
52
  }
50
53
  }
51
54
  return eventMap
@@ -16,7 +16,6 @@ import {
16
16
  import { ServerError, Status } from 'nice-grpc'
17
17
 
18
18
  import { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'
19
- import { getChainId } from './network.js'
20
19
  import { validateAndNormalizeAddress } from './utils.js'
21
20
 
22
21
  interface Handlers {
@@ -45,7 +44,7 @@ export class SuiPlugin extends Plugin {
45
44
  processorType: USER_PROCESSOR,
46
45
  contract: {
47
46
  name: suiProcessor.moduleName,
48
- chainId: getChainId(suiProcessor.config.network),
47
+ chainId: suiProcessor.config.network,
49
48
  address: validateAndNormalizeAddress(suiProcessor.config.address),
50
49
  abi: '',
51
50
  },
@@ -8,7 +8,7 @@ import {
8
8
  ProcessResult,
9
9
  } from '@sentio/protos'
10
10
  import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
11
- import { getChainId, SuiNetwork } from './network.js'
11
+ import { SuiNetwork } from './network.js'
12
12
  import { ServerError, Status } from 'nice-grpc'
13
13
  import { SuiContext, SuiObjectsContext } from './context.js'
14
14
  import {
@@ -71,7 +71,7 @@ export class SuiBaseProcessor {
71
71
  }
72
72
 
73
73
  getChainId(): string {
74
- return getChainId(this.config.network)
74
+ return this.config.network
75
75
  }
76
76
 
77
77
  public onMoveEvent(
@@ -236,7 +236,7 @@ abstract class SuiBaseObjectsProcessor<HandlerType> {
236
236
  }
237
237
 
238
238
  getChainId(): string {
239
- return getChainId(this.config.network)
239
+ return this.config.network
240
240
  }
241
241
 
242
242
  // protected abstract transformObjects(objects: SuiMoveObject[]): SuiMoveObject[]
@@ -1,6 +1,5 @@
1
1
  import { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from '../aptos/index.js'
2
2
  import { DataBinding, HandlerType } from '@sentio/protos'
3
- import { getChainId } from '../aptos/network.js'
4
3
  import { TestProcessorServer } from './test-processor-server.js'
5
4
  import { AptosNetwork } from '@sentio/sdk/aptos'
6
5
  import { parseMoveType } from '../move/types.js'
@@ -35,7 +34,7 @@ export class AptosFacet {
35
34
  ): DataBinding | undefined {
36
35
  const payload = transaction.payload as TransactionPayload_EntryFunctionPayload
37
36
  for (const config of this.server.contractConfigs) {
38
- if (config.contract?.chainId !== getChainId(network)) {
37
+ if (config.contract?.chainId !== network) {
39
38
  continue
40
39
  }
41
40
  for (const callConfig of config.moveCallConfigs) {
@@ -71,7 +70,7 @@ export class AptosFacet {
71
70
  ): DataBinding | undefined {
72
71
  // const allEvents = new Set(transaction.events.map(e => e.type))
73
72
  for (const config of this.server.contractConfigs) {
74
- if (config.contract?.chainId !== getChainId(network)) {
73
+ if (config.contract?.chainId !== network) {
75
74
  continue
76
75
  }
77
76
  for (const eventConfig of config.moveEventConfigs) {
@@ -1,9 +1,9 @@
1
1
  import { TestProcessorServer } from './test-processor-server.js'
2
2
  import { DataBinding, HandlerType, ProcessBindingResponse } from '@sentio/protos'
3
3
  import { Trace } from '../eth/eth.js'
4
- import { BlockParams, LogParams, Networkish } from 'ethers/providers'
4
+ import { BlockParams, LogParams } from 'ethers/providers'
5
5
  import { Block } from 'ethers'
6
- import { getNetworkFromCtxOrNetworkish } from '../eth/provider.js'
6
+ import { ChainId, EthChainId } from '../core/chain.js'
7
7
 
8
8
  export class EthFacet {
9
9
  server: TestProcessorServer
@@ -12,11 +12,11 @@ export class EthFacet {
12
12
  this.server = server
13
13
  }
14
14
 
15
- testTrace(trace: Trace, network: Networkish = 1): Promise<ProcessBindingResponse> {
15
+ testTrace(trace: Trace, network: EthChainId = EthChainId.ETHEREUM): Promise<ProcessBindingResponse> {
16
16
  return this.testTraces([trace], network)
17
17
  }
18
18
 
19
- testTraces(traces: Trace[], network: Networkish = 1): Promise<ProcessBindingResponse> {
19
+ testTraces(traces: Trace[], network: EthChainId = EthChainId.ETHEREUM): Promise<ProcessBindingResponse> {
20
20
  const bindings = []
21
21
  for (const trace of traces) {
22
22
  const binding = this.buildTraceBinding(trace, network)
@@ -30,14 +30,14 @@ export class EthFacet {
30
30
  })
31
31
  }
32
32
 
33
- buildTraceBinding(trace: Trace, network: Networkish = 1): DataBinding | undefined {
33
+ buildTraceBinding(trace: Trace, network: ChainId = EthChainId.ETHEREUM): DataBinding | undefined {
34
34
  if (trace.type !== 'call' || !trace.action.input) {
35
35
  throw Error('Invalid test trace: ' + JSON.stringify(trace))
36
36
  }
37
37
  const signature = trace.action.input.slice(0, 10)
38
38
 
39
39
  for (const contract of this.server.contractConfigs) {
40
- if (contract.contract?.chainId !== getNetworkFromCtxOrNetworkish(network).chainId.toString()) {
40
+ if (contract.contract?.chainId !== network) {
41
41
  continue
42
42
  }
43
43
  if (trace.action.to?.toLowerCase() !== contract.contract?.address.toLowerCase()) {
@@ -61,11 +61,11 @@ export class EthFacet {
61
61
  return undefined
62
62
  }
63
63
 
64
- testLog(log: LogParams, network: Networkish = 1): Promise<ProcessBindingResponse> {
64
+ testLog(log: LogParams, network: EthChainId = EthChainId.ETHEREUM): Promise<ProcessBindingResponse> {
65
65
  return this.testLogs([log], network)
66
66
  }
67
67
 
68
- testLogs(logs: LogParams[], network: Networkish = 1): Promise<ProcessBindingResponse> {
68
+ testLogs(logs: LogParams[], network: EthChainId = EthChainId.ETHEREUM): Promise<ProcessBindingResponse> {
69
69
  const bindings = []
70
70
  for (const log of logs) {
71
71
  const binding = this.buildLogBinding(log, network)
@@ -79,9 +79,9 @@ export class EthFacet {
79
79
  })
80
80
  }
81
81
 
82
- buildLogBinding(log: LogParams, network: Networkish = 1): DataBinding | undefined {
82
+ buildLogBinding(log: LogParams, network: EthChainId = EthChainId.ETHEREUM): DataBinding | undefined {
83
83
  for (const contract of this.server.contractConfigs) {
84
- if (contract.contract?.chainId !== getNetworkFromCtxOrNetworkish(network).chainId.toString()) {
84
+ if (contract.contract?.chainId !== network) {
85
85
  continue
86
86
  }
87
87
  if (log.address.toLowerCase() !== contract.contract?.address.toLowerCase()) {
@@ -122,11 +122,19 @@ export class EthFacet {
122
122
  }
123
123
  return undefined
124
124
  }
125
- testAccountLog(address: string, log: LogParams, network: Networkish = 1): Promise<ProcessBindingResponse> {
125
+ testAccountLog(
126
+ address: string,
127
+ log: LogParams,
128
+ network: EthChainId = EthChainId.ETHEREUM
129
+ ): Promise<ProcessBindingResponse> {
126
130
  return this.testAccountLogs(address, [log], network)
127
131
  }
128
132
 
129
- testAccountLogs(address: string, logs: LogParams[], network: Networkish = 1): Promise<ProcessBindingResponse> {
133
+ testAccountLogs(
134
+ address: string,
135
+ logs: LogParams[],
136
+ network: EthChainId = EthChainId.ETHEREUM
137
+ ): Promise<ProcessBindingResponse> {
130
138
  const bindings = []
131
139
  for (const log of logs) {
132
140
  const binding = this.buildAccountLogBinding(address, log, network)
@@ -140,9 +148,13 @@ export class EthFacet {
140
148
  })
141
149
  }
142
150
 
143
- buildAccountLogBinding(address: string, log: LogParams, network: Networkish = 1): DataBinding | undefined {
151
+ buildAccountLogBinding(
152
+ address: string,
153
+ log: LogParams,
154
+ network: EthChainId = EthChainId.ETHEREUM
155
+ ): DataBinding | undefined {
144
156
  for (const account of this.server.accountConfigs) {
145
- if (account.chainId !== getNetworkFromCtxOrNetworkish(network).chainId.toString()) {
157
+ if (account.chainId !== network) {
146
158
  continue
147
159
  }
148
160
  if (address.toLowerCase() !== account.address.toLowerCase()) {
@@ -186,12 +198,12 @@ export class EthFacet {
186
198
 
187
199
  testBlock(
188
200
  block: Partial<BlockParams> & { number: number },
189
- network: Networkish = 1
201
+ network: EthChainId = EthChainId.ETHEREUM
190
202
  ): Promise<ProcessBindingResponse> {
191
203
  return this.testBlocks([block], network)
192
204
  }
193
205
 
194
- testBlocks(blocks: Partial<BlockParams> & { number: number }[], network: Networkish = 1) {
206
+ testBlocks(blocks: Partial<BlockParams> & { number: number }[], network: EthChainId = EthChainId.ETHEREUM) {
195
207
  const bindings = []
196
208
  for (const block of blocks) {
197
209
  const binding = this.buildBlockBinding(block, network)
@@ -205,7 +217,10 @@ export class EthFacet {
205
217
  })
206
218
  }
207
219
 
208
- buildBlockBinding(block: Partial<Block> & { number: number }, network: Networkish = 1): DataBinding {
220
+ buildBlockBinding(
221
+ block: Partial<Block> & { number: number },
222
+ network: EthChainId = EthChainId.ETHEREUM
223
+ ): DataBinding {
209
224
  const binding: DataBinding = {
210
225
  data: {
211
226
  ethBlock: { block },
@@ -214,7 +229,7 @@ export class EthFacet {
214
229
  handlerIds: [],
215
230
  }
216
231
  for (const contract of this.server.contractConfigs) {
217
- if (contract.contract?.chainId !== getNetworkFromCtxOrNetworkish(network).chainId.toString()) {
232
+ if (contract.contract?.chainId !== network) {
218
233
  continue
219
234
  }
220
235
  const longBlockNumber = block.number
@@ -1,6 +1,5 @@
1
1
  import { SuiTransactionBlockResponse, MoveCallSuiTransaction } from '@mysten/sui.js'
2
2
  import { DataBinding, HandlerType } from '@sentio/protos'
3
- import { getChainId } from '../sui/network.js'
4
3
  import { TestProcessorServer } from './test-processor-server.js'
5
4
  import { parseMoveType } from '../move/types.js'
6
5
  import { SuiNetwork } from '../sui/index.js'
@@ -43,7 +42,7 @@ export class SuiFacet {
43
42
  const functionType = [call.package, call.module, call.function].join(SPLITTER)
44
43
 
45
44
  for (const config of this.server.contractConfigs) {
46
- if (config.contract?.chainId !== getChainId(network)) {
45
+ if (config.contract?.chainId !== network) {
47
46
  continue
48
47
  }
49
48
  for (const callConfig of config.moveCallConfigs) {
@@ -83,7 +82,7 @@ export class SuiFacet {
83
82
  // const allEvents = new Set(transaction.events.map(e => e.type))
84
83
 
85
84
  for (const config of this.server.contractConfigs) {
86
- if (config.contract?.chainId !== getChainId(network)) {
85
+ if (config.contract?.chainId !== network) {
87
86
  continue
88
87
  }
89
88
  for (const eventConfig of config.moveEventConfigs) {
@@ -4,6 +4,7 @@ import { parse } from 'csv-parse/sync'
4
4
  import { BlockTag } from 'ethers/providers'
5
5
  import url from 'url'
6
6
  import { scaleDown } from '../core/big-decimal.js'
7
+ import { EthChainId } from '../core/chain.js'
7
8
 
8
9
  type OralceRecord = {
9
10
  Pair: string
@@ -31,9 +32,9 @@ class DexPrice {
31
32
  BTC_ORACLE_MAP = new Map<string, string>()
32
33
  ASSETS_INFOS = new Map<string, number>()
33
34
 
34
- readonly chainId: number
35
+ readonly chainId: EthChainId
35
36
 
36
- constructor(csvFileName: string, chainId: number) {
37
+ constructor(csvFileName: string, chainId: EthChainId) {
37
38
  this.chainId = chainId
38
39
  const csvFilePath = url.fileURLToPath(new URL('./' + csvFileName, import.meta.url))
39
40
  const fileContent = fs.readFileSync(csvFilePath, { encoding: 'utf-8' })
@@ -131,5 +132,5 @@ class DexPrice {
131
132
  }
132
133
  }
133
134
 
134
- export const EthereumDexPrice = new DexPrice('chainlink-oracles.csv', 1)
135
- export const GoerliDexPrice = new DexPrice('chainlink-oracles-goerli.csv', 5)
135
+ export const EthereumDexPrice = new DexPrice('chainlink-oracles.csv', EthChainId.ETHEREUM)
136
+ export const GoerliDexPrice = new DexPrice('chainlink-oracles-goerli.csv', EthChainId.GOERLI)
@@ -3,6 +3,7 @@ import { createChannel, createClientFactory, Status } from 'nice-grpc'
3
3
  import { prometheusClientMiddleware } from 'nice-grpc-prometheus'
4
4
  import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'
5
5
  import { Endpoints } from '@sentio/runtime'
6
+ import { ChainId } from '../core/chain.js'
6
7
 
7
8
  export function getPriceClient(address?: string) {
8
9
  if (!address) {
@@ -98,7 +99,7 @@ export async function getPriceByTypeOrSymbolInternal(
98
99
  * @param options other behavior options
99
100
  */
100
101
  export async function getPriceByType(
101
- chainId: string,
102
+ chainId: ChainId,
102
103
  coinType: string,
103
104
  date: Date,
104
105
  options?: PriceOptions
@@ -2,9 +2,8 @@ import { getERC20Contract } from '../eth/builtin/erc20.js'
2
2
  import { getERC20BytesContract } from '../eth/builtin/erc20bytes.js'
3
3
  import { BigDecimal, scaleDown } from '../core/big-decimal.js'
4
4
  import { PromiseOrValue } from '../eth/builtin/internal/common.js'
5
- import { decodeBytes32String, Networkish } from 'ethers'
6
- import { BaseContext } from '../core/index.js'
7
- import { getNetworkFromCtxOrNetworkish } from '../eth/index.js'
5
+ import { decodeBytes32String } from 'ethers'
6
+ import { EthChainId, EthContext, getEthChainId } from '../eth/index.js'
8
7
 
9
8
  export interface TokenInfo {
10
9
  symbol: string
@@ -33,10 +32,10 @@ async function getTokenInfoPromise(
33
32
  }
34
33
 
35
34
  export async function getERC20TokenInfo(
36
- contextOrNetworkish: BaseContext | Networkish,
35
+ contextOrNetworkish: EthContext | EthChainId,
37
36
  tokenAddress: string
38
37
  ): Promise<TokenInfo> {
39
- const chainId = getNetworkFromCtxOrNetworkish(contextOrNetworkish).chainId.toString()
38
+ const chainId = getEthChainId(contextOrNetworkish)
40
39
  const key = chainId + tokenAddress
41
40
  const res = TOKEN_INFOS.get(key)
42
41
  if (res) {
@@ -67,7 +66,7 @@ export async function getERC20TokenInfo(
67
66
  }
68
67
 
69
68
  export async function getER20NormalizedAmount(
70
- contextOrNetworkish: BaseContext | Networkish,
69
+ contextOrNetworkish: EthContext | EthChainId,
71
70
  tokenAddress: string,
72
71
  amount: bigint
73
72
  ): Promise<BigDecimal> {