@sentio/sdk 2.12.3 → 2.13.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 (145) hide show
  1. package/lib/aptos/aptos-chain-adapter.d.ts +14 -0
  2. package/lib/aptos/aptos-chain-adapter.js +69 -0
  3. package/lib/aptos/aptos-chain-adapter.js.map +1 -0
  4. package/lib/aptos/aptos-plugin.js +2 -0
  5. package/lib/aptos/aptos-plugin.js.map +1 -1
  6. package/lib/aptos/aptos-processor.d.ts +7 -7
  7. package/lib/aptos/aptos-processor.js +27 -26
  8. package/lib/aptos/aptos-processor.js.map +1 -1
  9. package/lib/aptos/builtin/0x1.d.ts +1244 -599
  10. package/lib/aptos/builtin/0x1.js +1939 -1458
  11. package/lib/aptos/builtin/0x1.js.map +1 -1
  12. package/lib/aptos/builtin/0x3.d.ts +241 -118
  13. package/lib/aptos/builtin/0x3.js +373 -333
  14. package/lib/aptos/builtin/0x3.js.map +1 -1
  15. package/lib/aptos/codegen/codegen.d.ts +1 -1
  16. package/lib/aptos/codegen/codegen.js +6 -47
  17. package/lib/aptos/codegen/codegen.js.map +1 -1
  18. package/lib/aptos/codegen/run.js +1 -1
  19. package/lib/aptos/codegen/run.js.map +1 -1
  20. package/lib/aptos/context.d.ts +5 -1
  21. package/lib/aptos/context.js +9 -2
  22. package/lib/aptos/context.js.map +1 -1
  23. package/lib/aptos/ext/aptos-dex.d.ts +2 -1
  24. package/lib/aptos/ext/aptos-dex.js +1 -2
  25. package/lib/aptos/ext/aptos-dex.js.map +1 -1
  26. package/lib/aptos/index.d.ts +1 -0
  27. package/lib/aptos/index.js +1 -0
  28. package/lib/aptos/index.js.map +1 -1
  29. package/lib/aptos/models.d.ts +3 -11
  30. package/lib/aptos/models.js.map +1 -1
  31. package/lib/aptos/module-client.js +1 -1
  32. package/lib/aptos/module-client.js.map +1 -1
  33. package/lib/aptos/move-coder.d.ts +10 -10
  34. package/lib/aptos/move-coder.js +37 -18
  35. package/lib/aptos/move-coder.js.map +1 -1
  36. package/lib/eth/base-processor-template.d.ts +4 -3
  37. package/lib/eth/base-processor-template.js +7 -7
  38. package/lib/eth/base-processor-template.js.map +1 -1
  39. package/lib/eth/base-processor.d.ts +9 -8
  40. package/lib/eth/base-processor.js +13 -11
  41. package/lib/eth/base-processor.js.map +1 -1
  42. package/lib/eth/eth-plugin.js +2 -0
  43. package/lib/eth/eth-plugin.js.map +1 -1
  44. package/lib/eth/eth.d.ts +7 -2
  45. package/lib/eth/eth.js +8 -1
  46. package/lib/eth/eth.js.map +1 -1
  47. package/lib/move/abstract-codegen.d.ts +11 -11
  48. package/lib/move/abstract-codegen.js +60 -23
  49. package/lib/move/abstract-codegen.js.map +1 -1
  50. package/lib/move/abstract-move-coder.d.ts +19 -25
  51. package/lib/move/abstract-move-coder.js +74 -51
  52. package/lib/move/abstract-move-coder.js.map +1 -1
  53. package/lib/move/chain-adapter.d.ts +11 -0
  54. package/lib/move/chain-adapter.js +3 -0
  55. package/lib/move/chain-adapter.js.map +1 -0
  56. package/lib/move/index.d.ts +1 -0
  57. package/lib/move/index.js +1 -0
  58. package/lib/move/index.js.map +1 -1
  59. package/lib/move/types.d.ts +28 -1
  60. package/lib/move/types.js +65 -16
  61. package/lib/move/types.js.map +1 -1
  62. package/lib/sui/builtin/0x1.d.ts +37 -18
  63. package/lib/sui/builtin/0x1.js +58 -32
  64. package/lib/sui/builtin/0x1.js.map +1 -1
  65. package/lib/sui/builtin/0x2.d.ts +299 -149
  66. package/lib/sui/builtin/0x2.js +463 -322
  67. package/lib/sui/builtin/0x2.js.map +1 -1
  68. package/lib/sui/builtin/0x3.d.ts +169 -94
  69. package/lib/sui/builtin/0x3.js +229 -272
  70. package/lib/sui/builtin/0x3.js.map +1 -1
  71. package/lib/sui/codegen/codegen.d.ts +1 -1
  72. package/lib/sui/codegen/codegen.js +10 -36
  73. package/lib/sui/codegen/codegen.js.map +1 -1
  74. package/lib/sui/codegen/run.js +1 -1
  75. package/lib/sui/codegen/run.js.map +1 -1
  76. package/lib/sui/context.d.ts +5 -1
  77. package/lib/sui/context.js +8 -1
  78. package/lib/sui/context.js.map +1 -1
  79. package/lib/sui/index.d.ts +1 -0
  80. package/lib/sui/index.js +1 -0
  81. package/lib/sui/index.js.map +1 -1
  82. package/lib/sui/models.d.ts +3 -11
  83. package/lib/sui/models.js.map +1 -1
  84. package/lib/sui/move-coder.d.ts +15 -15
  85. package/lib/sui/move-coder.js +43 -39
  86. package/lib/sui/move-coder.js.map +1 -1
  87. package/lib/sui/sui-chain-adapter.d.ts +14 -0
  88. package/lib/sui/sui-chain-adapter.js +69 -0
  89. package/lib/sui/sui-chain-adapter.js.map +1 -0
  90. package/lib/sui/sui-plugin.js +1 -0
  91. package/lib/sui/sui-plugin.js.map +1 -1
  92. package/lib/sui/sui-processor.d.ts +8 -5
  93. package/lib/sui/sui-processor.js +23 -14
  94. package/lib/sui/sui-processor.js.map +1 -1
  95. package/lib/sui/utils.d.ts +0 -2
  96. package/lib/sui/utils.js +0 -6
  97. package/lib/sui/utils.js.map +1 -1
  98. package/lib/testing/aptos-facet.d.ts +2 -2
  99. package/lib/testing/aptos-facet.js +14 -21
  100. package/lib/testing/aptos-facet.js.map +1 -1
  101. package/lib/testing/sui-facet.d.ts +2 -2
  102. package/lib/testing/sui-facet.js +16 -26
  103. package/lib/testing/sui-facet.js.map +1 -1
  104. package/package.json +4 -4
  105. package/src/aptos/aptos-chain-adapter.ts +81 -0
  106. package/src/aptos/aptos-plugin.ts +2 -0
  107. package/src/aptos/aptos-processor.ts +58 -43
  108. package/src/aptos/builtin/0x1.ts +2858 -616
  109. package/src/aptos/builtin/0x3.ts +543 -120
  110. package/src/aptos/codegen/codegen.ts +13 -57
  111. package/src/aptos/codegen/run.ts +1 -1
  112. package/src/aptos/context.ts +10 -2
  113. package/src/aptos/ext/aptos-dex.ts +4 -12
  114. package/src/aptos/index.ts +2 -0
  115. package/src/aptos/models.ts +3 -13
  116. package/src/aptos/module-client.ts +1 -1
  117. package/src/aptos/move-coder.ts +48 -25
  118. package/src/eth/base-processor-template.ts +20 -10
  119. package/src/eth/base-processor.ts +45 -25
  120. package/src/eth/eth-plugin.ts +2 -0
  121. package/src/eth/eth.ts +15 -2
  122. package/src/move/abstract-codegen.ts +75 -38
  123. package/src/move/abstract-move-coder.ts +87 -75
  124. package/src/move/chain-adapter.ts +17 -0
  125. package/src/move/index.ts +1 -0
  126. package/src/move/types.ts +83 -17
  127. package/src/sui/builtin/0x1.ts +75 -20
  128. package/src/sui/builtin/0x2.ts +694 -150
  129. package/src/sui/builtin/0x3.ts +360 -95
  130. package/src/sui/codegen/codegen.ts +17 -43
  131. package/src/sui/codegen/run.ts +1 -1
  132. package/src/sui/context.ts +9 -1
  133. package/src/sui/index.ts +1 -0
  134. package/src/sui/models.ts +3 -13
  135. package/src/sui/move-coder.ts +58 -53
  136. package/src/sui/sui-chain-adapter.ts +86 -0
  137. package/src/sui/sui-plugin.ts +1 -0
  138. package/src/sui/sui-processor.ts +41 -28
  139. package/src/sui/utils.ts +0 -8
  140. package/src/testing/aptos-facet.ts +13 -27
  141. package/src/testing/sui-facet.ts +15 -30
  142. package/lib/aptos/utils.d.ts +0 -2
  143. package/lib/aptos/utils.js +0 -10
  144. package/lib/aptos/utils.js.map +0 -1
  145. package/src/aptos/utils.ts +0 -11
@@ -1,76 +1,32 @@
1
1
  import * as fs from 'fs'
2
- import { MoveModuleBytecode, toInternalModule } from '../move-types.js'
3
- import { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'
2
+ import { Event, MoveModuleBytecode, MoveResource } from '../move-types.js'
4
3
  import chalk from 'chalk'
5
4
  import { AptosNetwork } from '../network.js'
6
- import { AptosClient } from 'aptos-sdk'
7
- import { getMeaningfulFunctionParams } from '../utils.js'
8
- import { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'
5
+ import { join } from 'path'
6
+ import { AptosChainAdapter } from '../aptos-chain-adapter.js'
9
7
  import { AbstractCodegen } from '../../move/abstract-codegen.js'
10
- import {join} from "path";
11
8
 
12
- export async function codegen(abisDir: string, outDir = join('src', 'types', 'aptos'), genExample = false) {
9
+ export async function codegen(
10
+ abisDir: string,
11
+ outDir = join('src', 'types', 'aptos'),
12
+ genExample = false,
13
+ builtin = false
14
+ ) {
13
15
  if (!fs.existsSync(abisDir)) {
14
16
  return
15
17
  }
16
18
  const gen = new AptosCodegen()
17
- const numFiles = await gen.generate(abisDir, outDir)
19
+ const numFiles = await gen.generate(abisDir, outDir, builtin)
18
20
  console.log(chalk.green(`Generated ${numFiles} for Aptos`))
19
21
  }
20
22
 
21
- function getRpcEndpoint(network: AptosNetwork): string {
22
- switch (network) {
23
- case AptosNetwork.TEST_NET:
24
- return 'https://testnet.aptoslabs.com/'
25
- }
26
- return 'https://mainnet.aptoslabs.com/'
27
- }
28
-
29
- function getRpcClient(network: AptosNetwork): AptosClient {
30
- return new AptosClient(getRpcEndpoint(network))
31
- }
32
-
33
- class AptosCodegen extends AbstractCodegen<MoveModuleBytecode[], AptosNetwork> {
23
+ class AptosCodegen extends AbstractCodegen<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
34
24
  ADDRESS_TYPE = 'Address'
35
25
  MAIN_NET = AptosNetwork.MAIN_NET
36
26
  TEST_NET = AptosNetwork.TEST_NET
37
27
  PREFIX = 'Aptos'
38
28
 
39
- async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {
40
- const client = getRpcClient(network)
41
- return await client.getAccountModules(account)
42
- }
43
-
44
- toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {
45
- return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))
46
- }
47
-
48
- getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
49
- return getMeaningfulFunctionParams(params)
50
- }
51
-
52
- getEventStructs(module: InternalMoveModule) {
53
- const qname = moduleQname(module)
54
- const structMap = new Map<string, InternalMoveStruct>()
55
- const eventMap = new Map<string, InternalMoveStruct>()
56
-
57
- for (const struct of module.structs) {
58
- structMap.set(qname + SPLITTER + struct.name, struct)
59
- }
60
-
61
- for (const struct of module.structs) {
62
- for (const field of struct.fields) {
63
- const t = field.type
64
- if (t.qname === '0x1::event::EventHandle') {
65
- const event = t.typeArgs[0].qname
66
- const eventStruct = structMap.get(event)
67
- if (eventStruct) {
68
- eventMap.set(event, eventStruct)
69
- }
70
- }
71
- }
72
- }
73
-
74
- return eventMap
29
+ constructor() {
30
+ super(AptosChainAdapter.INSTANCE)
75
31
  }
76
32
  }
@@ -6,7 +6,7 @@ if (process.argv.length > 3) {
6
6
  const abisDir = process.argv[2]
7
7
  const targetDir = process.argv[3]
8
8
 
9
- await codegen(abisDir, targetDir)
9
+ await codegen(abisDir, targetDir, false, true)
10
10
  } else {
11
11
  console.error('Not enough argument')
12
12
  process.exit(1)
@@ -2,6 +2,7 @@ import { RecordMetaData } from '@sentio/protos'
2
2
  import { type Labels, BaseContext, normalizeLabels } from '@sentio/sdk'
3
3
  import { Transaction_UserTransaction } from './move-types.js'
4
4
  import { AptosNetwork, getChainId } from './network.js'
5
+ import { defaultMoveCoder, MoveCoder } from './move-coder.js'
5
6
 
6
7
  export class AptosContext extends BaseContext {
7
8
  address: string
@@ -9,19 +10,24 @@ export class AptosContext extends BaseContext {
9
10
  moduleName: string
10
11
  version: bigint
11
12
  transaction: Transaction_UserTransaction
13
+ eventIndex: number
14
+ coder: MoveCoder
12
15
 
13
16
  constructor(
14
17
  moduleName: string,
15
18
  network: AptosNetwork,
16
19
  address: string,
17
20
  version: bigint,
18
- transaction?: Transaction_UserTransaction
21
+ transaction: Transaction_UserTransaction,
22
+ eventIndex: number
19
23
  ) {
20
24
  super()
21
25
  this.address = address.toLowerCase()
22
26
  this.network = network
23
27
  this.moduleName = moduleName
24
28
  this.version = version
29
+ this.eventIndex = eventIndex
30
+ this.coder = defaultMoveCoder(network)
25
31
  if (transaction) {
26
32
  this.transaction = transaction
27
33
  }
@@ -38,7 +44,7 @@ export class AptosContext extends BaseContext {
38
44
  blockNumber: this.version,
39
45
  transactionIndex: 0,
40
46
  transactionHash: this.transaction?.hash || '', // TODO
41
- logIndex: 0,
47
+ logIndex: this.eventIndex,
42
48
  chainId: this.getChainId(),
43
49
  name: name,
44
50
  labels: normalizeLabels(labels),
@@ -51,6 +57,7 @@ export class AptosResourcesContext extends BaseContext {
51
57
  network: AptosNetwork
52
58
  version: bigint
53
59
  timestampInMicros: number
60
+ coder: MoveCoder
54
61
 
55
62
  constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {
56
63
  super()
@@ -58,6 +65,7 @@ export class AptosResourcesContext extends BaseContext {
58
65
  this.network = network
59
66
  this.version = version
60
67
  this.timestampInMicros = timestampInMicros
68
+ this.coder = defaultMoveCoder(network)
61
69
  }
62
70
 
63
71
  getChainId(): string {
@@ -1,19 +1,14 @@
1
1
  import { Gauge } from '@sentio/sdk'
2
2
  import { BigDecimal } from '@sentio/bigdecimal'
3
3
  import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
4
- import {
5
- AptosResourcesContext,
6
- TypedMoveResource,
7
- MoveResource,
8
- defaultMoveCoder,
9
- AptosContext,
10
- } from '@sentio/sdk/aptos'
4
+ import { AptosResourcesContext, TypedMoveResource, MoveResource, AptosContext } from '@sentio/sdk/aptos'
5
+ import { TypeDescriptor } from '../../move/index.js'
11
6
 
12
7
  export interface PoolAdaptor<T> {
13
8
  getXReserve(pool: T): bigint
14
9
  getYReserve(pool: T): bigint
15
10
  getExtraPoolTags(pool: TypedMoveResource<T>): any
16
- poolTypeName: string
11
+ poolType: TypeDescriptor<T>
17
12
  }
18
13
 
19
14
  export class AptosDex<T> {
@@ -104,10 +99,7 @@ export class AptosDex<T> {
104
99
  ctx: AptosResourcesContext,
105
100
  poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void
106
101
  ) {
107
- const pools: TypedMoveResource<T>[] = defaultMoveCoder().filterAndDecodeResources(
108
- this.poolAdaptor.poolTypeName,
109
- resources
110
- )
102
+ const pools = await ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolType, resources)
111
103
 
112
104
  const volumeByCoin = new Map<string, BigDecimal>()
113
105
  const timestamp = ctx.timestampInMicros
@@ -8,3 +8,5 @@ export * from './api.js'
8
8
  export { ModuleClient } from './module-client.js'
9
9
 
10
10
  export { AptosPlugin } from './aptos-plugin.js'
11
+
12
+ export { BUILTIN_TYPES } from '../move/types.js'
@@ -1,17 +1,12 @@
1
1
  import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'
2
+ import { DecodedStruct } from '../move/types.js'
2
3
 
3
4
  export type EventInstance = Event & {
4
5
  version: string
5
6
  }
6
7
 
7
- export type TypedEventInstance<T> = EventInstance & {
8
- /**
9
- * decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
10
- */
11
- data_decoded: T
12
-
13
- type_arguments: string[]
14
- }
8
+ export type TypedEventInstance<T> = DecodedStruct<EventInstance, T>
9
+ export type TypedMoveResource<T> = DecodedStruct<MoveResource, T>
15
10
 
16
11
  // Don't use intermediate type to make IDE happier
17
12
  export type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
@@ -20,8 +15,3 @@ export type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_Entr
20
15
  */
21
16
  arguments_decoded: T
22
17
  }
23
-
24
- export type TypedMoveResource<T> = MoveResource & {
25
- data_decoded: T
26
- type_arguments: string[]
27
- }
@@ -17,7 +17,7 @@ export class ModuleClient {
17
17
  ledger_version?: bigint
18
18
  ): Promise<any[]> {
19
19
  const coder = defaultMoveCoder()
20
- const encodedArgs = coder.encodeCallArgs(args, func)
20
+ const encodedArgs = await coder.encodeCallArgs(args, func)
21
21
 
22
22
  const request: Types.ViewRequest = {
23
23
  function: func,
@@ -6,43 +6,62 @@ import {
6
6
  TransactionPayload_EntryFunctionPayload,
7
7
  } from './move-types.js'
8
8
 
9
- import { TypedEventInstance, TypedMoveResource, TypedFunctionPayload } from './models.js'
10
- import { getMeaningfulFunctionParams } from './utils.js'
9
+ import { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'
11
10
  import { AbstractMoveCoder } from '../move/abstract-move-coder.js'
12
- import { TypeDescriptor } from '../move/index.js'
11
+ import { AptosNetwork } from './network.js'
12
+ import { AptosChainAdapter } from './aptos-chain-adapter.js'
13
+ import { parseMoveType, TypeDescriptor } from '../move/index.js'
14
+
15
+ export class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
16
+ constructor(network: AptosNetwork) {
17
+ super(network)
18
+ this.adapter = new AptosChainAdapter()
19
+ }
13
20
 
14
- export class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
15
21
  load(module: MoveModuleBytecode) {
16
22
  if (!module.abi) {
17
23
  throw Error('Module without abi')
18
24
  }
19
- if (this.contains(module.abi.address, module.abi.name)) {
20
- return
25
+ let m = this.moduleMapping.get(module.abi.address + '::' + module.abi.name)
26
+ // if (this.contains(module.abi.address, module.abi.name)) {
27
+ // return
28
+ // }
29
+ if (m) {
30
+ return m
21
31
  }
22
- this.loadInternal(toInternalModule(module))
32
+ m = toInternalModule(module)
33
+ this.loadInternal(m)
34
+ return m
23
35
  }
24
36
 
25
- decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {
26
- return this.decodedStruct<T>(event) as TypedEventInstance<T>
37
+ decodeEvent<T>(event: Event): Promise<TypedEventInstance<T> | undefined> {
38
+ return this.decodedStruct<T>(event) as any
27
39
  }
28
- filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {
29
- return this.filterAndDecodeStruct(typeQname, resources) as TypedEventInstance<T>[]
40
+ filterAndDecodeEvents<T>(type: string | TypeDescriptor<T>, resources: Event[]): Promise<TypedEventInstance<T>[]> {
41
+ if (typeof type === 'string') {
42
+ type = parseMoveType(type)
43
+ }
44
+ return this.filterAndDecodeStruct(type, resources) as any
30
45
  }
31
- decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {
46
+ decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined> {
32
47
  return this.decodedStruct<T>(res)
33
48
  }
34
- filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {
35
- return this.filterAndDecodeStruct(typeQname, resources) as any
36
- }
37
-
38
- getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
39
- return getMeaningfulFunctionParams(params)
49
+ filterAndDecodeResources<T>(
50
+ type: string | TypeDescriptor<T>,
51
+ resources: MoveResource[]
52
+ ): Promise<TypedMoveResource<T>[]> {
53
+ if (typeof type === 'string') {
54
+ type = parseMoveType(type)
55
+ }
56
+ return this.filterAndDecodeStruct(type, resources)
40
57
  }
41
58
 
42
- decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {
43
- const func = this.getMoveFunction(payload.function)
44
- const params = getMeaningfulFunctionParams(func.params)
45
- const argumentsDecoded = this.decodeArray(payload.arguments, params)
59
+ async decodeFunctionPayload(
60
+ payload: TransactionPayload_EntryFunctionPayload
61
+ ): Promise<TransactionPayload_EntryFunctionPayload> {
62
+ const func = await this.getMoveFunction(payload.function)
63
+ const params = this.adapter.getMeaningfulFunctionParams(func.params)
64
+ const argumentsDecoded = await this.decodeArray(payload.arguments, params)
46
65
 
47
66
  return {
48
67
  ...payload,
@@ -51,8 +70,12 @@ export class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
51
70
  }
52
71
  }
53
72
 
54
- export const MOVE_CODER = new MoveCoder()
73
+ const MOVE_CODER = new MoveCoder(AptosNetwork.MAIN_NET)
74
+ const TESTNET_MOVE_CODER = new MoveCoder(AptosNetwork.TEST_NET)
55
75
 
56
- export function defaultMoveCoder(): MoveCoder {
57
- return MOVE_CODER
76
+ export function defaultMoveCoder(network: AptosNetwork = AptosNetwork.MAIN_NET): MoveCoder {
77
+ if (network == AptosNetwork.MAIN_NET) {
78
+ return MOVE_CODER
79
+ }
80
+ return TESTNET_MOVE_CODER
58
81
  }
@@ -30,6 +30,7 @@ export abstract class BaseProcessorTemplate<
30
30
  handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
31
31
  blockInterval?: HandleInterval
32
32
  timeIntervalInMinutes?: HandleInterval
33
+ fetchConfig?: EthFetchConfig
33
34
  }[] = []
34
35
  traceHandlers: {
35
36
  signature: string
@@ -64,7 +65,7 @@ export abstract class BaseProcessorTemplate<
64
65
  processor.onTrace(th.signature, th.handler, th.fetchConfig)
65
66
  }
66
67
  for (const bh of this.blockHandlers) {
67
- processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)
68
+ processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.fetchConfig)
68
69
  }
69
70
 
70
71
  const instance: TemplateInstance = {
@@ -103,32 +104,41 @@ export abstract class BaseProcessorTemplate<
103
104
  public onBlockInterval(
104
105
  handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
105
106
  blockInterval = 1000,
106
- backfillBlockInterval = 4000
107
+ backfillBlockInterval = 4000,
108
+ fetchConfig?: EthFetchConfig
107
109
  ) {
108
- return this.onInterval(handler, undefined, {
109
- recentInterval: blockInterval,
110
- backfillInterval: backfillBlockInterval,
111
- })
110
+ return this.onInterval(
111
+ handler,
112
+ undefined,
113
+ {
114
+ recentInterval: blockInterval,
115
+ backfillInterval: backfillBlockInterval,
116
+ },
117
+ fetchConfig
118
+ )
112
119
  }
113
120
 
114
121
  public onTimeInterval(
115
122
  handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
116
123
  timeIntervalInMinutes = 60,
117
- backfillBlockInterval = 240
124
+ backfillBlockInterval = 240,
125
+ fetchConfig?: EthFetchConfig
118
126
  ) {
119
127
  return this.onInterval(
120
128
  handler,
121
129
  { recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },
122
- undefined
130
+ undefined,
131
+ fetchConfig
123
132
  )
124
133
  }
125
134
 
126
135
  public onInterval(
127
136
  handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
128
137
  timeInterval: HandleInterval | undefined,
129
- blockInterval: HandleInterval | undefined
138
+ blockInterval: HandleInterval | undefined,
139
+ fetchConfig: EthFetchConfig | undefined
130
140
  ) {
131
- this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval })
141
+ this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval, fetchConfig })
132
142
  return this
133
143
  }
134
144
 
@@ -1,5 +1,5 @@
1
1
  import { BaseContract, DeferredTopicFilter, TransactionResponseParams } from 'ethers'
2
- import { BlockParams, Network } from 'ethers/providers'
2
+ import { Network } from 'ethers/providers'
3
3
 
4
4
  import { BoundContractView, ContractContext, ContractView, GlobalContext } from './context.js'
5
5
  import {
@@ -15,8 +15,7 @@ import {
15
15
  import { BindOptions } from './bind-options.js'
16
16
  import { PromiseOrVoid } from '../core/promises.js'
17
17
  import { ServerError, Status } from 'nice-grpc'
18
- import { fixEmptyKey, TypedEvent, TypedCallTrace, formatEthData } from './eth.js'
19
- import * as console from 'console'
18
+ import { fixEmptyKey, TypedEvent, TypedCallTrace, formatEthData, RichBlock } from './eth.js'
20
19
  import { getNetworkFromCtxOrNetworkish } from './provider.js'
21
20
  import sha3 from 'js-sha3'
22
21
  import { ListStateStorage } from '@sentio/runtime'
@@ -42,6 +41,7 @@ export class BlockHandler {
42
41
  blockInterval?: HandleInterval
43
42
  timeIntervalInMinutes?: HandleInterval
44
43
  handler: (block: Data_EthBlock) => Promise<ProcessResult>
44
+ fetchConfig: EthFetchConfig
45
45
  }
46
46
 
47
47
  export class TransactionHandler {
@@ -88,25 +88,33 @@ export class GlobalProcessor {
88
88
  }
89
89
 
90
90
  public onBlockInterval(
91
- handler: (block: BlockParams, ctx: GlobalContext) => PromiseOrVoid,
91
+ handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
92
92
  blockInterval = 250,
93
- backfillBlockInterval = 1000
93
+ backfillBlockInterval = 1000,
94
+ fetchConfig?: Partial<EthFetchConfig>
94
95
  ): this {
95
- return this.onInterval(handler, undefined, {
96
- recentInterval: blockInterval,
97
- backfillInterval: backfillBlockInterval,
98
- })
96
+ return this.onInterval(
97
+ handler,
98
+ undefined,
99
+ {
100
+ recentInterval: blockInterval,
101
+ backfillInterval: backfillBlockInterval,
102
+ },
103
+ fetchConfig
104
+ )
99
105
  }
100
106
 
101
107
  public onTimeInterval(
102
- handler: (block: BlockParams, ctx: GlobalContext) => PromiseOrVoid,
108
+ handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
103
109
  timeIntervalInMinutes = 60,
104
- backfillTimeIntervalInMinutes = 240
110
+ backfillTimeIntervalInMinutes = 240,
111
+ fetchConfig?: Partial<EthFetchConfig>
105
112
  ): this {
106
113
  return this.onInterval(
107
114
  handler,
108
115
  { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
109
- undefined
116
+ undefined,
117
+ fetchConfig
110
118
  )
111
119
  }
112
120
 
@@ -115,9 +123,10 @@ export class GlobalProcessor {
115
123
  }
116
124
 
117
125
  public onInterval(
118
- handler: (block: BlockParams, ctx: GlobalContext) => PromiseOrVoid,
126
+ handler: (block: RichBlock, ctx: GlobalContext) => PromiseOrVoid,
119
127
  timeInterval: HandleInterval | undefined,
120
- blockInterval: HandleInterval | undefined
128
+ blockInterval: HandleInterval | undefined,
129
+ fetchConfig: Partial<EthFetchConfig> | undefined
121
130
  ): this {
122
131
  const chainId = this.getChainId()
123
132
 
@@ -135,6 +144,7 @@ export class GlobalProcessor {
135
144
  },
136
145
  timeIntervalInMinutes: timeInterval,
137
146
  blockInterval: blockInterval,
147
+ fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
138
148
  })
139
149
  return this
140
150
  }
@@ -245,32 +255,41 @@ export abstract class BaseProcessor<
245
255
  }
246
256
 
247
257
  public onBlockInterval(
248
- handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
258
+ handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
249
259
  blockInterval = 250,
250
- backfillBlockInterval = 1000
260
+ backfillBlockInterval = 1000,
261
+ fetchConfig?: Partial<EthFetchConfig>
251
262
  ): this {
252
- return this.onInterval(handler, undefined, {
253
- recentInterval: blockInterval,
254
- backfillInterval: backfillBlockInterval,
255
- })
263
+ return this.onInterval(
264
+ handler,
265
+ undefined,
266
+ {
267
+ recentInterval: blockInterval,
268
+ backfillInterval: backfillBlockInterval,
269
+ },
270
+ fetchConfig
271
+ )
256
272
  }
257
273
 
258
274
  public onTimeInterval(
259
- handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
275
+ handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
260
276
  timeIntervalInMinutes = 60,
261
- backfillTimeIntervalInMinutes = 240
277
+ backfillTimeIntervalInMinutes = 240,
278
+ fetchConfig?: Partial<EthFetchConfig>
262
279
  ): this {
263
280
  return this.onInterval(
264
281
  handler,
265
282
  { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },
266
- undefined
283
+ undefined,
284
+ fetchConfig
267
285
  )
268
286
  }
269
287
 
270
288
  public onInterval(
271
- handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
289
+ handler: (block: RichBlock, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
272
290
  timeInterval: HandleInterval | undefined,
273
- blockInterval: HandleInterval | undefined
291
+ blockInterval: HandleInterval | undefined,
292
+ fetchConfig: Partial<EthFetchConfig> | undefined
274
293
  ): this {
275
294
  const chainId = this.getChainId()
276
295
  const processor = this
@@ -300,6 +319,7 @@ export abstract class BaseProcessor<
300
319
  },
301
320
  timeIntervalInMinutes: timeInterval,
302
321
  blockInterval: blockInterval,
322
+ fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
303
323
  })
304
324
  return this
305
325
  }
@@ -62,6 +62,7 @@ export class EthPlugin extends Plugin {
62
62
  minutes: 0,
63
63
  minutesInterval: blockHandler.timeIntervalInMinutes,
64
64
  handlerId: handlerId,
65
+ fetchConfig: blockHandler.fetchConfig,
65
66
  })
66
67
  }
67
68
 
@@ -140,6 +141,7 @@ export class EthPlugin extends Plugin {
140
141
  minutes: 0,
141
142
  minutesInterval: blockHandler.timeIntervalInMinutes,
142
143
  handlerId: handlerId,
144
+ fetchConfig: blockHandler.fetchConfig,
143
145
  })
144
146
  }
145
147
 
package/src/eth/eth.ts CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  object,
12
12
  formatData,
13
13
  } from 'ethers/providers'
14
- import { CallExceptionError, LogDescription, Result, DeferredTopicFilter } from 'ethers'
14
+ import { CallExceptionError, LogDescription, Result, DeferredTopicFilter, BlockParams } from 'ethers'
15
15
  import { ContractContext } from './context.js'
16
16
  import { getAddress } from 'ethers/address'
17
17
  import { getBigInt, getNumber, hexlify } from 'ethers/utils'
@@ -34,6 +34,11 @@ export interface TypedEvent<TArgsArray extends Array<any> = any, TArgsObject = a
34
34
 
35
35
  export type TypedEventFilter<_TEvent extends TypedEvent> = DeferredTopicFilter
36
36
 
37
+ export interface RichBlock extends BlockParams {
38
+ traces?: Trace[]
39
+ transactionReceipts?: TransactionReceiptParams[]
40
+ }
41
+
37
42
  export class SimpleEthersError extends Error {
38
43
  e: Error
39
44
 
@@ -132,7 +137,7 @@ export function formatEthData(data: {
132
137
  if (data.block && !data.block.transactions) {
133
138
  data.block.transactions = []
134
139
  }
135
- const block = data.block ? formatBlock(data.block) : undefined
140
+ const block = data.block ? formatRichBlock(data.block) : undefined
136
141
  const trace = data.trace ? (data.trace as Trace) : undefined
137
142
  const transaction = data.transaction ? formatTransactionResponse(data.transaction) : undefined
138
143
  const transactionReceipt = data.transactionReceipt ? formatTransactionReceipt(data.transactionReceipt) : undefined
@@ -145,6 +150,14 @@ export function formatEthData(data: {
145
150
  }
146
151
  }
147
152
 
153
+ export function formatRichBlock(block: RichBlock): RichBlock {
154
+ formatBlock(block)
155
+ if (block.transactionReceipts) {
156
+ block.transactionReceipts = block.transactionReceipts.map((t) => formatTransactionReceipt(t))
157
+ }
158
+ return block
159
+ }
160
+
148
161
  export interface TypedCallTrace<TArgsArray extends Array<any> = any, TArgsObject = any> extends Trace {
149
162
  args: TArgsObject & IResult
150
163
  name: string