@sentio/sdk 2.14.5-rc.1 → 2.15.0-rc.2

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 (160) 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-processor.js +3 -3
  5. package/lib/aptos/aptos-processor.js.map +1 -1
  6. package/lib/aptos/context.d.ts +2 -2
  7. package/lib/aptos/context.js +3 -4
  8. package/lib/aptos/context.js.map +1 -1
  9. package/lib/aptos/ext/coin.js +2 -2
  10. package/lib/aptos/ext/coin.js.map +1 -1
  11. package/lib/aptos/network.d.ts +7 -7
  12. package/lib/aptos/network.js +6 -19
  13. package/lib/aptos/network.js.map +1 -1
  14. package/lib/core/base-context.d.ts +2 -1
  15. package/lib/core/base-context.js.map +1 -1
  16. package/lib/core/chain.d.ts +196 -93
  17. package/lib/core/chain.js +113 -96
  18. package/lib/core/chain.js.map +1 -1
  19. package/lib/core/yaml-contract-config.d.ts +2 -1
  20. package/lib/core/yaml-contract-config.js.map +1 -1
  21. package/lib/eth/account-processor.d.ts +3 -2
  22. package/lib/eth/account-processor.js +3 -3
  23. package/lib/eth/account-processor.js.map +1 -1
  24. package/lib/eth/base-processor-template.d.ts +2 -3
  25. package/lib/eth/base-processor-template.js +1 -2
  26. package/lib/eth/base-processor-template.js.map +1 -1
  27. package/lib/eth/base-processor.d.ts +5 -5
  28. package/lib/eth/base-processor.js +5 -5
  29. package/lib/eth/base-processor.js.map +1 -1
  30. package/lib/eth/bind-options.d.ts +3 -3
  31. package/lib/eth/bind-options.js +3 -4
  32. package/lib/eth/bind-options.js.map +1 -1
  33. package/lib/eth/binds.d.ts +3 -3
  34. package/lib/eth/binds.js +1 -3
  35. package/lib/eth/binds.js.map +1 -1
  36. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +2 -4
  37. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +2 -2
  38. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  39. package/lib/eth/builtin/internal/eacaggregatorproxy-test-utils.js +5 -4
  40. package/lib/eth/builtin/internal/eacaggregatorproxy-test-utils.js.map +1 -1
  41. package/lib/eth/builtin/internal/erc1155-processor.d.ts +2 -4
  42. package/lib/eth/builtin/internal/erc1155-processor.js +2 -2
  43. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  44. package/lib/eth/builtin/internal/erc1155-test-utils.js +5 -4
  45. package/lib/eth/builtin/internal/erc1155-test-utils.js.map +1 -1
  46. package/lib/eth/builtin/internal/erc20-processor.d.ts +2 -4
  47. package/lib/eth/builtin/internal/erc20-processor.js +2 -2
  48. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  49. package/lib/eth/builtin/internal/erc20-test-utils.js +4 -3
  50. package/lib/eth/builtin/internal/erc20-test-utils.js.map +1 -1
  51. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +2 -4
  52. package/lib/eth/builtin/internal/erc20bytes-processor.js +2 -2
  53. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  54. package/lib/eth/builtin/internal/erc20bytes-test-utils.js +3 -2
  55. package/lib/eth/builtin/internal/erc20bytes-test-utils.js.map +1 -1
  56. package/lib/eth/builtin/internal/erc721-processor.d.ts +2 -4
  57. package/lib/eth/builtin/internal/erc721-processor.js +2 -2
  58. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  59. package/lib/eth/builtin/internal/erc721-test-utils.js +4 -3
  60. package/lib/eth/builtin/internal/erc721-test-utils.js.map +1 -1
  61. package/lib/eth/builtin/internal/weth9-processor.d.ts +2 -4
  62. package/lib/eth/builtin/internal/weth9-processor.js +2 -2
  63. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  64. package/lib/eth/builtin/internal/weth9-test-utils.js +5 -4
  65. package/lib/eth/builtin/internal/weth9-test-utils.js.map +1 -1
  66. package/lib/eth/codegen/ethers-sentio.js +11 -4
  67. package/lib/eth/codegen/ethers-sentio.js.map +1 -1
  68. package/lib/eth/codegen/file.js +9 -6
  69. package/lib/eth/codegen/file.js.map +1 -1
  70. package/lib/eth/context.d.ts +6 -5
  71. package/lib/eth/context.js +2 -2
  72. package/lib/eth/context.js.map +1 -1
  73. package/lib/eth/eth-plugin.js +7 -9
  74. package/lib/eth/eth-plugin.js.map +1 -1
  75. package/lib/eth/index.d.ts +3 -1
  76. package/lib/eth/index.js +3 -1
  77. package/lib/eth/index.js.map +1 -1
  78. package/lib/eth/provider.d.ts +5 -5
  79. package/lib/eth/provider.js +12 -14
  80. package/lib/eth/provider.js.map +1 -1
  81. package/lib/eth/provider.test.js.map +1 -1
  82. package/lib/solana/solana-context.d.ts +4 -3
  83. package/lib/solana/solana-context.js +3 -2
  84. package/lib/solana/solana-context.js.map +1 -1
  85. package/lib/solana/solana-options.d.ts +2 -1
  86. package/lib/solana/solana-options.js.map +1 -1
  87. package/lib/solana/solana-processor.d.ts +2 -1
  88. package/lib/solana/solana-processor.js +2 -2
  89. package/lib/solana/solana-processor.js.map +1 -1
  90. package/lib/sui/context.d.ts +2 -2
  91. package/lib/sui/context.js +4 -5
  92. package/lib/sui/context.js.map +1 -1
  93. package/lib/sui/network.d.ts +7 -7
  94. package/lib/sui/network.js +6 -19
  95. package/lib/sui/network.js.map +1 -1
  96. package/lib/sui/sui-plugin.js +1 -2
  97. package/lib/sui/sui-plugin.js.map +1 -1
  98. package/lib/sui/sui-processor.js +3 -3
  99. package/lib/sui/sui-processor.js.map +1 -1
  100. package/lib/testing/aptos-facet.js +2 -3
  101. package/lib/testing/aptos-facet.js.map +1 -1
  102. package/lib/testing/eth-facet.d.ts +14 -13
  103. package/lib/testing/eth-facet.js +17 -17
  104. package/lib/testing/eth-facet.js.map +1 -1
  105. package/lib/testing/sui-facet.js +2 -3
  106. package/lib/testing/sui-facet.js.map +1 -1
  107. package/lib/utils/dex-price.d.ts +3 -2
  108. package/lib/utils/dex-price.js +3 -2
  109. package/lib/utils/dex-price.js.map +1 -1
  110. package/lib/utils/erc20.test.js.map +1 -1
  111. package/lib/utils/price.d.ts +2 -1
  112. package/lib/utils/price.js.map +1 -1
  113. package/lib/utils/token.d.ts +3 -4
  114. package/lib/utils/token.js +2 -2
  115. package/lib/utils/token.js.map +1 -1
  116. package/package.json +3 -3
  117. package/src/aptos/api.ts +2 -2
  118. package/src/aptos/aptos-processor.ts +3 -3
  119. package/src/aptos/context.ts +6 -6
  120. package/src/aptos/ext/coin.ts +2 -2
  121. package/src/aptos/network.ts +6 -19
  122. package/src/core/base-context.ts +2 -1
  123. package/src/core/chain.ts +114 -96
  124. package/src/core/yaml-contract-config.ts +3 -1
  125. package/src/eth/account-processor.ts +7 -7
  126. package/src/eth/base-processor-template.ts +3 -5
  127. package/src/eth/base-processor.ts +9 -10
  128. package/src/eth/bind-options.ts +4 -6
  129. package/src/eth/binds.ts +5 -7
  130. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +5 -5
  131. package/src/eth/builtin/internal/eacaggregatorproxy-test-utils.ts +17 -4
  132. package/src/eth/builtin/internal/erc1155-processor.ts +5 -5
  133. package/src/eth/builtin/internal/erc1155-test-utils.ts +5 -4
  134. package/src/eth/builtin/internal/erc20-processor.ts +5 -5
  135. package/src/eth/builtin/internal/erc20-test-utils.ts +4 -3
  136. package/src/eth/builtin/internal/erc20bytes-processor.ts +5 -5
  137. package/src/eth/builtin/internal/erc20bytes-test-utils.ts +3 -2
  138. package/src/eth/builtin/internal/erc721-processor.ts +5 -5
  139. package/src/eth/builtin/internal/erc721-test-utils.ts +4 -3
  140. package/src/eth/builtin/internal/weth9-processor.ts +5 -5
  141. package/src/eth/builtin/internal/weth9-test-utils.ts +5 -4
  142. package/src/eth/codegen/ethers-sentio.ts +12 -5
  143. package/src/eth/codegen/file.ts +9 -6
  144. package/src/eth/context.ts +8 -7
  145. package/src/eth/eth-plugin.ts +7 -10
  146. package/src/eth/index.ts +4 -1
  147. package/src/eth/provider.ts +13 -15
  148. package/src/solana/solana-context.ts +12 -5
  149. package/src/solana/solana-options.ts +2 -1
  150. package/src/solana/solana-processor.ts +3 -3
  151. package/src/sui/context.ts +7 -7
  152. package/src/sui/network.ts +6 -19
  153. package/src/sui/sui-plugin.ts +1 -2
  154. package/src/sui/sui-processor.ts +3 -3
  155. package/src/testing/aptos-facet.ts +2 -3
  156. package/src/testing/eth-facet.ts +33 -18
  157. package/src/testing/sui-facet.ts +2 -3
  158. package/src/utils/dex-price.ts +5 -4
  159. package/src/utils/price.ts +2 -1
  160. package/src/utils/token.ts +5 -6
@@ -106,10 +106,10 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
106
106
  .join('\n')}
107
107
  }
108
108
 
109
- export function get${contract.name}Contract(contextOrNetwork: BaseContext | Networkish, address: string): ${
109
+ export function get${contract.name}Contract(contextOrNetwork: EthContext | EthChainId, address: string): ${
110
110
  contract.name
111
111
  }ContractView {
112
- const network = getNetworkFromCtxOrNetworkish(contextOrNetwork)
112
+ const network = getEthChainId(contextOrNetwork)
113
113
  let contract = getContractByABI("${contract.name}", address, network) as ${contract.name}ContractView
114
114
  if (!contract) {
115
115
  const rawContract = ${contract.name}__factory.connect(address, getProvider(network))
@@ -148,7 +148,7 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
148
148
  const imports = createImportsForUsedIdentifiers(
149
149
  {
150
150
  ethers: ['BigNumberish', 'Overrides', 'BytesLike'],
151
- 'ethers/providers': ['Networkish'],
151
+ // 'ethers/providers': ['Networkish'],
152
152
  '@sentio/sdk/eth': [
153
153
  'addContractByABI',
154
154
  'getContractByABI',
@@ -164,12 +164,14 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
164
164
  'ContractContext',
165
165
  'ContractView',
166
166
  'DummyProvider',
167
+ 'EthChainId',
167
168
  'TypedCallTrace',
168
- 'getNetworkFromCtxOrNetworkish',
169
+ 'getEthChainId',
169
170
  // 'toBlockTag',
171
+ 'EthContext',
170
172
  'EthFetchConfig',
171
173
  ],
172
- '@sentio/sdk': ['BaseContext'],
174
+ // '@sentio/sdk/eth': ['BaseContext'],
173
175
  // '@sentio/protos': ['EthFetchConfig'],
174
176
  './common.js': ['PromiseOrValue'],
175
177
  './index.js': [`${contract.name}`, `${contract.name}__factory`],
@@ -206,6 +208,7 @@ export function codeGenTestUtilsFile(contract: Contract): string {
206
208
 
207
209
  const possibleImports = {
208
210
  'ethers/providers': ['LogParams'],
211
+ '@sentio/sdk/eth': ['EthChainId'],
209
212
  } as any
210
213
  possibleImports[`./${contract.name}.js`] = Object.values(contract.events).flatMap((events) => {
211
214
  if (events.length === 1) {
@@ -232,7 +235,7 @@ function generateMockEventLogFunction(event: EventDeclaration, contractName: str
232
235
 
233
236
  return `
234
237
  export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): LogParams {
235
- const contract = get${contractName}Contract(1, contractAddress)
238
+ const contract = get${contractName}Contract(EthChainId.ETHEREUM, contractAddress)
236
239
  const encodedLog = contract.rawContract.interface.encodeEventLog(
237
240
  '${getFullSignatureForEvent(event)}',
238
241
  [${eventArgs.join(', ')}]
@@ -5,9 +5,10 @@ import { RecordMetaData } from '@sentio/protos'
5
5
  import { Trace } from './eth.js'
6
6
  import { Labels, normalizeLabels } from '../core/index.js'
7
7
  import { BaseContext } from '../core/base-context.js'
8
+ import { EthChainId } from '../core/chain.js'
8
9
 
9
10
  export abstract class EthContext extends BaseContext {
10
- chainId: number
11
+ chainId: EthChainId
11
12
  address: string
12
13
  private readonly log?: LogParams
13
14
  block?: BlockParams
@@ -19,7 +20,7 @@ export abstract class EthContext extends BaseContext {
19
20
  timestamp: Date
20
21
 
21
22
  constructor(
22
- chainId: number,
23
+ chainId: EthChainId,
23
24
  address: string,
24
25
  timestamp?: Date,
25
26
  block?: BlockParams,
@@ -51,8 +52,8 @@ export abstract class EthContext extends BaseContext {
51
52
 
52
53
  protected abstract getContractName(): string
53
54
 
54
- getChainId(): string {
55
- return this.chainId.toString()
55
+ getChainId(): EthChainId {
56
+ return this.chainId
56
57
  }
57
58
 
58
59
  getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
@@ -64,7 +65,7 @@ export abstract class EthContext extends BaseContext {
64
65
  transactionIndex: this.log.transactionIndex,
65
66
  transactionHash: this.transactionHash || '',
66
67
  logIndex: this.log.index,
67
- chainId: this.chainId.toString(),
68
+ chainId: this.chainId,
68
69
  name: name,
69
70
  labels: normalizeLabels(labels),
70
71
  }
@@ -110,7 +111,7 @@ export class AccountContext extends EthContext {
110
111
 
111
112
  export class GlobalContext extends EthContext {
112
113
  constructor(
113
- chainId: number,
114
+ chainId: EthChainId,
114
115
  timestamp?: Date,
115
116
  block?: BlockParams,
116
117
  log?: LogParams,
@@ -135,7 +136,7 @@ export class ContractContext<
135
136
  constructor(
136
137
  contractName: string,
137
138
  view: TContractBoundView,
138
- chainId: number,
139
+ chainId: EthChainId,
139
140
  timestamp?: Date,
140
141
  block?: BlockParams,
141
142
  log?: LogParams,
@@ -12,7 +12,6 @@ import {
12
12
  LogHandlerConfig,
13
13
  ProcessConfigResponse,
14
14
  ProcessResult,
15
- RecordMetaData,
16
15
  StartRequest,
17
16
  } from '@sentio/protos'
18
17
 
@@ -22,7 +21,8 @@ import { AccountProcessorState } from './account-processor-state.js'
22
21
  import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template.js'
23
22
  import { GlobalProcessorState } from './base-processor.js'
24
23
  import { validateAndNormalizeAddress } from './eth.js'
25
- import { BaseContext, Labels } from '../core/index.js'
24
+ import { EthChainId } from '../core/chain.js'
25
+ import { EthContext } from './context.js'
26
26
 
27
27
  interface Handlers {
28
28
  eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[]
@@ -256,7 +256,7 @@ export class EthPlugin extends Plugin {
256
256
  {
257
257
  name: instance.contract.name,
258
258
  address: validateAndNormalizeAddress(instance.contract.address),
259
- network: Number(instance.contract.chainId),
259
+ network: instance.contract.chainId as EthChainId,
260
260
  startBlock: instance.startBlock,
261
261
  endBlock: instance.endBlock,
262
262
  },
@@ -355,15 +355,12 @@ export class EthPlugin extends Plugin {
355
355
 
356
356
  PluginManager.INSTANCE.register(new EthPlugin())
357
357
 
358
- class NoopContext extends BaseContext {
358
+ class NoopContext extends EthContext {
359
359
  public constructor() {
360
- super({})
361
- }
362
- getChainId(): string {
363
- return ''
360
+ super(EthChainId.ETHEREUM, '')
364
361
  }
365
362
 
366
- getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
367
- return RecordMetaData.create()
363
+ protected getContractName(): string {
364
+ return ''
368
365
  }
369
366
  }
package/src/eth/index.ts CHANGED
@@ -2,7 +2,8 @@ export { BaseProcessor, GlobalProcessor } from './base-processor.js'
2
2
  export { GenericProcessor } from './generic-processor.js'
3
3
  export { BaseProcessorTemplate } from './base-processor-template.js'
4
4
  export { AccountProcessor } from './account-processor.js'
5
- export { getProvider, DummyProvider, getNetworkFromCtxOrNetworkish } from './provider.js'
5
+ export { getProvider, DummyProvider, getEthChainId } from './provider.js'
6
+ export { EthContext } from './context.js'
6
7
  export * from './eth.js'
7
8
  export { BindOptions, AccountBindOptions } from './bind-options.js'
8
9
  export { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds.js'
@@ -11,3 +12,5 @@ export { ContractContext, GlobalContext, ContractView, BoundContractView } from
11
12
  export { EthPlugin } from './eth-plugin.js'
12
13
 
13
14
  export { EthFetchConfig } from '@sentio/protos'
15
+
16
+ export { EthChainId } from '../core/chain.js'
@@ -1,36 +1,34 @@
1
- import { Provider, Network, JsonRpcProvider } from 'ethers'
2
- import { Networkish } from 'ethers/providers'
1
+ import { JsonRpcProvider, Network, Provider } from 'ethers'
3
2
 
4
3
  import PQueue from 'p-queue'
5
4
  import { Endpoints } from '@sentio/runtime'
6
5
  import { BaseContext } from '../core/index.js'
6
+ import { EthChainId } from '../core/chain.js'
7
+ import { EthContext } from './context.js'
7
8
 
8
9
  export const DummyProvider = new JsonRpcProvider('', Network.from(1))
9
10
 
10
11
  const providers = new Map<string, JsonRpcProvider>()
11
12
 
12
- export function getNetworkFromCtxOrNetworkish(networkish?: BaseContext | Networkish) {
13
+ export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {
13
14
  if (!networkish) {
14
- networkish = 1
15
+ networkish = EthChainId.ETHEREUM
15
16
  }
16
17
  if (networkish instanceof BaseContext) {
17
18
  networkish = networkish.getChainId()
18
19
  }
19
- if (typeof networkish === 'string') {
20
- const id = parseInt(networkish)
21
- if (isNaN(id)) {
22
- throw Error('Unexpected Network')
23
- }
24
- networkish = id
25
- }
26
- return Network.from(networkish)
20
+ return networkish
27
21
  }
28
22
 
29
- export function getProvider(networkish?: Networkish): Provider {
30
- const network = getNetworkFromCtxOrNetworkish(networkish)
23
+ export function getProvider(chainId?: EthChainId): Provider {
24
+ // const network = getNetworkFromCtxOrNetworkish(networkish)
25
+ if (!chainId) {
26
+ chainId = EthChainId.ETHEREUM
27
+ }
28
+ const network = Network.from(parseInt(chainId))
31
29
  // TODO check if other key needed
32
30
 
33
- const address = Endpoints.INSTANCE.chainServer.get(network.chainId.toString())
31
+ const address = Endpoints.INSTANCE.chainServer.get(chainId)
34
32
  const key = network.chainId.toString() + '-' + address
35
33
  let provider = providers.get(key)
36
34
 
@@ -1,20 +1,27 @@
1
- import { normalizeLabels, Labels, BaseContext, RecordMetaData, CHAIN_IDS } from '@sentio/sdk'
1
+ import { normalizeLabels, Labels, BaseContext, RecordMetaData } from '@sentio/sdk'
2
+ import { SolanaChainId } from '../core/chain.js'
2
3
 
3
4
  export class SolanaContext extends BaseContext {
4
- network: string
5
+ network: SolanaChainId
5
6
  address: string
6
7
  programName: string
7
8
  blockNumber: bigint
8
9
 
9
- constructor(programName: string, network: string, address: string, slot: bigint, baseLabels: Labels | undefined) {
10
+ constructor(
11
+ programName: string,
12
+ network: SolanaChainId,
13
+ address: string,
14
+ slot: bigint,
15
+ baseLabels: Labels | undefined
16
+ ) {
10
17
  super(baseLabels)
11
- this.network = network || CHAIN_IDS.SOLANA_MAINNET
18
+ this.network = network || SolanaChainId.SOLANA_MAINNET
12
19
  this.programName = programName
13
20
  this.address = address
14
21
  this.blockNumber = slot
15
22
  }
16
23
 
17
- getChainId(): string {
24
+ getChainId() {
18
25
  return this.network
19
26
  }
20
27
 
@@ -1,9 +1,10 @@
1
1
  import { InstructionCoder } from './solana-processor.js'
2
2
  import { Labels } from '../core/index.js'
3
+ import { SolanaChainId } from '../core/chain.js'
3
4
 
4
5
  export class SolanaBindOptions {
5
6
  address: string
6
- network?: string
7
+ network?: SolanaChainId
7
8
  name?: string
8
9
  startBlock?: bigint | number
9
10
  endBlock?: bigint | number
@@ -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 {
@@ -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