@sentio/sdk 1.22.3 → 1.23.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 (47) hide show
  1. package/lib/aptos/aptos-processor.js +3 -3
  2. package/lib/aptos/aptos-processor.js.map +1 -1
  3. package/lib/aptos/context.js +2 -2
  4. package/lib/aptos/context.js.map +1 -1
  5. package/lib/aptos/index.d.ts +2 -2
  6. package/lib/aptos/index.js +3 -3
  7. package/lib/aptos/index.js.map +1 -1
  8. package/lib/aptos/{bind-options.d.ts → network.d.ts} +2 -0
  9. package/lib/aptos/{bind-options.js → network.js} +18 -2
  10. package/lib/aptos/network.js.map +1 -0
  11. package/lib/aptos/runtime.d.ts +1 -1
  12. package/lib/aptos/runtime.js.map +1 -1
  13. package/lib/aptos/types.d.ts +1 -1
  14. package/lib/aptos/types.js.map +1 -1
  15. package/lib/aptos/utils.d.ts +1 -1
  16. package/lib/aptos/utils.js.map +1 -1
  17. package/lib/aptos-codegen/codegen.d.ts +12 -5
  18. package/lib/aptos-codegen/codegen.js +81 -36
  19. package/lib/aptos-codegen/codegen.js.map +1 -1
  20. package/lib/aptos-codegen/typegen.d.ts +1 -1
  21. package/lib/aptos-codegen/typegen.js.map +1 -1
  22. package/lib/builtin/aptos/0x1.d.ts +1 -1
  23. package/lib/builtin/aptos/0x1.js +16 -16
  24. package/lib/builtin/aptos/0x1.js.map +1 -1
  25. package/lib/builtin/aptos/0x3.d.ts +1 -1
  26. package/lib/builtin/aptos/0x3.js +3 -3
  27. package/lib/builtin/aptos/0x3.js.map +1 -1
  28. package/lib/cli/webpack.config.js +2 -1
  29. package/lib/tests/types/aptos/souffle.d.ts +1 -1
  30. package/lib/tests/types/aptos/souffle.js +2 -2
  31. package/lib/tests/types/aptos/souffle.js.map +1 -1
  32. package/package.json +2 -2
  33. package/src/aptos/aptos-processor.ts +2 -2
  34. package/src/aptos/context.ts +1 -1
  35. package/src/aptos/index.ts +2 -2
  36. package/src/aptos/network.ts +39 -0
  37. package/src/aptos/runtime.ts +1 -1
  38. package/src/aptos/types.ts +1 -1
  39. package/src/aptos/utils.ts +1 -1
  40. package/src/aptos-codegen/codegen.ts +97 -39
  41. package/src/aptos-codegen/typegen.ts +1 -1
  42. package/src/builtin/aptos/0x1.ts +17 -17
  43. package/src/builtin/aptos/0x3.ts +4 -4
  44. package/src/cli/webpack.config.js +2 -1
  45. package/src/tests/types/aptos/souffle.ts +3 -3
  46. package/lib/aptos/bind-options.js.map +0 -1
  47. package/src/aptos/bind-options.ts +0 -23
@@ -8,7 +8,7 @@ const _1 = require(".");
8
8
  const long_1 = __importDefault(require("long"));
9
9
  const types_1 = require("./types");
10
10
  const typegen_1 = require("../aptos-codegen/typegen");
11
- const bind_options_1 = require("./bind-options");
11
+ const network_1 = require("./network");
12
12
  class EventHandler {
13
13
  filters;
14
14
  handler;
@@ -122,11 +122,11 @@ class AptosBaseProcessor {
122
122
  this.config = {
123
123
  startVersion: startVersion,
124
124
  address: options.address,
125
- network: options.network || _1.AptosNetwork.TEST_NET,
125
+ network: options.network || _1.AptosNetwork.MAIN_NET,
126
126
  };
127
127
  }
128
128
  getChainId() {
129
- return (0, bind_options_1.getChainId)(this.config.network);
129
+ return (0, network_1.getChainId)(this.config.network);
130
130
  }
131
131
  loadTypes(registry) {
132
132
  if (registry.contains(this.config.address, this.moduleName)) {
@@ -1 +1 @@
1
- {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,wBASU;AAEV,gDAAuB;AACvB,mCAA6D;AAC7D,sDAAwD;AACxD,iDAA2C;AA6B3C,MAAM,YAAY;IAChB,OAAO,CAAe;IACtB,OAAO,CAAgE;CACxE;AAED,MAAM,WAAW;IACf,OAAO,CAA6B;IACpC,OAAO,CAA+D;CACvE;AAED,MAAa,kBAAkB;IACpB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IACtB,aAAa,GAAmB,EAAE,CAA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AAO,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE;gBACpD,sGAAsG;gBACtG,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBACnD,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;aACnD;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;YAC7D,OAAO,OAAO,CAAA;SACf;QAED,OAAO,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAoC,CAAA;IAC1F,CAAC;CACF;AA5MD,gDA4MC","sourcesContent":["import { ProcessResult } from '../gen'\nimport {\n AptosBindOptions,\n AptosContext,\n AptosNetwork,\n Transaction_UserTransaction,\n TransactionPayload_EntryFunctionPayload,\n TypedEntryFunctionPayload,\n TypedEventInstance,\n TypeRegistry,\n} from '.'\n\nimport Long from 'long'\nimport { EventInstance, GLOBAL_TYPE_REGISTRY } from './types'\nimport { parseMoveType } from '../aptos-codegen/typegen'\nimport { getChainId } from './bind-options'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: Long\n // endSeqNumber?: Long\n}\n\n// TODO extends ArgumentsFilter\nexport interface EventFilter {\n type: string\n account?: string\n}\n\nexport interface FunctionNameAndCallFilter extends CallFilter {\n function: string\n}\n\n// TODO extends ArgumentsFilter\nexport interface CallFilter {\n includeFailed?: boolean\n typeArguments?: string[]\n}\n\nexport interface ArgumentsFilter {\n arguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: FunctionNameAndCallFilter[]\n handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler[] = []\n callHandlers: CallHandler[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.configure(options)\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void\n ): AptosBaseProcessor {\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(tx.version),\n tx\n )\n if (tx) {\n handler(tx, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: [],\n })\n return this\n }\n\n public onEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[]\n ): AptosBaseProcessor {\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.eventHandlers.push({\n handler: async function (txn) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(txn.version),\n txn\n )\n if (txn && txn.events) {\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const decoded = processor.decodeEvent(evt as EventInstance)\n handler(decoded, ctx)\n }\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[]\n ): AptosBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(tx.version),\n tx\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = processor.decodeFunctionPayload(payload)\n handler(decoded, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n return this\n }\n\n private configure(options: AptosBindOptions) {\n let startVersion = Long.ZERO\n if (options.startVersion) {\n startVersion = Long.fromValue(options.startVersion)\n }\n\n this.config = {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.TEST_NET,\n }\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: TypeRegistry) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: TypeRegistry) {\n // should be override by subclass\n }\n\n private decodeEvent(event: EventInstance): EventInstance {\n const registry = GLOBAL_TYPE_REGISTRY\n this.loadTypes(registry)\n // TODO check if module is not loaded\n\n const typeDescriptor = parseMoveType(event.type)\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n // TODO check move structure's type param match type args, also maybe\n // use type arguments for decoding\n\n let dataTyped = undefined\n try {\n dataTyped = registry.decode(event.data, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(event))\n return event\n }\n\n return { ...event, data_typed: dataTyped, type_arguments: typeArguments } as TypedEventInstance<any>\n }\n\n private decodeFunctionPayload(\n payload: TransactionPayload_EntryFunctionPayload\n ): TransactionPayload_EntryFunctionPayload {\n const registry = GLOBAL_TYPE_REGISTRY\n this.loadTypes(registry)\n const argumentsTyped: any[] = []\n\n try {\n const func = registry.getMoveFunction(payload.function)\n for (const [idx, arg] of payload.arguments.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = parseMoveType(func.params[idx + 1])\n argumentsTyped.push(registry.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload))\n return payload\n }\n\n return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>\n }\n}\n"]}
1
+ {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,wBASU;AAEV,gDAAuB;AACvB,mCAA6D;AAC7D,sDAAwD;AACxD,uCAAsC;AA6BtC,MAAM,YAAY;IAChB,OAAO,CAAe;IACtB,OAAO,CAAgE;CACxE;AAED,MAAM,WAAW;IACf,OAAO,CAA6B;IACpC,OAAO,CAA+D;CACvE;AAED,MAAa,kBAAkB;IACpB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IACtB,aAAa,GAAmB,EAAE,CAAA;IAClC,YAAY,GAAkB,EAAE,CAAA;IAEhC,YAAY,UAAkB,EAAE,OAAyB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QACvB,MAAM,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,qCAAqC;IACrC,qBAAqB;IACrB,IAAI;IAEG,aAAa,CAClB,OAA8E;QAE9E,sCAAsC;QACtC,qCAAqC;QACrC,4DAA4D;QAC5D,MAAM,SAAS,GAAG,IAAI,CAAA;QACtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YACrB,OAAO,EAAE,KAAK,WAAW,EAAE;gBACzB,MAAM,GAAG,GAAG,IAAI,eAAY,CAC1B,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,MAAM,CAAC,OAAO,EACx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ptosNetwork,\n Transaction_UserTransaction,\n TransactionPayload_EntryFunctionPayload,\n TypedEntryFunctionPayload,\n TypedEventInstance,\n TypeRegistry,\n} from '.'\n\nimport Long from 'long'\nimport { EventInstance, GLOBAL_TYPE_REGISTRY } from './types'\nimport { parseMoveType } from '../aptos-codegen/typegen'\nimport { getChainId } from './network'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: Long\n // endSeqNumber?: Long\n}\n\n// TODO extends ArgumentsFilter\nexport interface EventFilter {\n type: string\n account?: string\n}\n\nexport interface FunctionNameAndCallFilter extends CallFilter {\n function: string\n}\n\n// TODO extends ArgumentsFilter\nexport interface CallFilter {\n includeFailed?: boolean\n typeArguments?: string[]\n}\n\nexport interface ArgumentsFilter {\n arguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: FunctionNameAndCallFilter[]\n handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler[] = []\n callHandlers: CallHandler[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.configure(options)\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void\n ): AptosBaseProcessor {\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(tx.version),\n tx\n )\n if (tx) {\n handler(tx, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: [],\n })\n return this\n }\n\n public onEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[]\n ): AptosBaseProcessor {\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.eventHandlers.push({\n handler: async function (txn) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(txn.version),\n txn\n )\n if (txn && txn.events) {\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const decoded = processor.decodeEvent(evt as EventInstance)\n handler(decoded, ctx)\n }\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[]\n ): AptosBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const processor = this\n\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n Long.fromString(tx.version),\n tx\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = processor.decodeFunctionPayload(payload)\n handler(decoded, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n return this\n }\n\n private configure(options: AptosBindOptions) {\n let startVersion = Long.ZERO\n if (options.startVersion) {\n startVersion = Long.fromValue(options.startVersion)\n }\n\n this.config = {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: TypeRegistry) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: TypeRegistry) {\n // should be override by subclass\n }\n\n private decodeEvent(event: EventInstance): EventInstance {\n const registry = GLOBAL_TYPE_REGISTRY\n this.loadTypes(registry)\n // TODO check if module is not loaded\n\n const typeDescriptor = parseMoveType(event.type)\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n // TODO check move structure's type param match type args, also maybe\n // use type arguments for decoding\n\n let dataTyped = undefined\n try {\n dataTyped = registry.decode(event.data, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(event))\n return event\n }\n\n return { ...event, data_typed: dataTyped, type_arguments: typeArguments } as TypedEventInstance<any>\n }\n\n private decodeFunctionPayload(\n payload: TransactionPayload_EntryFunctionPayload\n ): TransactionPayload_EntryFunctionPayload {\n const registry = GLOBAL_TYPE_REGISTRY\n this.loadTypes(registry)\n const argumentsTyped: any[] = []\n\n try {\n const func = registry.getMoveFunction(payload.function)\n for (const [idx, arg] of payload.arguments.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = parseMoveType(func.params[idx + 1])\n argumentsTyped.push(registry.decode(arg, argType))\n }\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(payload))\n return payload\n }\n\n return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>\n }\n}\n"]}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AptosContext = void 0;
4
4
  const meter_1 = require("../core/meter");
5
5
  const context_1 = require("../core/context");
6
- const bind_options_1 = require("./bind-options");
6
+ const network_1 = require("./network");
7
7
  class AptosContext extends context_1.BaseContext {
8
8
  address;
9
9
  network;
@@ -28,7 +28,7 @@ class AptosContext extends context_1.BaseContext {
28
28
  transactionIndex: 0,
29
29
  transactionHash: this.transaction?.hash || '',
30
30
  logIndex: 0,
31
- chainId: (0, bind_options_1.getChainId)(this.network),
31
+ chainId: (0, network_1.getChainId)(this.network),
32
32
  dataDescriptor: descriptor,
33
33
  labels: (0, meter_1.normalizeLabels)(labels),
34
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";;;AAGA,yCAA+C;AAC/C,6CAA6C;AAE7C,iDAA2C;AAE3C,MAAa,YAAa,SAAQ,qBAAW;IAC3C,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,UAAU,CAAQ;IAClB,OAAO,CAAM;IACb,WAAW,CAA6B;IAExC,YACE,UAAkB,EAClB,OAAqB,EACrB,OAAe,EACf,OAAa,EACb,WAAyC;QAEzC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,WAAW,CAAC,UAAsC,EAAE,MAAc;QAChE,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;YAC7C,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAA,yBAAU,EAAC,IAAI,CAAC,OAAO,CAAC;YACjC,cAAc,EAAE,UAAU;YAC1B,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AArCD,oCAqCC","sourcesContent":["import Long from 'long'\nimport { DataDescriptor, RecordMetaData } from '../gen'\nimport { Labels } from '../core/metadata'\nimport { normalizeLabels } from '../core/meter'\nimport { BaseContext } from '../core/context'\nimport { AptosNetwork, Transaction_UserTransaction } from './'\nimport { getChainId } from './bind-options'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: Long\n transaction: Transaction_UserTransaction\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: Long,\n transaction?: Transaction_UserTransaction\n ) {\n super()\n this.address = address\n this.network = network\n this.moduleName = moduleName\n this.version = version\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: getChainId(this.network),\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";;;AAGA,yCAA+C;AAC/C,6CAA6C;AAE7C,uCAAsC;AAEtC,MAAa,YAAa,SAAQ,qBAAW;IAC3C,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,UAAU,CAAQ;IAClB,OAAO,CAAM;IACb,WAAW,CAA6B;IAExC,YACE,UAAkB,EAClB,OAAqB,EACrB,OAAe,EACf,OAAa,EACb,WAAyC;QAEzC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,WAAW,CAAC,UAAsC,EAAE,MAAc;QAChE,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;YAC7C,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAA,oBAAU,EAAC,IAAI,CAAC,OAAO,CAAC;YACjC,cAAc,EAAE,UAAU;YAC1B,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AArCD,oCAqCC","sourcesContent":["import Long from 'long'\nimport { DataDescriptor, RecordMetaData } from '../gen'\nimport { Labels } from '../core/metadata'\nimport { normalizeLabels } from '../core/meter'\nimport { BaseContext } from '../core/context'\nimport { AptosNetwork, Transaction_UserTransaction } from './'\nimport { getChainId } from './network'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: Long\n transaction: Transaction_UserTransaction\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: Long,\n transaction?: Transaction_UserTransaction\n ) {\n super()\n this.address = address\n this.network = network\n this.moduleName = moduleName\n this.version = version\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: getChainId(this.network),\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
- export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos/src/generated';
1
+ export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated';
2
2
  export type { EventInstance, TypedEventInstance, TypeRegistry, TypedEntryFunctionPayload } from './types';
3
3
  export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor';
4
4
  export { AptosBaseProcessor } from './aptos-processor';
5
5
  export { AptosContext } from './context';
6
- export { AptosBindOptions, AptosNetwork } from './bind-options';
6
+ export { AptosBindOptions, AptosNetwork } from './network';
@@ -5,7 +5,7 @@ var aptos_processor_1 = require("./aptos-processor");
5
5
  Object.defineProperty(exports, "AptosBaseProcessor", { enumerable: true, get: function () { return aptos_processor_1.AptosBaseProcessor; } });
6
6
  var context_1 = require("./context");
7
7
  Object.defineProperty(exports, "AptosContext", { enumerable: true, get: function () { return context_1.AptosContext; } });
8
- var bind_options_1 = require("./bind-options");
9
- Object.defineProperty(exports, "AptosBindOptions", { enumerable: true, get: function () { return bind_options_1.AptosBindOptions; } });
10
- Object.defineProperty(exports, "AptosNetwork", { enumerable: true, get: function () { return bind_options_1.AptosNetwork; } });
8
+ var network_1 = require("./network");
9
+ Object.defineProperty(exports, "AptosBindOptions", { enumerable: true, get: function () { return network_1.AptosBindOptions; } });
10
+ Object.defineProperty(exports, "AptosNetwork", { enumerable: true, get: function () { return network_1.AptosNetwork; } });
11
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;AAGA,qDAAsD;AAA7C,qHAAA,kBAAkB,OAAA;AAC3B,qCAAwC;AAA/B,uGAAA,YAAY,OAAA;AACrB,+CAA+D;AAAtD,gHAAA,gBAAgB,OAAA;AAAE,4GAAA,YAAY,OAAA","sourcesContent":["export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos/src/generated'\nexport type { EventInstance, TypedEventInstance, TypeRegistry, TypedEntryFunctionPayload } from './types'\nexport type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'\nexport { AptosBaseProcessor } from './aptos-processor'\nexport { AptosContext } from './context'\nexport { AptosBindOptions, AptosNetwork } from './bind-options'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;AAGA,qDAAsD;AAA7C,qHAAA,kBAAkB,OAAA;AAC3B,qCAAwC;AAA/B,uGAAA,YAAY,OAAA;AACrB,qCAA0D;AAAjD,2GAAA,gBAAgB,OAAA;AAAE,uGAAA,YAAY,OAAA","sourcesContent":["export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated'\nexport type { EventInstance, TypedEventInstance, TypeRegistry, TypedEntryFunctionPayload } from './types'\nexport type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'\nexport { AptosBaseProcessor } from './aptos-processor'\nexport { AptosContext } from './context'\nexport { AptosBindOptions, AptosNetwork } from './network'\n"]}
@@ -4,6 +4,8 @@ export declare enum AptosNetwork {
4
4
  TEST_NET = 2
5
5
  }
6
6
  export declare function getChainId(network: AptosNetwork): string;
7
+ export declare function getChainName(network: AptosNetwork): string;
8
+ export declare function getChainRpcEndpoint(network: AptosNetwork): string;
7
9
  export declare class AptosBindOptions {
8
10
  address: string;
9
11
  network?: AptosNetwork;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AptosBindOptions = exports.getChainId = exports.AptosNetwork = void 0;
3
+ exports.AptosBindOptions = exports.getChainRpcEndpoint = exports.getChainName = exports.getChainId = exports.AptosNetwork = void 0;
4
4
  const chain_1 = require("../utils/chain");
5
5
  var AptosNetwork;
6
6
  (function (AptosNetwork) {
@@ -16,10 +16,26 @@ function getChainId(network) {
16
16
  return chain_1.APTOS_MAINNET_ID;
17
17
  }
18
18
  exports.getChainId = getChainId;
19
+ function getChainName(network) {
20
+ switch (network) {
21
+ case AptosNetwork.TEST_NET:
22
+ return chain_1.CHAIN_MAP[chain_1.APTOS_TESTNET_ID];
23
+ }
24
+ return chain_1.CHAIN_MAP[chain_1.APTOS_MAINNET_ID];
25
+ }
26
+ exports.getChainName = getChainName;
27
+ function getChainRpcEndpoint(network) {
28
+ switch (network) {
29
+ case AptosNetwork.TEST_NET:
30
+ return 'https://testnet.aptoslabs.com/';
31
+ }
32
+ return 'https://mainnet.aptoslabs.com/v1/';
33
+ }
34
+ exports.getChainRpcEndpoint = getChainRpcEndpoint;
19
35
  class AptosBindOptions {
20
36
  address;
21
37
  network = AptosNetwork.TEST_NET;
22
38
  startVersion;
23
39
  }
24
40
  exports.AptosBindOptions = AptosBindOptions;
25
- //# sourceMappingURL=bind-options.js.map
41
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/aptos/network.ts"],"names":[],"mappings":";;;AACA,0CAA8E;AAE9E,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,WAAW;AACb,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED,SAAgB,UAAU,CAAC,OAAqB;IAC9C,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,wBAAgB,CAAA;KAC1B;IACD,OAAO,wBAAgB,CAAA;AACzB,CAAC;AAND,gCAMC;AAED,SAAgB,YAAY,CAAC,OAAqB;IAChD,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,iBAAS,CAAC,wBAAgB,CAAC,CAAA;KACrC;IACD,OAAO,iBAAS,CAAC,wBAAgB,CAAC,CAAA;AACpC,CAAC;AAND,oCAMC;AAED,SAAgB,mBAAmB,CAAC,OAAqB;IACvD,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,gCAAgC,CAAA;KAC1C;IACD,OAAO,mCAAmC,CAAA;AAC5C,CAAC;AAND,kDAMC;AAED,MAAa,gBAAgB;IAC3B,OAAO,CAAQ;IACf,OAAO,GAAkB,YAAY,CAAC,QAAQ,CAAA;IAC9C,YAAY,CAAgB;CAE7B;AALD,4CAKC","sourcesContent":["import Long from 'long'\nimport { APTOS_MAINNET_ID, APTOS_TESTNET_ID, CHAIN_MAP } from '../utils/chain'\n\nexport enum AptosNetwork {\n MAIN_NET = 1,\n TEST_NET = 2,\n // DEV_NET,\n}\n\nexport function getChainId(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return APTOS_TESTNET_ID\n }\n return APTOS_MAINNET_ID\n}\n\nexport function getChainName(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return CHAIN_MAP[APTOS_TESTNET_ID]\n }\n return CHAIN_MAP[APTOS_MAINNET_ID]\n}\n\nexport function getChainRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/v1/'\n}\n\nexport class AptosBindOptions {\n address: string\n network?: AptosNetwork = AptosNetwork.TEST_NET\n startVersion?: Long | number\n // endBlock?: Long | number\n}\n"]}
@@ -1,2 +1,2 @@
1
- import { MoveStruct } from 'aptos/src/generated/models/MoveStruct';
1
+ import { MoveStruct } from 'aptos-sdk/src/generated';
2
2
  export declare function decode<T>(struct: MoveStruct, args: any[]): T | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/aptos/runtime.ts"],"names":[],"mappings":";;;AAEA,SAAgB,MAAM,CAAI,MAAkB,EAAE,IAAW;IACvD,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QACvC,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3D,OAAO,SAAS,CAAA;KACjB;IACD,MAAM,GAAG,GAAQ,EAAE,CAAA;IACnB,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE;QAChD,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;KAC1B;IACD,OAAO,GAAQ,CAAA;AACjB,CAAC;AAVD,wBAUC","sourcesContent":["import { MoveStruct } from 'aptos/src/generated/models/MoveStruct'\n\nexport function decode<T>(struct: MoveStruct, args: any[]): T | undefined {\n if (args.length != struct.fields.length) {\n console.log('type mismatch actually data for', struct.name)\n return undefined\n }\n const res: any = {}\n for (const [i, field] of struct.fields.entries()) {\n res[field.name] = args[i]\n }\n return res as T\n}\n"]}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/aptos/runtime.ts"],"names":[],"mappings":";;;AAEA,SAAgB,MAAM,CAAI,MAAkB,EAAE,IAAW;IACvD,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QACvC,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3D,OAAO,SAAS,CAAA;KACjB;IACD,MAAM,GAAG,GAAQ,EAAE,CAAA;IACnB,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE;QAChD,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;KAC1B;IACD,OAAO,GAAQ,CAAA;AACjB,CAAC;AAVD,wBAUC","sourcesContent":["import { MoveStruct } from 'aptos-sdk/src/generated'\n\nexport function decode<T>(struct: MoveStruct, args: any[]): T | undefined {\n if (args.length != struct.fields.length) {\n console.log('type mismatch actually data for', struct.name)\n return undefined\n }\n const res: any = {}\n for (const [i, field] of struct.fields.entries()) {\n res[field.name] = args[i]\n }\n return res as T\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Event, MoveFunction, MoveModule, MoveStruct, TransactionPayload_EntryFunctionPayload } from 'aptos/src/generated';
1
+ import { Event, MoveFunction, MoveModule, MoveStruct, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated';
2
2
  export declare type EventInstance = Event & {
3
3
  version: string;
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/aptos/types.ts"],"names":[],"mappings":";;;AAOA,mCAA2D;AAC3D,sDAAwD;AAoBxD,MAAa,cAAc;IACzB,eAAe;IAEf,yCAAyC;IACzC,KAAK,CAAQ;IACb,mBAAmB;IACnB,kBAAkB;IAElB,QAAQ,CAAkB;IAE1B,YAAY,MAAc,EAAE,UAA6B;QACvD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;QACnB,IAAI,CAAC,QAAQ,GAAG,UAAU,IAAI,EAAE,CAAA;IAClC,CAAC;IAED,YAAY;QACV,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,OAAO,IAAI,CAAC,KAAK,GAAG,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;SACtF;QACD,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,yCAAyC;IACzC,aAAa,CAAC,GAAgC;QAC5C,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACnC,IAAI,OAAO,EAAE;YACX,OAAO,OAAO,CAAA;SACf;QACD,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YAChD,OAAO,IAAI,CAAA;SACZ;QAED,MAAM,QAAQ,GAAqB,EAAE,CAAA;QACrC,KAAK,MAAM,GAAG,IAAI,IAAI,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AG,GAAG,EAAE,CAAA;YACd,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE;gBACxB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;aAC/C;YACD,OAAO,GAAG,CAAA;SACX;QAED,uBAAuB;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAE7C,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAA;QACjD,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE;YACpD,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE,OAAO,CAAC,CAAA;SAChC;QAED,MAAM,SAAS,GAAQ,EAAE,CAAA;QAEzB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;YACjC,IAAI,SAAS,GAAG,IAAA,uBAAa,EAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACzC,SAAS,GAAG,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;YAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAA;YACtD,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;SAC9B;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CAGF;AAnGD,oCAmGC;AAEY,QAAA,oBAAoB,GAAG,IAAI,YAAY,EAAE,CAAA","sourcesContent":["import {\n Event,\n MoveFunction,\n MoveModule,\n MoveStruct,\n TransactionPayload_EntryFunctionPayload,\n} from 'aptos/src/generated'\nimport { moduleQname, SPLITTER, VECTOR_STR } from './utils'\nimport { parseMoveType } from '../aptos-codegen/typegen'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = EventInstance & {\n // Typed data converted from ABI\n // undefined if there is converting error, usually because the ABI/data\n // mismatch\n data_typed: T\n\n type_arguments: string[]\n}\n\n// Don't use intermedidate type to make IDE happier\nexport type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n arguments_typed: T\n}\n\nexport class TypeDescriptor {\n // type: string\n\n // qualified name without type parameters\n qname: string\n // account?: string\n // module?: string\n\n typeArgs: TypeDescriptor[]\n\n constructor(symbol: string, typeParams?: TypeDescriptor[]) {\n this.qname = symbol\n this.typeArgs = typeParams || []\n }\n\n getSignature(): string {\n if (this.typeArgs.length > 0) {\n return this.qname + '<' + this.typeArgs.map((t) => t.getSignature()).join(', ') + '>'\n }\n return this.qname\n }\n\n // Replace T0, T1 with more concrete type\n applyTypeArgs(ctx: Map<string, TypeDescriptor>): TypeDescriptor {\n const replace = ctx.get(this.qname)\n if (replace) {\n return replace\n }\n if (ctx.size === 0 || this.typeArgs.length === 0) {\n return this\n }\n\n const typeArgs: TypeDescriptor[] = []\n for (const arg of this.typeArgs) {\n const replace = ctx.get(arg.qname)\n if (replace) {\n typeArgs.push(replace)\n } else {\n typeArgs.push(arg.applyTypeArgs(ctx))\n }\n }\n return new TypeDescriptor(this.qname, typeArgs)\n }\n\n // all depended types including itself, not include system type\n dependedTypes(): string[] {\n if (this.qname.startsWith('&')) {\n return []\n }\n switch (this.qname) {\n case 'signer':\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n case 'u64':\n case 'u128':\n return []\n }\n\n // Type parameters are not depended\n if (this.qname.indexOf(SPLITTER) == -1) {\n if (this.qname.startsWith('T')) {\n return []\n }\n }\n\n const types = new Set<string>()\n for (const param of this.typeArgs) {\n param.dependedTypes().forEach((t) => types.add(t))\n }\n\n if (this.qname !== VECTOR_STR) {\n types.add(this.qname)\n }\n\n return Array.from(types)\n }\n}\n\nexport class TypeRegistry {\n moduleMapping = new Map<string, MoveModule>()\n typeMapping = new Map<string, MoveStruct>()\n funcMapping = new Map<string, MoveFunction>()\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n load(module: MoveModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname(module), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [module.address, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n const key = [module.address, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n getMoveStruct(type: string): MoveStruct {\n const struct = this.typeMapping.get(type)\n if (!struct) {\n throw new Error('Failed to load type' + type)\n }\n return struct\n }\n\n getMoveFunction(type: string): MoveFunction {\n const func = this.funcMapping.get(type)\n if (!func) {\n throw new Error('Failed to load function' + type)\n }\n return func\n }\n\n decode(data: any, type: TypeDescriptor): any {\n // process simple type\n if (type.qname.startsWith('&')) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n return data\n case 'u64':\n case 'u128':\n return BigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.decode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = parseMoveType(field.type)\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = this.decode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n // private decodeInternal(data: any, type: TypeDescriptor, typ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E,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;aAC/C;YACD,OAAO,GAAG,CAAA;SACX;QAED,uBAAuB;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAE7C,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAA;QACjD,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE;YACpD,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE,OAAO,CAAC,CAAA;SAChC;QAED,MAAM,SAAS,GAAQ,EAAE,CAAA;QAEzB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;YACjC,IAAI,SAAS,GAAG,IAAA,uBAAa,EAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACzC,SAAS,GAAG,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;YAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAA;YACtD,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;SAC9B;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CAGF;AAnGD,oCAmGC;AAEY,QAAA,oBAAoB,GAAG,IAAI,YAAY,EAAE,CAAA","sourcesContent":["import {\n Event,\n MoveFunction,\n MoveModule,\n MoveStruct,\n TransactionPayload_EntryFunctionPayload,\n} from 'aptos-sdk/src/generated'\nimport { moduleQname, SPLITTER, VECTOR_STR } from './utils'\nimport { parseMoveType } from '../aptos-codegen/typegen'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = EventInstance & {\n // Typed data converted from ABI\n // undefined if there is converting error, usually because the ABI/data\n // mismatch\n data_typed: T\n\n type_arguments: string[]\n}\n\n// Don't use intermedidate type to make IDE happier\nexport type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n arguments_typed: T\n}\n\nexport class TypeDescriptor {\n // type: string\n\n // qualified name without type parameters\n qname: string\n // account?: string\n // module?: string\n\n typeArgs: TypeDescriptor[]\n\n constructor(symbol: string, typeParams?: TypeDescriptor[]) {\n this.qname = symbol\n this.typeArgs = typeParams || []\n }\n\n getSignature(): string {\n if (this.typeArgs.length > 0) {\n return this.qname + '<' + this.typeArgs.map((t) => t.getSignature()).join(', ') + '>'\n }\n return this.qname\n }\n\n // Replace T0, T1 with more concrete type\n applyTypeArgs(ctx: Map<string, TypeDescriptor>): TypeDescriptor {\n const replace = ctx.get(this.qname)\n if (replace) {\n return replace\n }\n if (ctx.size === 0 || this.typeArgs.length === 0) {\n return this\n }\n\n const typeArgs: TypeDescriptor[] = []\n for (const arg of this.typeArgs) {\n const replace = ctx.get(arg.qname)\n if (replace) {\n typeArgs.push(replace)\n } else {\n typeArgs.push(arg.applyTypeArgs(ctx))\n }\n }\n return new TypeDescriptor(this.qname, typeArgs)\n }\n\n // all depended types including itself, not include system type\n dependedTypes(): string[] {\n if (this.qname.startsWith('&')) {\n return []\n }\n switch (this.qname) {\n case 'signer':\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n case 'u64':\n case 'u128':\n return []\n }\n\n // Type parameters are not depended\n if (this.qname.indexOf(SPLITTER) == -1) {\n if (this.qname.startsWith('T')) {\n return []\n }\n }\n\n const types = new Set<string>()\n for (const param of this.typeArgs) {\n param.dependedTypes().forEach((t) => types.add(t))\n }\n\n if (this.qname !== VECTOR_STR) {\n types.add(this.qname)\n }\n\n return Array.from(types)\n }\n}\n\nexport class TypeRegistry {\n moduleMapping = new Map<string, MoveModule>()\n typeMapping = new Map<string, MoveStruct>()\n funcMapping = new Map<string, MoveFunction>()\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n load(module: MoveModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname(module), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [module.address, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n const key = [module.address, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n getMoveStruct(type: string): MoveStruct {\n const struct = this.typeMapping.get(type)\n if (!struct) {\n throw new Error('Failed to load type' + type)\n }\n return struct\n }\n\n getMoveFunction(type: string): MoveFunction {\n const func = this.funcMapping.get(type)\n if (!func) {\n throw new Error('Failed to load function' + type)\n }\n return func\n }\n\n decode(data: any, type: TypeDescriptor): any {\n // process simple type\n if (type.qname.startsWith('&')) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n case '0x1::string::String':\n case 'bool':\n case 'u8':\n case 'u16':\n case 'u32':\n return data\n case 'u64':\n case 'u128':\n return BigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.decode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = parseMoveType(field.type)\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = this.decode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n // private decodeInternal(data: any, type: TypeDescriptor, typeArgs: )\n}\n\nexport const GLOBAL_TYPE_REGISTRY = new TypeRegistry()\n"]}
@@ -1,4 +1,4 @@
1
- import { MoveModule } from 'aptos/src/generated';
1
+ import { MoveModule } from 'aptos-sdk/src/generated';
2
2
  export declare const SPLITTER = "::";
3
3
  export declare const VECTOR_STR = "vector";
4
4
  export declare function isFrameworkAccount(account: string): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,QAAQ,GAAG,IAAI,CAAA;AAEf,QAAA,UAAU,GAAG,QAAQ,CAAA;AAElC,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,CAAA;AACpE,CAAC;AAFD,gDAEC;AAED,SAAgB,WAAW,CAAC,MAAkB;IAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,gBAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;AAC9D,CAAC;AAFD,kCAEC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC;AAHD,gDAGC","sourcesContent":["import { MoveModule } from 'aptos/src/generated'\n\nexport const SPLITTER = '::'\n\nexport const VECTOR_STR = 'vector'\n\nexport function isFrameworkAccount(account: string) {\n return account === '0x1' || account === '0x2' || account === '0x3'\n}\n\nexport function moduleQname(module: MoveModule): string {\n return module.address.toLowerCase() + SPLITTER + module.name\n}\n\nexport function moduleQnameForType(type: string): [string, string] {\n const parts = type.split(SPLITTER).slice(0, 2)\n return [parts[0], parts[1]]\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,QAAQ,GAAG,IAAI,CAAA;AAEf,QAAA,UAAU,GAAG,QAAQ,CAAA;AAElC,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,CAAA;AACpE,CAAC;AAFD,gDAEC;AAED,SAAgB,WAAW,CAAC,MAAkB;IAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,gBAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;AAC9D,CAAC;AAFD,kCAEC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC;AAHD,gDAGC","sourcesContent":["import { MoveModule } from 'aptos-sdk/src/generated'\n\nexport const SPLITTER = '::'\n\nexport const VECTOR_STR = 'vector'\n\nexport function isFrameworkAccount(account: string) {\n return account === '0x1' || account === '0x2' || account === '0x3'\n}\n\nexport function moduleQname(module: MoveModule): string {\n return module.address.toLowerCase() + SPLITTER + module.name\n}\n\nexport function moduleQnameForType(type: string): [string, string] {\n const parts = type.split(SPLITTER).slice(0, 2)\n return [parts[0], parts[1]]\n}\n"]}
@@ -1,15 +1,22 @@
1
- import { MoveModuleBytecode } from 'aptos/src/generated';
1
+ import { MoveModuleBytecode } from 'aptos-sdk/src/generated';
2
2
  import { AccountRegister } from './typegen';
3
- export declare function generate(srcDir: string, outputDir: string): void;
3
+ import { AptosNetwork } from '../aptos/network';
4
+ export declare function generate(srcDir: string, outputDir: string): Promise<void>;
5
+ export declare function generateForNetwork(srcDir: string, outputDir: string, network: AptosNetwork): Promise<void>;
6
+ interface OutputFile {
7
+ fileName: string;
8
+ fileContent: string;
9
+ }
4
10
  interface Config {
5
- srcFile: string;
11
+ fileName: string;
6
12
  outputDir: string;
13
+ network: AptosNetwork;
7
14
  }
8
15
  export declare class AccountCodegen {
9
16
  modules: MoveModuleBytecode[];
10
17
  config: Config;
11
18
  loader: AccountRegister;
12
- constructor(loader: AccountRegister, config: Config);
13
- generate(): void;
19
+ constructor(loader: AccountRegister, modules: MoveModuleBytecode[], config: Config);
20
+ generate(): OutputFile[];
14
21
  }
15
22
  export {};
@@ -3,67 +3,101 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AccountCodegen = exports.generate = void 0;
6
+ exports.AccountCodegen = exports.generateForNetwork = exports.generate = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const prettier_1 = __importDefault(require("prettier"));
10
10
  const typegen_1 = require("./typegen");
11
11
  const utils_1 = require("../aptos/utils");
12
- function generate(srcDir, outputDir) {
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ const network_1 = require("../aptos/network");
14
+ const aptos_sdk_1 = require("aptos-sdk");
15
+ async function generate(srcDir, outputDir) {
16
+ await generateForNetwork(srcDir, outputDir, network_1.AptosNetwork.MAIN_NET);
17
+ await generateForNetwork(path_1.default.join(srcDir, 'testnet'), path_1.default.join(outputDir, 'testnet'), network_1.AptosNetwork.TEST_NET);
18
+ }
19
+ exports.generate = generate;
20
+ async function generateForNetwork(srcDir, outputDir, network) {
21
+ if (!fs_1.default.existsSync(srcDir)) {
22
+ return;
23
+ }
24
+ if (network === network_1.AptosNetwork.TEST_NET) {
25
+ console.log('Found testnet directory, generate code for testnet modules');
26
+ }
13
27
  const files = fs_1.default.readdirSync(srcDir);
14
28
  outputDir = path_1.default.resolve(outputDir);
29
+ const outputs = [];
15
30
  fs_1.default.mkdirSync(outputDir, { recursive: true });
16
31
  const loader = new typegen_1.AccountRegister();
17
- // The first path, identify import relation and module name (filename) of those imports
32
+ // when generating user code, don't need to generate framework account
33
+ loader.accountImports.set('0x1', new typegen_1.AccountModulesImportInfo('0x1', '0x1'));
34
+ loader.accountImports.set('0x2', new typegen_1.AccountModulesImportInfo('0x2', '0x2'));
35
+ loader.accountImports.set('0x3', new typegen_1.AccountModulesImportInfo('0x3', '0x3'));
36
+ const client = new aptos_sdk_1.AptosClient((0, network_1.getChainRpcEndpoint)(network));
18
37
  for (const file of files) {
19
38
  if (!file.endsWith('.json')) {
20
39
  continue;
21
40
  }
22
- // Reading file is duplicated, but since they are small files probably file
23
- // TODO add file manager class
24
- const json = fs_1.default.readFileSync(path_1.default.join(srcDir, file), 'utf-8');
25
- const modules = JSON.parse(json);
41
+ const fullPath = path_1.default.resolve(srcDir, file);
42
+ const modules = JSON.parse(fs_1.default.readFileSync(fullPath, 'utf-8'));
26
43
  for (const module of modules) {
27
44
  if (module.abi) {
28
45
  loader.register(module.abi, path_1.default.basename(file, '.json'));
29
46
  }
30
47
  }
31
- }
32
- for (const file of files) {
33
- if (!file.endsWith('.json')) {
34
- continue;
35
- }
36
- const codeGen = new AccountCodegen(loader, {
37
- srcFile: path_1.default.join(srcDir, file),
48
+ const codeGen = new AccountCodegen(loader, modules, {
49
+ fileName: path_1.default.basename(file, '.json'),
38
50
  outputDir: outputDir,
51
+ network,
39
52
  });
40
- codeGen.generate();
53
+ outputs.push(...codeGen.generate());
41
54
  }
42
- // when generating user code, don't need to generate framework account
43
- loader.pendingAccounts.delete('0x1');
44
- loader.pendingAccounts.delete('0x2');
45
- loader.pendingAccounts.delete('0x3');
46
- if (loader.pendingAccounts.size > 0) {
47
- // TODO automatic download dependencies
48
- console.error('Missing ABIs from the following accounts', loader.pendingAccounts);
55
+ while (loader.pendingAccounts.size > 0) {
56
+ for (const account of loader.pendingAccounts) {
57
+ console.log(`download depended module for account ${account} at ${(0, network_1.getChainName)(network)}`);
58
+ try {
59
+ const modules = await client.getAccountModules(account);
60
+ fs_1.default.writeFileSync(path_1.default.resolve(srcDir, account + '.json'), JSON.stringify(modules, null, '\t'));
61
+ for (const module of modules) {
62
+ if (module.abi) {
63
+ loader.register(module.abi, account);
64
+ }
65
+ }
66
+ const codeGen = new AccountCodegen(loader, modules, {
67
+ fileName: account,
68
+ outputDir: outputDir,
69
+ network,
70
+ });
71
+ outputs.push(...codeGen.generate());
72
+ }
73
+ catch (e) {
74
+ console.error(chalk_1.default.red('Error downloading account module, check if you choose the right network,or download account modules manually into your director'));
75
+ console.error(e);
76
+ process.exit(1);
77
+ }
78
+ }
79
+ }
80
+ for (const output of outputs) {
81
+ const content = prettier_1.default.format(output.fileContent, { parser: 'typescript' });
82
+ fs_1.default.writeFileSync(path_1.default.join(outputDir, output.fileName), content);
49
83
  }
50
84
  }
51
- exports.generate = generate;
85
+ exports.generateForNetwork = generateForNetwork;
52
86
  class AccountCodegen {
53
87
  modules;
54
88
  config;
55
89
  loader;
56
- constructor(loader, config) {
57
- const json = fs_1.default.readFileSync(config.srcFile, 'utf-8');
58
- this.modules = JSON.parse(json);
90
+ constructor(loader, modules, config) {
91
+ // const json = fs.readFileSync(config.srcFile, 'utf-8')
92
+ this.modules = modules;
59
93
  this.config = config;
60
94
  this.loader = loader;
61
95
  }
62
96
  generate() {
63
97
  if (!this.modules) {
64
- return;
98
+ return [];
65
99
  }
66
- const baseName = path_1.default.basename(this.config.srcFile, '.json');
100
+ // const baseName = path.basename(this.config.fileName, '.json')
67
101
  let address;
68
102
  for (const module of this.modules) {
69
103
  if (module.abi && module.abi.address) {
@@ -71,11 +105,11 @@ class AccountCodegen {
71
105
  }
72
106
  }
73
107
  if (!address) {
74
- return;
108
+ return [];
75
109
  }
76
110
  const imports = `
77
111
  import { aptos } from "@sentio/sdk"
78
- import { Address, MoveModule } from "aptos/src/generated"
112
+ import { Address, MoveModule } from "aptos-sdk/src/generated"
79
113
  `;
80
114
  const dependedAccounts = [];
81
115
  const moduleImports = [];
@@ -99,7 +133,7 @@ class AccountCodegen {
99
133
  items.forEach((m) => dependedAccounts.push(m));
100
134
  }
101
135
  }
102
- let source = `
136
+ const source = `
103
137
  /* Autogenerated file. Do not edit manually. */
104
138
  /* tslint:disable */
105
139
  /* eslint-disable */
@@ -110,7 +144,7 @@ class AccountCodegen {
110
144
 
111
145
  ${moduleImports.join('\n')}
112
146
 
113
- ${this.modules.map((m) => generateModule(m, dependedAccounts)).join('\n')}
147
+ ${this.modules.map((m) => generateModule(m, this.config.network)).join('\n')}
114
148
 
115
149
  function loadAllTypes(registry: aptos.TypeRegistry) {
116
150
  ${dependedAccounts.map((m) => `${m}.loadTypes(registry)`).join('\n')}
@@ -122,12 +156,23 @@ class AccountCodegen {
122
156
  .join('\n')}
123
157
  }
124
158
  `; // source
125
- source = prettier_1.default.format(source, { parser: 'typescript' });
126
- fs_1.default.writeFileSync(path_1.default.join(this.config.outputDir, baseName + '.ts'), source);
159
+ return [
160
+ {
161
+ fileName: this.config.fileName + '.ts',
162
+ fileContent: source,
163
+ },
164
+ ];
127
165
  }
128
166
  }
129
167
  exports.AccountCodegen = AccountCodegen;
130
- function generateModule(moduleByteCode, dependedModules) {
168
+ function generateNetworkOption(network) {
169
+ switch (network) {
170
+ case network_1.AptosNetwork.TEST_NET:
171
+ return 'TEST_NET';
172
+ }
173
+ return 'MAIN_NET';
174
+ }
175
+ function generateModule(moduleByteCode, network) {
131
176
  if (!moduleByteCode.abi) {
132
177
  return '';
133
178
  }
@@ -145,7 +190,7 @@ function generateModule(moduleByteCode, dependedModules) {
145
190
  }
146
191
  static DEFAULT_OPTIONS: aptos.AptosBindOptions = {
147
192
  address: "${module.address}",
148
- network: aptos.AptosNetwork.TEST_NET
193
+ network: aptos.AptosNetwork.${generateNetworkOption(network)}
149
194
  }
150
195
 
151
196
  static bind(options: Partial<aptos.AptosBindOptions> = {}): ${module.name} {