@sentio/sdk 1.26.3 → 1.27.0

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 (52) hide show
  1. package/lib/aptos/aptos-processor.d.ts +1 -1
  2. package/lib/aptos/aptos-processor.js +2 -2
  3. package/lib/aptos/aptos-processor.js.map +1 -1
  4. package/lib/aptos/index.d.ts +1 -1
  5. package/lib/aptos/index.js +2 -1
  6. package/lib/aptos/index.js.map +1 -1
  7. package/lib/aptos-codegen/codegen.js +37 -15
  8. package/lib/aptos-codegen/codegen.js.map +1 -1
  9. package/lib/builtin/aptos/0x1.d.ts +89 -84
  10. package/lib/builtin/aptos/0x1.js +257 -251
  11. package/lib/builtin/aptos/0x1.js.map +1 -1
  12. package/lib/builtin/aptos/0x3.d.ts +8 -8
  13. package/lib/builtin/aptos/0x3.js +35 -35
  14. package/lib/builtin/aptos/0x3.js.map +1 -1
  15. package/lib/cli/cli.js +3 -3
  16. package/lib/cli/cli.js.map +1 -1
  17. package/lib/cli/commands/login-server.d.ts +7 -0
  18. package/lib/cli/commands/login-server.js +134 -0
  19. package/lib/cli/commands/login-server.js.map +1 -0
  20. package/lib/cli/commands/run-login.js +77 -27
  21. package/lib/cli/commands/run-login.js.map +1 -1
  22. package/lib/cli/config.d.ts +5 -0
  23. package/lib/cli/config.js +28 -1
  24. package/lib/cli/config.js.map +1 -1
  25. package/lib/core/exporter.d.ts +4 -9
  26. package/lib/core/exporter.js +8 -8
  27. package/lib/core/exporter.js.map +1 -1
  28. package/lib/gen/processor/protos/processor.d.ts +2 -9
  29. package/lib/gen/processor/protos/processor.js +15 -54
  30. package/lib/gen/processor/protos/processor.js.map +1 -1
  31. package/lib/service.js +2 -3
  32. package/lib/service.js.map +1 -1
  33. package/lib/tests/erc20.js +1 -5
  34. package/lib/tests/erc20.js.map +1 -1
  35. package/lib/tests/types/aptos/souffle.d.ts +2 -2
  36. package/lib/tests/types/aptos/souffle.js +12 -12
  37. package/lib/tests/types/aptos/souffle.js.map +1 -1
  38. package/package.json +7 -2
  39. package/src/aptos/aptos-processor.ts +2 -2
  40. package/src/aptos/index.ts +1 -1
  41. package/src/aptos-codegen/codegen.ts +43 -17
  42. package/src/builtin/aptos/0x1.ts +301 -283
  43. package/src/builtin/aptos/0x3.ts +47 -47
  44. package/src/cli/cli.ts +3 -3
  45. package/src/cli/commands/login-server.ts +120 -0
  46. package/src/cli/commands/run-login.ts +59 -28
  47. package/src/cli/config.ts +29 -0
  48. package/src/core/exporter.ts +9 -14
  49. package/src/gen/processor/protos/processor.ts +15 -59
  50. package/src/service.ts +2 -3
  51. package/src/tests/erc20.ts +1 -5
  52. package/src/tests/types/aptos/souffle.ts +12 -12
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "1.26.3",
4
+ "version": "1.27.0",
5
5
  "scripts": {
6
6
  "compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
7
7
  "compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli && cp src/utils/*.csv lib/utils",
@@ -25,6 +25,7 @@
25
25
  "@solana/web3.js": "^1.47.3",
26
26
  "@typechain/ethers-v5": "^10.0.0",
27
27
  "@types/bn.js": "^5.1.0",
28
+ "@types/express": "^4.17.14",
28
29
  "@types/node-fetch": "^2.6.2",
29
30
  "aptos-sdk": "npm:aptos@^1.3.16",
30
31
  "bignumber.js": "^9.1.0",
@@ -34,6 +35,7 @@
34
35
  "command-line-usage": "^6.1.3",
35
36
  "csv-parse": "^5.3.0",
36
37
  "ethers": "~5.7.1",
38
+ "express": "^4.18.2",
37
39
  "form-data": "^4.0.0",
38
40
  "fs-extra": "^10.1.0",
39
41
  "google-protobuf": "^3.15.8",
@@ -78,5 +80,8 @@
78
80
  "lib/**/*",
79
81
  "src/**/*",
80
82
  "templates/**/*"
81
- ]
83
+ ],
84
+ "engines": {
85
+ "node": ">=16"
86
+ }
82
87
  }
@@ -251,9 +251,9 @@ export class AptosAccountProcessor {
251
251
  public onTimeInterval(
252
252
  handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
253
253
  timeIntervalInMinutes = 60,
254
- typpe?: string
254
+ type?: string
255
255
  ) {
256
- return this.onInterval(handler, timeIntervalInMinutes, undefined, typpe)
256
+ return this.onInterval(handler, timeIntervalInMinutes, undefined, type)
257
257
  }
258
258
 
259
259
  public onVersionInterval(
@@ -3,5 +3,5 @@ export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload } fro
3
3
  export { TYPE_REGISTRY, TypeRegistry } from './types'
4
4
  export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'
5
5
  export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor'
6
- export { AptosContext } from './context'
6
+ export { AptosContext, AptosResourceContext } from './context'
7
7
  export { AptosBindOptions, AptosNetwork, getRpcClient } from './network'
@@ -2,8 +2,8 @@ import fs from 'fs'
2
2
  import path from 'path'
3
3
  import prettier from 'prettier'
4
4
  import { MoveFunction, MoveModule, MoveModuleBytecode, MoveStruct } from 'aptos-sdk/src/generated'
5
- import { AccountModulesImportInfo, AccountRegister, generateType } from './typegen'
6
- import { isFrameworkAccount } from '../aptos/utils'
5
+ import { AccountModulesImportInfo, AccountRegister, generateType, parseMoveType } from './typegen'
6
+ import { isFrameworkAccount, moduleQname, SPLITTER } from '../aptos/utils'
7
7
  import chalk from 'chalk'
8
8
  import { AptosNetwork, getChainName, getRpcClient } from '../aptos/network'
9
9
 
@@ -56,7 +56,7 @@ export async function generateForNetwork(srcDir: string, outputDir: string, netw
56
56
 
57
57
  while (loader.pendingAccounts.size > 0) {
58
58
  for (const account of loader.pendingAccounts) {
59
- console.log(`download depended module for account ${account} at ${getChainName(network)}`)
59
+ console.log(`download dependent module for account ${account} at ${getChainName(network)}`)
60
60
 
61
61
  try {
62
62
  const modules = await client.getAccountModules(account)
@@ -176,12 +176,12 @@ export class AccountCodegen {
176
176
 
177
177
  ${this.modules.map((m) => generateModule(m, this.config.network)).join('\n')}
178
178
 
179
- function loadAllTypes(registry: aptos.TypeRegistry) {
180
- ${dependedAccounts.map((m) => `${m}.loadTypes(registry)`).join('\n')}
179
+ function loadAllTypes(_r: aptos.TypeRegistry) {
180
+ ${dependedAccounts.map((m) => `${m}.loadTypes(_r)`).join('\n')}
181
181
 
182
182
  ${this.modules
183
183
  .map((m) => {
184
- return `registry.load(${m.abi?.name}.ABI)`
184
+ return `_r.load(${m.abi?.name}.ABI)`
185
185
  })
186
186
  .join('\n')}
187
187
  }
@@ -211,8 +211,13 @@ function generateModule(moduleByteCode: MoveModuleBytecode, network: AptosNetwor
211
211
  const module = moduleByteCode.abi
212
212
 
213
213
  const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')
214
- const events = module.structs.map((e) => generateOnEvents(module, e)).filter((s) => s !== '')
215
- const structs = module.structs.map((s) => generateStructs(module, s))
214
+
215
+ const eventStructs = getEventStructs(module)
216
+ const eventTypes = new Set(eventStructs.keys())
217
+ const events = Array.from(eventStructs.values())
218
+ .map((e) => generateOnEvents(module, e))
219
+ .filter((s) => s !== '')
220
+ const structs = module.structs.map((s) => generateStructs(module, s, eventTypes))
216
221
  const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f))
217
222
 
218
223
  let processor = ''
@@ -250,15 +255,15 @@ function generateModule(moduleByteCode: MoveModuleBytecode, network: AptosNetwor
250
255
 
251
256
  ${callArgs.join('\n')}
252
257
 
253
- export function loadTypes(registry: aptos.TypeRegistry) {
254
- loadAllTypes(registry)
258
+ export function loadTypes(_r: aptos.TypeRegistry) {
259
+ loadAllTypes(_r)
255
260
  }
256
261
  export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')
257
262
  }
258
263
  `
259
264
  }
260
265
 
261
- function generateStructs(module: MoveModule, struct: MoveStruct) {
266
+ function generateStructs(module: MoveModule, struct: MoveStruct, events: Set<string>) {
262
267
  const genericString = generateStructTypeParameters(struct)
263
268
  const genericStringAny = generateStructTypeParameters(struct, true)
264
269
 
@@ -267,7 +272,7 @@ function generateStructs(module: MoveModule, struct: MoveStruct) {
267
272
  })
268
273
 
269
274
  let eventPayload = ''
270
- if (isEvent(struct)) {
275
+ if (events.has(moduleQname(module) + SPLITTER + struct.name)) {
271
276
  eventPayload = `
272
277
  export interface ${struct.name}Instance extends
273
278
  aptos.TypedEventInstance<${struct.name}${genericStringAny}> {
@@ -357,15 +362,36 @@ function generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {
357
362
  return source
358
363
  }
359
364
 
360
- function isEvent(struct: MoveStruct) {
361
- return struct.abilities.includes('drop') && struct.abilities.includes('store') && struct.name.endsWith('Event')
365
+ function getEventStructs(module: MoveModule) {
366
+ const qname = moduleQname(module)
367
+ const structMap = new Map<string, MoveStruct>()
368
+ const eventMap = new Map<string, MoveStruct>()
369
+
370
+ for (const struct of module.structs) {
371
+ structMap.set(qname + SPLITTER + struct.name, struct)
372
+ }
373
+
374
+ for (const struct of module.structs) {
375
+ for (const field of struct.fields) {
376
+ const t = parseMoveType(field.type)
377
+ if (t.qname === '0x1::event::EventHandle') {
378
+ const event = t.typeArgs[0].qname
379
+ const eventStruct = structMap.get(event)
380
+ if (eventStruct) {
381
+ eventMap.set(event, eventStruct)
382
+ }
383
+ }
384
+ }
385
+ }
386
+
387
+ return eventMap
362
388
  }
363
389
 
364
390
  function generateOnEvents(module: MoveModule, struct: MoveStruct): string {
365
391
  // for struct that has drop + store
366
- if (!isEvent(struct)) {
367
- return ''
368
- }
392
+ // if (!isEvent(struct, module)) {
393
+ // return ''
394
+ // }
369
395
 
370
396
  // const genericString = generateStructTypeParameters(struct)
371
397