@sentio/sdk 1.20.1 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. package/lib/aptos/aptos-processor.d.ts +17 -12
  2. package/lib/aptos/aptos-processor.js +65 -13
  3. package/lib/aptos/aptos-processor.js.map +1 -1
  4. package/lib/aptos/bind-options.d.ts +0 -6
  5. package/lib/aptos/bind-options.js +1 -8
  6. package/lib/aptos/bind-options.js.map +1 -1
  7. package/lib/aptos/context.d.ts +5 -4
  8. package/lib/aptos/context.js +9 -6
  9. package/lib/aptos/context.js.map +1 -1
  10. package/lib/aptos/index.d.ts +3 -2
  11. package/lib/aptos/index.js +1 -2
  12. package/lib/aptos/index.js.map +1 -1
  13. package/lib/aptos/runtime.d.ts +2 -0
  14. package/lib/aptos/runtime.js +16 -0
  15. package/lib/aptos/runtime.js.map +1 -0
  16. package/lib/aptos/types.d.ts +28 -0
  17. package/lib/aptos/types.js +159 -0
  18. package/lib/aptos/types.js.map +1 -0
  19. package/lib/aptos/utils.d.ts +6 -0
  20. package/lib/aptos/utils.js +19 -0
  21. package/lib/aptos/utils.js.map +1 -0
  22. package/lib/aptos-codegen/codegen.d.ts +5 -2
  23. package/lib/aptos-codegen/codegen.js +195 -18
  24. package/lib/aptos-codegen/codegen.js.map +1 -1
  25. package/lib/aptos-codegen/typegen.d.ts +18 -0
  26. package/lib/aptos-codegen/typegen.js +196 -0
  27. package/lib/aptos-codegen/typegen.js.map +1 -0
  28. package/lib/binds.d.ts +2 -3
  29. package/lib/binds.js +6 -33
  30. package/lib/binds.js.map +1 -1
  31. package/lib/builtin/aptos/0x1.d.ts +1624 -0
  32. package/lib/builtin/aptos/0x1.js +2502 -0
  33. package/lib/builtin/aptos/0x1.js.map +1 -0
  34. package/lib/builtin/aptos/0x3.d.ts +414 -0
  35. package/lib/builtin/aptos/0x3.js +461 -0
  36. package/lib/builtin/aptos/0x3.js.map +1 -0
  37. package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +2 -2
  38. package/lib/builtin/internal/eacaggregatorproxy_processor.js +12 -11
  39. package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
  40. package/lib/builtin/internal/erc20_processor.d.ts +2 -2
  41. package/lib/builtin/internal/erc20_processor.js +12 -11
  42. package/lib/builtin/internal/erc20_processor.js.map +1 -1
  43. package/lib/builtin/internal/erc20bytes_processor.d.ts +2 -2
  44. package/lib/builtin/internal/erc20bytes_processor.js +12 -11
  45. package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
  46. package/lib/builtin/internal/weth9_processor.d.ts +2 -2
  47. package/lib/builtin/internal/weth9_processor.js +12 -11
  48. package/lib/builtin/internal/weth9_processor.js.map +1 -1
  49. package/lib/builtin/solana/types.d.ts +5 -5
  50. package/lib/builtin/solana/wormhole-processor.d.ts +6 -6
  51. package/lib/builtin/solana/wormhole-processor.js +15 -12
  52. package/lib/builtin/solana/wormhole-processor.js.map +1 -1
  53. package/lib/cli/build.js +17 -16
  54. package/lib/cli/build.js.map +1 -1
  55. package/lib/core/base-processor-template.d.ts +7 -7
  56. package/lib/core/base-processor-template.js.map +1 -1
  57. package/lib/core/base-processor.d.ts +5 -6
  58. package/lib/core/base-processor.js +6 -4
  59. package/lib/core/base-processor.js.map +1 -1
  60. package/lib/core/big-decimal.d.ts +1 -0
  61. package/lib/core/big-decimal.js +6 -0
  62. package/lib/core/big-decimal.js.map +1 -0
  63. package/lib/core/bind-options.d.ts +0 -2
  64. package/lib/core/bind-options.js +4 -4
  65. package/lib/core/bind-options.js.map +1 -1
  66. package/lib/core/context.d.ts +14 -11
  67. package/lib/core/context.js +28 -19
  68. package/lib/core/context.js.map +1 -1
  69. package/lib/core/generic-processor.js +5 -5
  70. package/lib/core/generic-processor.js.map +1 -1
  71. package/lib/core/index.d.ts +5 -5
  72. package/lib/core/index.js +6 -6
  73. package/lib/core/index.js.map +1 -1
  74. package/lib/core/logger.d.ts +2 -3
  75. package/lib/core/logger.js +6 -6
  76. package/lib/core/logger.js.map +1 -1
  77. package/lib/core/metadata.d.ts +7 -4
  78. package/lib/core/metadata.js +13 -10
  79. package/lib/core/metadata.js.map +1 -1
  80. package/lib/core/meter.d.ts +4 -7
  81. package/lib/core/meter.js +12 -13
  82. package/lib/core/meter.js.map +1 -1
  83. package/lib/core/solana-processor.d.ts +7 -4
  84. package/lib/core/solana-processor.js +14 -20
  85. package/lib/core/solana-processor.js.map +1 -1
  86. package/lib/core/sui-processor.d.ts +5 -4
  87. package/lib/core/sui-processor.js +10 -17
  88. package/lib/core/sui-processor.js.map +1 -1
  89. package/lib/error.d.ts +2 -2
  90. package/lib/error.js.map +1 -1
  91. package/lib/gen/processor/protos/processor.d.ts +23 -12
  92. package/lib/gen/processor/protos/processor.js +129 -57
  93. package/lib/gen/processor/protos/processor.js.map +1 -1
  94. package/lib/index.d.ts +1 -2
  95. package/lib/index.js +1 -4
  96. package/lib/index.js.map +1 -1
  97. package/lib/processor-state.d.ts +1 -1
  98. package/lib/processor-state.js.map +1 -1
  99. package/lib/service.js +13 -12
  100. package/lib/service.js.map +1 -1
  101. package/lib/target-ethers-sentio/codegen.js +14 -15
  102. package/lib/target-ethers-sentio/codegen.js.map +1 -1
  103. package/lib/test-abi-code-gen.js.map +1 -1
  104. package/lib/testing/metric-utils.js +2 -2
  105. package/lib/testing/metric-utils.js.map +1 -1
  106. package/lib/tests/aptos.test.js +95 -2
  107. package/lib/tests/aptos.test.js.map +1 -1
  108. package/lib/tests/erc20.js +1 -1
  109. package/lib/tests/erc20.js.map +1 -1
  110. package/lib/tests/erc20.test.js +3 -4
  111. package/lib/tests/erc20.test.js.map +1 -1
  112. package/lib/tests/solana.test.js +5 -1
  113. package/lib/tests/solana.test.js.map +1 -1
  114. package/lib/tests/souffl3.js +17 -4
  115. package/lib/tests/souffl3.js.map +1 -1
  116. package/lib/tests/sui.test.js +1 -4
  117. package/lib/tests/sui.test.js.map +1 -1
  118. package/lib/tests/types/aptos/souffle.d.ts +311 -22
  119. package/lib/tests/types/aptos/souffle.js +142 -6
  120. package/lib/tests/types/aptos/souffle.js.map +1 -1
  121. package/lib/tests/types/solana/basic_1_processor.d.ts +2 -2
  122. package/lib/tests/types/solana/basic_1_processor.js +4 -4
  123. package/lib/tests/types/solana/basic_1_processor.js.map +1 -1
  124. package/lib/tests/wormhole-token-bridge.js +2 -1
  125. package/lib/tests/wormhole-token-bridge.js.map +1 -1
  126. package/lib/utils/chain.d.ts +1 -0
  127. package/lib/utils/chain.js +15 -1
  128. package/lib/utils/chain.js.map +1 -1
  129. package/lib/utils/conversion.d.ts +1 -1
  130. package/lib/utils/conversion.js.map +1 -1
  131. package/package.json +3 -2
  132. package/src/abis/aptos/0x1.json +9205 -0
  133. package/src/abis/aptos/0x3.json +1515 -0
  134. package/src/aptos/aptos-processor.ts +88 -20
  135. package/src/aptos/bind-options.ts +0 -7
  136. package/src/aptos/context.ts +11 -8
  137. package/src/aptos/index.ts +3 -2
  138. package/src/aptos/runtime.ts +13 -0
  139. package/src/aptos/types.ts +203 -0
  140. package/src/aptos/utils.ts +18 -0
  141. package/src/aptos-codegen/codegen.ts +222 -19
  142. package/src/aptos-codegen/typegen.test.ts +29 -0
  143. package/src/aptos-codegen/typegen.ts +216 -0
  144. package/src/binds.ts +5 -39
  145. package/src/builtin/aptos/0x1.ts +3760 -0
  146. package/src/builtin/aptos/0x3.ts +798 -0
  147. package/src/builtin/internal/eacaggregatorproxy_processor.ts +14 -31
  148. package/src/builtin/internal/erc20_processor.ts +14 -25
  149. package/src/builtin/internal/erc20bytes_processor.ts +14 -25
  150. package/src/builtin/internal/weth9_processor.ts +14 -25
  151. package/src/builtin/solana/wormhole-processor.ts +21 -18
  152. package/src/cli/build.ts +19 -17
  153. package/src/core/base-processor-template.ts +7 -7
  154. package/src/core/base-processor.ts +30 -9
  155. package/src/core/big-decimal.ts +1 -0
  156. package/src/core/bind-options.ts +3 -2
  157. package/src/core/context.ts +40 -24
  158. package/src/core/generic-processor.ts +6 -7
  159. package/src/core/index.ts +5 -5
  160. package/src/core/logger.ts +7 -7
  161. package/src/core/metadata.ts +14 -12
  162. package/src/core/meter.ts +12 -14
  163. package/src/core/solana-processor.ts +24 -21
  164. package/src/core/sui-processor.ts +10 -21
  165. package/src/error.ts +2 -2
  166. package/src/gen/processor/protos/processor.ts +158 -68
  167. package/src/index.ts +1 -2
  168. package/src/processor-state.ts +1 -1
  169. package/src/service.ts +22 -15
  170. package/src/target-ethers-sentio/codegen.ts +14 -15
  171. package/src/test-abi-code-gen.ts +1 -0
  172. package/src/testing/metric-utils.ts +2 -2
  173. package/src/tests/aptos.test.ts +102 -3
  174. package/src/tests/erc20.test.ts +3 -4
  175. package/src/tests/erc20.ts +1 -1
  176. package/src/tests/solana.test.ts +5 -1
  177. package/src/tests/souffl3.ts +21 -6
  178. package/src/tests/sui.test.ts +1 -4
  179. package/src/tests/types/aptos/souffle.ts +424 -42
  180. package/src/tests/types/solana/basic_1_processor.ts +6 -6
  181. package/src/tests/wormhole-token-bridge.ts +2 -1
  182. package/src/types/global.d.ts +1 -1
  183. package/src/utils/chain.ts +14 -0
  184. package/src/utils/conversion.ts +1 -1
  185. package/lib/contract-namer.d.ts +0 -6
  186. package/lib/contract-namer.js +0 -20
  187. package/lib/contract-namer.js.map +0 -1
  188. package/src/aptos-codegen/codgen.test.ts +0 -11
  189. package/src/contract-namer.ts +0 -17
@@ -1,41 +1,46 @@
1
1
  import { ProcessResult } from '../gen';
2
- import { AptosBindOptions, AptosContext, AptosNetwork, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from '.';
3
- import type { Event as OldEvent } from 'aptos/src/generated';
2
+ import { AptosBindOptions, AptosContext, AptosNetwork, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload, TypeRegistry } from '.';
4
3
  import Long from 'long';
5
- export declare type Event = OldEvent & {
6
- version: string;
7
- };
4
+ import { EventInstance } from './types';
8
5
  declare type IndexConfigure = {
9
6
  address: string;
10
7
  network: AptosNetwork;
11
8
  startVersion: Long;
12
9
  };
13
- export interface EventFilter {
10
+ export interface EventFilter extends ArgumentsFilter {
14
11
  type: string;
15
12
  }
16
- export interface CallFilter {
13
+ export interface CallFilter extends CallArgumentsFilter {
17
14
  function: string;
15
+ }
16
+ export interface CallArgumentsFilter extends ArgumentsFilter {
18
17
  typeArguments?: string[];
19
18
  }
19
+ export interface ArgumentsFilter {
20
+ arguments?: string[];
21
+ }
20
22
  declare class EventHandler {
21
23
  filters: EventFilter[];
22
- handler: (event: Event) => Promise<ProcessResult>;
24
+ handler: (event: EventInstance) => Promise<ProcessResult>;
23
25
  }
24
26
  declare class CallHandler {
25
27
  filters: CallFilter[];
26
28
  handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>;
27
29
  }
28
30
  export declare class AptosBaseProcessor {
29
- name: string;
31
+ readonly moduleName: string;
30
32
  config: IndexConfigure;
31
33
  eventHandlers: EventHandler[];
32
34
  callHandlers: CallHandler[];
33
- constructor(options: AptosBindOptions);
34
- static bind(options: AptosBindOptions): AptosBaseProcessor;
35
+ constructor(moduleName: string, options: AptosBindOptions);
35
36
  onTransaction(handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void): AptosBaseProcessor;
36
- onEvent(handler: (event: Event, ctx: AptosContext) => void, filter: EventFilter | EventFilter[]): AptosBaseProcessor;
37
+ onEvent(handler: (event: EventInstance, ctx: AptosContext) => void, filter: EventFilter | EventFilter[]): AptosBaseProcessor;
37
38
  onEntryFunctionCall(handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void, filter: CallFilter | CallFilter[]): AptosBaseProcessor;
38
39
  private configure;
39
40
  getChainId(): string;
41
+ loadTypes(registry: TypeRegistry): void;
42
+ protected loadTypesInternal(registry: TypeRegistry): void;
43
+ private decodeEvent;
44
+ private decodeFunctionPayload;
40
45
  }
41
46
  export {};
@@ -7,6 +7,8 @@ exports.AptosBaseProcessor = void 0;
7
7
  const _1 = require(".");
8
8
  const long_1 = __importDefault(require("long"));
9
9
  const chain_1 = require("../utils/chain");
10
+ const types_1 = require("./types");
11
+ const typegen_1 = require("../aptos-codegen/typegen");
10
12
  class EventHandler {
11
13
  filters;
12
14
  handler;
@@ -16,23 +18,24 @@ class CallHandler {
16
18
  handler;
17
19
  }
18
20
  class AptosBaseProcessor {
19
- name;
21
+ moduleName;
20
22
  config;
21
23
  eventHandlers = [];
22
24
  callHandlers = [];
23
- constructor(options) {
24
- this.name = options.name || options.address;
25
+ constructor(moduleName, options) {
26
+ this.moduleName = moduleName;
25
27
  this.configure(options);
26
28
  global.PROCESSOR_STATE.aptosProcessors.push(this);
27
29
  }
28
- static bind(options) {
29
- return new AptosBaseProcessor(options);
30
- }
30
+ // getABI(): MoveModule | undefined {
31
+ // return undefined
32
+ // }
31
33
  onTransaction(handler) {
32
34
  const address = this.config.address;
35
+ const moduleName = this.moduleName;
33
36
  this.callHandlers.push({
34
37
  handler: async function (tx) {
35
- const ctx = new _1.AptosContext(address, long_1.default.fromString(tx.version), tx);
38
+ const ctx = new _1.AptosContext(moduleName, address, long_1.default.fromString(tx.version), tx);
36
39
  if (tx) {
37
40
  handler(tx, ctx);
38
41
  }
@@ -54,12 +57,16 @@ class AptosBaseProcessor {
54
57
  else {
55
58
  _filters.push(filter);
56
59
  }
57
- const address = this.config.address;
60
+ // const address = this.config.address
61
+ // const moduleName = this.moduleName
62
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
63
+ const processor = this;
58
64
  this.eventHandlers.push({
59
65
  handler: async function (event) {
60
- const ctx = new _1.AptosContext(address, long_1.default.fromString(event.version));
66
+ const ctx = new _1.AptosContext(processor.moduleName, processor.config.address, long_1.default.fromString(event.version));
61
67
  if (event) {
62
- handler(event, ctx);
68
+ const decoded = processor.decodeEvent(event);
69
+ handler(decoded, ctx);
63
70
  }
64
71
  return {
65
72
  gauges: ctx.gauges,
@@ -79,13 +86,17 @@ class AptosBaseProcessor {
79
86
  else {
80
87
  _filters.push(filter);
81
88
  }
82
- const address = this.config.address;
89
+ // const address = this.config.address
90
+ // const moduleName = this.moduleName
91
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
92
+ const processor = this;
83
93
  this.callHandlers.push({
84
94
  handler: async function (tx) {
85
- const ctx = new _1.AptosContext(address, long_1.default.fromString(tx.version), tx);
95
+ const ctx = new _1.AptosContext(processor.moduleName, processor.config.address, long_1.default.fromString(tx.version), tx);
86
96
  if (tx) {
87
97
  const payload = tx.payload;
88
- handler(payload, ctx);
98
+ const decoded = processor.decodeFunctionPayload(payload);
99
+ handler(decoded, ctx);
89
100
  }
90
101
  return {
91
102
  gauges: ctx.gauges,
@@ -116,6 +127,47 @@ class AptosBaseProcessor {
116
127
  return chain_1.APTOS_MAINNET_ID;
117
128
  }
118
129
  }
130
+ loadTypes(registry) {
131
+ if (registry.contains(this.config.address, this.moduleName)) {
132
+ return;
133
+ }
134
+ this.loadTypesInternal(registry);
135
+ }
136
+ loadTypesInternal(registry) {
137
+ // should be override by subclass
138
+ }
139
+ decodeEvent(event) {
140
+ const registry = types_1.GLOBAL_TYPE_REGISTRY;
141
+ this.loadTypes(registry);
142
+ // TODO check if module is not loaded
143
+ let dataTyped = undefined;
144
+ try {
145
+ dataTyped = registry.decode(event.data, (0, typegen_1.parseMoveType)(event.type));
146
+ }
147
+ catch (e) {
148
+ console.warn('Decoding error for ', event.type);
149
+ return event;
150
+ }
151
+ return { ...event, data_typed: dataTyped };
152
+ }
153
+ decodeFunctionPayload(payload) {
154
+ const registry = types_1.GLOBAL_TYPE_REGISTRY;
155
+ this.loadTypes(registry);
156
+ const argumentsTyped = [];
157
+ try {
158
+ const func = registry.getMoveFunction(payload.function);
159
+ for (const [idx, arg] of payload.arguments.entries()) {
160
+ // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
161
+ const argType = (0, typegen_1.parseMoveType)(func.params[idx + 1]);
162
+ argumentsTyped.push(registry.decode(arg, argType));
163
+ }
164
+ }
165
+ catch (e) {
166
+ console.warn('Decoding error for ', payload.function);
167
+ return payload;
168
+ }
169
+ return { ...payload, arguments_typed: argumentsTyped };
170
+ }
119
171
  }
120
172
  exports.AptosBaseProcessor = AptosBaseProcessor;
121
173
  //# sourceMappingURL=aptos-processor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,wBAMU;AAGV,gDAAuB;AACvB,0CAAmE;AAoBnE,MAAM,YAAY;IAChB,OAAO,CAAe;IACtB,OAAO,CAA0C;CAClD;AAED,MAAM,WAAW;IACf,OAAO,CAAc;IACrB,OAAO,CAA+D;CACvE;AAED,MAAa,kBAAkB;IAC7B,IAAI,CAAQ;IACZ,MAAM,CAAgB;IACtB,aAAa,GAAmB,EAAE,CAAA;IAClC,YAAY,GAAkB,EAAE,CAAA;IAEhC,YAAY,OAAyB;QACnC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAA;QAC3C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QACvB,MAAM,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAyB;QACnC,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAA;IACxC,CAAC;IAEM,aAAa,CAClB,OAA8E;QAE9E,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAA;QACnC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YACrB,OAAO,EAAE,KAAK,WAAW,EAAE;gBACzB,MAAM,GAAG,GAAG,IAAI,eAAY,CAAC,OAAO,EAAE,cAAI,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;gBACtE,IAAI,EAAE,EAAE;oBACN,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;iBACjB;gBACD,OAAO;oBACL,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,QAAQ,EA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action,\n TransactionPayload_EntryFunctionPayload,\n} from '.'\nimport type { Event as OldEvent } from 'aptos/src/generated'\n\nimport Long from 'long'\nimport { APTOS_MAINNET_ID, APTOS_TESTNET_ID } from '../utils/chain'\n\nexport type Event = OldEvent & { version: string }\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: Long\n // endSeqNumber?: Long\n}\n\nexport interface EventFilter {\n type: string\n}\n\nexport interface CallFilter {\n function: string\n typeArguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: Event) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: CallFilter[]\n handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n name: string\n config: IndexConfigure\n eventHandlers: EventHandler[] = []\n callHandlers: CallHandler[] = []\n\n constructor(options: AptosBindOptions) {\n this.name = options.name || options.address\n this.configure(options)\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n static bind(options: AptosBindOptions): AptosBaseProcessor {\n return new AptosBaseProcessor(options)\n }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void\n ): AptosBaseProcessor {\n const address = this.config.address\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(address, Long.fromString(tx.version), tx)\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: Event, 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\n this.eventHandlers.push({\n handler: async function (event) {\n const ctx = new AptosContext(address, Long.fromString(event.version))\n if (event) {\n handler(event, 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 public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: CallFilter | CallFilter[]\n ): AptosBaseProcessor {\n let _filters: CallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const address = this.config.address\n\n this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(address, Long.fromString(tx.version), tx)\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n handler(payload, 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 switch (this.config.network) {\n case AptosNetwork.TEST_NET:\n return APTOS_TESTNET_ID\n case AptosNetwork.MAIN_NET:\n return APTOS_MAINNET_ID\n }\n }\n}\n"]}
1
+ {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,wBASU;AAEV,gDAAuB;AACvB,0CAAmE;AACnE,mCAA6D;AAC7D,sDAAwD;AAyBxD,MAAM,YAAY;IAChB,OAAO,CAAe;IACtB,OAAO,CAAkD;CAC1D;AAED,MAAM,WAAW;IACf,OAAO,CAAc;IACrB,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,CA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TransactionPayload_EntryFunctionPayload,\n TypedEntryFunctionPayload,\n TypedEventInstance,\n TypeRegistry,\n} from '.'\n\nimport Long from 'long'\nimport { APTOS_MAINNET_ID, APTOS_TESTNET_ID } from '../utils/chain'\nimport { EventInstance, GLOBAL_TYPE_REGISTRY } from './types'\nimport { parseMoveType } from '../aptos-codegen/typegen'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: Long\n // endSeqNumber?: Long\n}\n\nexport interface EventFilter extends ArgumentsFilter {\n type: string\n}\n\nexport interface CallFilter extends CallArgumentsFilter {\n function: string\n}\n\nexport interface CallArgumentsFilter extends ArgumentsFilter {\n typeArguments?: string[]\n}\n\nexport interface ArgumentsFilter {\n arguments?: string[]\n}\n\nclass EventHandler {\n filters: EventFilter[]\n handler: (event: EventInstance) => Promise<ProcessResult>\n}\n\nclass CallHandler {\n filters: CallFilter[]\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 this.callHandlers.push({\n handler: async function (tx) {\n const ctx = new AptosContext(moduleName, address, Long.fromString(tx.version), tx)\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 (event) {\n const ctx = new AptosContext(processor.moduleName, processor.config.address, Long.fromString(event.version))\n if (event) {\n const decoded = processor.decodeEvent(event)\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 public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: CallFilter | CallFilter[]\n ): AptosBaseProcessor {\n let _filters: CallFilter[] = []\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(processor.moduleName, processor.config.address, Long.fromString(tx.version), tx)\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 switch (this.config.network) {\n case AptosNetwork.TEST_NET:\n return APTOS_TESTNET_ID\n case AptosNetwork.MAIN_NET:\n return APTOS_MAINNET_ID\n }\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 let dataTyped = undefined\n try {\n dataTyped = registry.decode(event.data, parseMoveType(event.type))\n } catch (e) {\n console.warn('Decoding error for ', event.type)\n return event\n }\n\n return { ...event, data_typed: dataTyped } 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.warn('Decoding error for ', payload.function)\n return payload\n }\n\n return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>\n }\n}\n"]}
@@ -4,12 +4,6 @@ export declare enum AptosNetwork {
4
4
  TEST_NET = 1
5
5
  }
6
6
  export declare class AptosBindOptions {
7
- address: string;
8
- network?: AptosNetwork;
9
- name?: string;
10
- startVersion?: Long | number;
11
- }
12
- export declare class NamedAptosBindOptions {
13
7
  address: string;
14
8
  network?: AptosNetwork;
15
9
  startVersion?: Long | number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NamedAptosBindOptions = exports.AptosBindOptions = exports.AptosNetwork = void 0;
3
+ exports.AptosBindOptions = exports.AptosNetwork = void 0;
4
4
  var AptosNetwork;
5
5
  (function (AptosNetwork) {
6
6
  AptosNetwork[AptosNetwork["MAIN_NET"] = 0] = "MAIN_NET";
@@ -10,14 +10,7 @@ var AptosNetwork;
10
10
  class AptosBindOptions {
11
11
  address;
12
12
  network = AptosNetwork.TEST_NET;
13
- name;
14
13
  startVersion;
15
14
  }
16
15
  exports.AptosBindOptions = AptosBindOptions;
17
- class NamedAptosBindOptions {
18
- address;
19
- network = AptosNetwork.TEST_NET;
20
- startVersion;
21
- }
22
- exports.NamedAptosBindOptions = NamedAptosBindOptions;
23
16
  //# sourceMappingURL=bind-options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bind-options.js","sourceRoot":"","sources":["../../src/aptos/bind-options.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,WAAW;AACb,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED,MAAa,gBAAgB;IAC3B,OAAO,CAAQ;IACf,OAAO,GAAkB,YAAY,CAAC,QAAQ,CAAA;IAC9C,IAAI,CAAS;IACb,YAAY,CAAgB;CAE7B;AAND,4CAMC;AAED,MAAa,qBAAqB;IAChC,OAAO,CAAQ;IACf,OAAO,GAAkB,YAAY,CAAC,QAAQ,CAAA;IAC9C,YAAY,CAAgB;CAC7B;AAJD,sDAIC","sourcesContent":["import Long from 'long'\n\nexport enum AptosNetwork {\n MAIN_NET = 0,\n TEST_NET = 1,\n // DEV_NET,\n}\n\nexport class AptosBindOptions {\n address: string\n network?: AptosNetwork = AptosNetwork.TEST_NET\n name?: string\n startVersion?: Long | number\n // endBlock?: Long | number\n}\n\nexport class NamedAptosBindOptions {\n address: string\n network?: AptosNetwork = AptosNetwork.TEST_NET\n startVersion?: Long | number\n}\n"]}
1
+ {"version":3,"file":"bind-options.js","sourceRoot":"","sources":["../../src/aptos/bind-options.ts"],"names":[],"mappings":";;;AAEA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,WAAW;AACb,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED,MAAa,gBAAgB;IAC3B,OAAO,CAAQ;IACf,OAAO,GAAkB,YAAY,CAAC,QAAQ,CAAA;IAC9C,YAAY,CAAgB;CAE7B;AALD,4CAKC","sourcesContent":["import Long from 'long'\n\nexport enum AptosNetwork {\n MAIN_NET = 0,\n TEST_NET = 1,\n // DEV_NET,\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,12 +1,13 @@
1
1
  import Long from 'long';
2
- import { MetricDescriptor, RecordMetaData } from '../gen';
2
+ import { DataDescriptor, RecordMetaData } from '../gen';
3
3
  import { Labels } from '../core/metadata';
4
4
  import { BaseContext } from '../core/context';
5
5
  import { Transaction_UserTransaction } from './';
6
6
  export declare class AptosContext extends BaseContext {
7
7
  address: string;
8
- blockNumber: Long;
8
+ moduleName: string;
9
+ version: Long;
9
10
  transaction: Transaction_UserTransaction;
10
- constructor(address: string, slot: Long, transaction?: Transaction_UserTransaction);
11
- getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData;
11
+ constructor(moduleName: string, address: string, version: Long, transaction?: Transaction_UserTransaction);
12
+ getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
12
13
  }
@@ -6,25 +6,28 @@ const meter_1 = require("../core/meter");
6
6
  const context_1 = require("../core/context");
7
7
  class AptosContext extends context_1.BaseContext {
8
8
  address;
9
- blockNumber;
9
+ moduleName;
10
+ version;
10
11
  transaction;
11
- constructor(address, slot, transaction) {
12
+ constructor(moduleName, address, version, transaction) {
12
13
  super();
13
14
  this.address = address;
14
- this.blockNumber = slot;
15
+ this.moduleName = moduleName;
16
+ this.version = version;
15
17
  if (transaction) {
16
18
  this.transaction = transaction;
17
19
  }
18
20
  }
19
21
  getMetaData(descriptor, labels) {
20
22
  return {
21
- contractAddress: this.address,
22
- blockNumber: this.blockNumber,
23
+ address: this.address,
24
+ contractName: this.moduleName,
25
+ blockNumber: this.version,
23
26
  transactionIndex: 0,
24
27
  transactionHash: this.transaction?.hash || '',
25
28
  logIndex: 0,
26
29
  chainId: chain_1.APTOS_TESTNET_ID,
27
- descriptor: descriptor,
30
+ dataDescriptor: descriptor,
28
31
  labels: (0, meter_1.normalizeLabels)(labels),
29
32
  };
30
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";;;AAGA,0CAAiD;AACjD,yCAA+C;AAC/C,6CAA6C;AAG7C,MAAa,YAAa,SAAQ,qBAAW;IAC3C,OAAO,CAAQ;IACf,WAAW,CAAM;IACjB,WAAW,CAA6B;IAExC,YAAY,OAAe,EAAE,IAAU,EAAE,WAAyC;QAChF,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACvB,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,WAAW,CAAC,UAAwC,EAAE,MAAc;QAClE,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,OAAO;YAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;YAC7C,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,wBAAgB;YACzB,UAAU,EAAE,UAAU;YACtB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AA1BD,oCA0BC","sourcesContent":["import Long from 'long'\nimport { MetricDescriptor, RecordMetaData } from '../gen'\nimport { Labels } from '../core/metadata'\nimport { APTOS_TESTNET_ID } from '../utils/chain'\nimport { normalizeLabels } from '../core/meter'\nimport { BaseContext } from '../core/context'\nimport { Transaction_UserTransaction } from './'\n\nexport class AptosContext extends BaseContext {\n address: string\n blockNumber: Long\n transaction: Transaction_UserTransaction\n\n constructor(address: string, slot: Long, transaction?: Transaction_UserTransaction) {\n super()\n this.address = address\n this.blockNumber = slot\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData {\n return {\n contractAddress: this.address,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: APTOS_TESTNET_ID, // TODO set in context\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":";;;AAGA,0CAAiD;AACjD,yCAA+C;AAC/C,6CAA6C;AAG7C,MAAa,YAAa,SAAQ,qBAAW;IAC3C,OAAO,CAAQ;IACf,UAAU,CAAQ;IAClB,OAAO,CAAM;IACb,WAAW,CAA6B;IAExC,YAAY,UAAkB,EAAE,OAAe,EAAE,OAAa,EAAE,WAAyC;QACvG,KAAK,EAAE,CAAA;QACP,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,wBAAgB;YACzB,cAAc,EAAE,UAAU;YAC1B,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AA7BD,oCA6BC","sourcesContent":["import Long from 'long'\nimport { DataDescriptor, RecordMetaData } from '../gen'\nimport { Labels } from '../core/metadata'\nimport { APTOS_TESTNET_ID } from '../utils/chain'\nimport { normalizeLabels } from '../core/meter'\nimport { BaseContext } from '../core/context'\nimport { Transaction_UserTransaction } from './'\n\nexport class AptosContext extends BaseContext {\n address: string\n moduleName: string\n version: Long\n transaction: Transaction_UserTransaction\n\n constructor(moduleName: string, address: string, version: Long, transaction?: Transaction_UserTransaction) {\n super()\n this.address = address\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: APTOS_TESTNET_ID, // TODO set in context\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos/src/generated';
2
- export type { Event, CallFilter, EventFilter } from './aptos-processor';
2
+ export type { EventInstance, TypedEventInstance, TypeRegistry, TypedEntryFunctionPayload } from './types';
3
+ export type { CallFilter, EventFilter } from './aptos-processor';
3
4
  export { AptosBaseProcessor } from './aptos-processor';
4
5
  export { AptosContext } from './context';
5
- export { AptosBindOptions, NamedAptosBindOptions, AptosNetwork } from './bind-options';
6
+ export { AptosBindOptions, AptosNetwork } from './bind-options';
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AptosNetwork = exports.NamedAptosBindOptions = exports.AptosBindOptions = exports.AptosContext = exports.AptosBaseProcessor = void 0;
3
+ exports.AptosNetwork = exports.AptosBindOptions = exports.AptosContext = exports.AptosBaseProcessor = void 0;
4
4
  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
8
  var bind_options_1 = require("./bind-options");
9
9
  Object.defineProperty(exports, "AptosBindOptions", { enumerable: true, get: function () { return bind_options_1.AptosBindOptions; } });
10
- Object.defineProperty(exports, "NamedAptosBindOptions", { enumerable: true, get: function () { return bind_options_1.NamedAptosBindOptions; } });
11
10
  Object.defineProperty(exports, "AptosNetwork", { enumerable: true, get: function () { return bind_options_1.AptosNetwork; } });
12
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;AAEA,qDAAsD;AAA7C,qHAAA,kBAAkB,OAAA;AAC3B,qCAAwC;AAA/B,uGAAA,YAAY,OAAA;AACrB,+CAAsF;AAA7E,gHAAA,gBAAgB,OAAA;AAAE,qHAAA,qBAAqB,OAAA;AAAE,4GAAA,YAAY,OAAA","sourcesContent":["export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos/src/generated'\nexport type { Event, CallFilter, EventFilter } from './aptos-processor'\nexport { AptosBaseProcessor } from './aptos-processor'\nexport { AptosContext } from './context'\nexport { AptosBindOptions, NamedAptosBindOptions, 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,+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 { CallFilter, EventFilter } from './aptos-processor'\nexport { AptosBaseProcessor } from './aptos-processor'\nexport { AptosContext } from './context'\nexport { AptosBindOptions, AptosNetwork } from './bind-options'\n"]}
@@ -0,0 +1,2 @@
1
+ import { MoveStruct } from 'aptos/src/generated/models/MoveStruct';
2
+ export declare function decode<T>(struct: MoveStruct, args: any[]): T | undefined;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decode = void 0;
4
+ function decode(struct, args) {
5
+ if (args.length != struct.fields.length) {
6
+ console.log('type mismatch actually data for', struct.name);
7
+ return undefined;
8
+ }
9
+ const res = {};
10
+ for (const [i, field] of struct.fields.entries()) {
11
+ res[field.name] = args[i];
12
+ }
13
+ return res;
14
+ }
15
+ exports.decode = decode;
16
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,28 @@
1
+ import { Event, MoveFunction, MoveModule, MoveStruct, TransactionPayload_EntryFunctionPayload } from 'aptos/src/generated';
2
+ export declare type EventInstance = Event & {
3
+ version: string;
4
+ };
5
+ export declare type TypedEventInstance<T> = EventInstance & {
6
+ data_typed: T;
7
+ };
8
+ export declare type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
9
+ arguments_typed: T;
10
+ };
11
+ export declare class TypeDescriptor {
12
+ qname: string;
13
+ typeArgs: TypeDescriptor[];
14
+ constructor(symbol: string, typeParams?: TypeDescriptor[]);
15
+ applyArgs(ctx: Map<string, TypeDescriptor>): TypeDescriptor;
16
+ dependedTypes(): string[];
17
+ }
18
+ export declare class TypeRegistry {
19
+ moduleMapping: Map<string, MoveModule>;
20
+ typeMapping: Map<string, MoveStruct>;
21
+ funcMapping: Map<string, MoveFunction>;
22
+ contains(account: string, name: string): boolean;
23
+ load(module: MoveModule): void;
24
+ getMoveStruct(type: string): MoveStruct;
25
+ getMoveFunction(type: string): MoveFunction;
26
+ decode(data: any, type: TypeDescriptor): any;
27
+ }
28
+ export declare const GLOBAL_TYPE_REGISTRY: TypeRegistry;
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GLOBAL_TYPE_REGISTRY = exports.TypeRegistry = exports.TypeDescriptor = void 0;
4
+ const utils_1 = require("./utils");
5
+ const typegen_1 = require("../aptos-codegen/typegen");
6
+ class TypeDescriptor {
7
+ // type: string
8
+ // qualified name without type parameters
9
+ qname;
10
+ // account?: string
11
+ // module?: string
12
+ typeArgs;
13
+ constructor(symbol, typeParams) {
14
+ this.qname = symbol;
15
+ this.typeArgs = typeParams || [];
16
+ }
17
+ // Replace T0, T1 with more concrete type
18
+ applyArgs(ctx) {
19
+ const replace = ctx.get(this.qname);
20
+ if (replace) {
21
+ return replace;
22
+ }
23
+ if (ctx.size === 0 || this.typeArgs.length === 0) {
24
+ return this;
25
+ }
26
+ const typeArgs = [];
27
+ for (const arg of this.typeArgs) {
28
+ const replace = ctx.get(arg.qname);
29
+ if (replace) {
30
+ typeArgs.push(replace);
31
+ }
32
+ else {
33
+ typeArgs.push(arg.applyArgs(ctx));
34
+ }
35
+ }
36
+ return new TypeDescriptor(this.qname, typeArgs);
37
+ }
38
+ // all depended types including itself, not include system type
39
+ dependedTypes() {
40
+ if (this.qname.startsWith('&')) {
41
+ return [];
42
+ }
43
+ switch (this.qname) {
44
+ case 'signer':
45
+ case 'address':
46
+ case '0x1::string::String':
47
+ case 'bool':
48
+ case 'u8':
49
+ case 'u16':
50
+ case 'u32':
51
+ case 'u64':
52
+ case 'u128':
53
+ return [];
54
+ }
55
+ // Type parameters are not depended
56
+ if (this.qname.indexOf(utils_1.SPLITTER) == -1) {
57
+ if (this.qname.startsWith('T')) {
58
+ return [];
59
+ }
60
+ }
61
+ const types = new Set();
62
+ for (const param of this.typeArgs) {
63
+ param.dependedTypes().forEach((t) => types.add(t));
64
+ }
65
+ if (this.qname !== utils_1.VECTOR_STR) {
66
+ types.add(this.qname);
67
+ }
68
+ return Array.from(types);
69
+ }
70
+ }
71
+ exports.TypeDescriptor = TypeDescriptor;
72
+ class TypeRegistry {
73
+ moduleMapping = new Map();
74
+ typeMapping = new Map();
75
+ funcMapping = new Map();
76
+ contains(account, name) {
77
+ return this.moduleMapping.has(account + '::' + name);
78
+ }
79
+ load(module) {
80
+ if (this.contains(module.address, module.name)) {
81
+ return;
82
+ }
83
+ this.moduleMapping.set((0, utils_1.moduleQname)(module), module);
84
+ for (const struct of module.structs) {
85
+ // TODO move to util
86
+ const key = [module.address, module.name, struct.name].join(utils_1.SPLITTER);
87
+ this.typeMapping.set(key, struct);
88
+ }
89
+ for (const func of module.exposed_functions) {
90
+ if (!func.is_entry) {
91
+ continue;
92
+ }
93
+ const key = [module.address, module.name, func.name].join(utils_1.SPLITTER);
94
+ this.funcMapping.set(key, func);
95
+ }
96
+ }
97
+ getMoveStruct(type) {
98
+ const struct = this.typeMapping.get(type);
99
+ if (!struct) {
100
+ throw new Error('Failed to load type' + type);
101
+ }
102
+ return struct;
103
+ }
104
+ getMoveFunction(type) {
105
+ const func = this.funcMapping.get(type);
106
+ if (!func) {
107
+ throw new Error('Failed to load function' + type);
108
+ }
109
+ return func;
110
+ }
111
+ decode(data, type) {
112
+ // process simple type
113
+ if (type.qname.startsWith('&')) {
114
+ return data;
115
+ }
116
+ switch (type.qname) {
117
+ case 'signer': // TODO check this
118
+ case 'address':
119
+ case '0x1::string::String':
120
+ case 'bool':
121
+ case 'u8':
122
+ case 'u16':
123
+ case 'u32':
124
+ return data;
125
+ case 'u64':
126
+ case 'u128':
127
+ return BigInt(data);
128
+ }
129
+ // process vector
130
+ if (type.qname === utils_1.VECTOR_STR) {
131
+ // vector<u8> as hex string
132
+ if (type.typeArgs[0].qname === 'u8') {
133
+ return data;
134
+ }
135
+ const res = [];
136
+ for (const entry of data) {
137
+ res.push(this.decode(entry, type.typeArgs[0]));
138
+ }
139
+ return res;
140
+ }
141
+ // Process complex type
142
+ const struct = this.getMoveStruct(type.qname);
143
+ const typeCtx = new Map();
144
+ for (const [idx, typeArg] of type.typeArgs.entries()) {
145
+ typeCtx.set('T' + idx, typeArg);
146
+ }
147
+ const typedData = {};
148
+ for (const field of struct.fields) {
149
+ let filedType = (0, typegen_1.parseMoveType)(field.type);
150
+ filedType = filedType.applyArgs(typeCtx);
151
+ const value = this.decode(data[field.name], filedType);
152
+ typedData[field.name] = value;
153
+ }
154
+ return typedData;
155
+ }
156
+ }
157
+ exports.TypeRegistry = TypeRegistry;
158
+ exports.GLOBAL_TYPE_REGISTRY = new TypeRegistry();
159
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/aptos/types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AQ,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,SAAS,CAAC,OAAO,CAAC,CAAA;YACxC,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\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 // Replace T0, T1 with more concrete type\n applyArgs(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.applyArgs(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.applyArgs(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"]}
@@ -0,0 +1,6 @@
1
+ import { MoveModule } from 'aptos/src/generated';
2
+ export declare const SPLITTER = "::";
3
+ export declare const VECTOR_STR = "vector";
4
+ export declare function isFrameworkAccount(account: string): boolean;
5
+ export declare function moduleQname(module: MoveModule): string;
6
+ export declare function moduleQnameForType(type: string): [string, string];
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.moduleQnameForType = exports.moduleQname = exports.isFrameworkAccount = exports.VECTOR_STR = exports.SPLITTER = void 0;
4
+ exports.SPLITTER = '::';
5
+ exports.VECTOR_STR = 'vector';
6
+ function isFrameworkAccount(account) {
7
+ return account === '0x1' || account === '0x2' || account === '0x3';
8
+ }
9
+ exports.isFrameworkAccount = isFrameworkAccount;
10
+ function moduleQname(module) {
11
+ return module.address.toLowerCase() + exports.SPLITTER + module.name;
12
+ }
13
+ exports.moduleQname = moduleQname;
14
+ function moduleQnameForType(type) {
15
+ const parts = type.split(exports.SPLITTER).slice(0, 2);
16
+ return [parts[0], parts[1]];
17
+ }
18
+ exports.moduleQnameForType = moduleQnameForType;
19
+ //# sourceMappingURL=utils.js.map