@sentio/sdk 2.0.0-rc.3 → 2.0.0-rc.4
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.
- package/lib/builtin/eacaggregatorproxy/index.d.ts +3 -2
- package/lib/builtin/eacaggregatorproxy/index.js +3 -5
- package/lib/builtin/eacaggregatorproxy/index.js.map +1 -1
- package/lib/builtin/eacaggregatorproxy/test-utils.d.ts +1 -1
- package/lib/builtin/eacaggregatorproxy/test-utils.js +9 -16
- package/lib/builtin/eacaggregatorproxy/test-utils.js.map +1 -1
- package/lib/builtin/erc1155/index.d.ts +3 -2
- package/lib/builtin/erc1155/index.js +3 -5
- package/lib/builtin/erc1155/index.js.map +1 -1
- package/lib/builtin/erc1155/test-utils.d.ts +1 -1
- package/lib/builtin/erc1155/test-utils.js +9 -16
- package/lib/builtin/erc1155/test-utils.js.map +1 -1
- package/lib/builtin/erc20/index.d.ts +3 -2
- package/lib/builtin/erc20/index.js +3 -5
- package/lib/builtin/erc20/index.js.map +1 -1
- package/lib/builtin/erc20/test-utils.d.ts +1 -1
- package/lib/builtin/erc20/test-utils.js +7 -13
- package/lib/builtin/erc20/test-utils.js.map +1 -1
- package/lib/builtin/erc20bytes/index.d.ts +3 -2
- package/lib/builtin/erc20bytes/index.js +3 -5
- package/lib/builtin/erc20bytes/index.js.map +1 -1
- package/lib/builtin/erc20bytes/test-utils.d.ts +1 -1
- package/lib/builtin/erc20bytes/test-utils.js +5 -10
- package/lib/builtin/erc20bytes/test-utils.js.map +1 -1
- package/lib/builtin/erc721/index.d.ts +3 -2
- package/lib/builtin/erc721/index.js +3 -5
- package/lib/builtin/erc721/index.js.map +1 -1
- package/lib/builtin/erc721/test-utils.d.ts +1 -1
- package/lib/builtin/erc721/test-utils.js +7 -13
- package/lib/builtin/erc721/test-utils.js.map +1 -1
- package/lib/builtin/index.d.ts +8 -4
- package/lib/builtin/index.js +8 -8
- package/lib/builtin/index.js.map +1 -1
- package/lib/builtin/internal/EACAggregatorProxy.d.ts +1 -1
- package/lib/builtin/internal/EACAggregatorProxy.js +1 -2
- package/lib/builtin/internal/EACAggregatorProxy.js.map +1 -1
- package/lib/builtin/internal/ERC1155.d.ts +1 -1
- package/lib/builtin/internal/ERC1155.js +1 -2
- package/lib/builtin/internal/ERC1155.js.map +1 -1
- package/lib/builtin/internal/ERC20.d.ts +1 -1
- package/lib/builtin/internal/ERC20.js +1 -2
- package/lib/builtin/internal/ERC20.js.map +1 -1
- package/lib/builtin/internal/ERC20Bytes.d.ts +1 -1
- package/lib/builtin/internal/ERC20Bytes.js +1 -2
- package/lib/builtin/internal/ERC20Bytes.js.map +1 -1
- package/lib/builtin/internal/ERC721.d.ts +1 -1
- package/lib/builtin/internal/ERC721.js +1 -2
- package/lib/builtin/internal/ERC721.js.map +1 -1
- package/lib/builtin/internal/WETH9.d.ts +1 -1
- package/lib/builtin/internal/WETH9.js +1 -2
- package/lib/builtin/internal/WETH9.js.map +1 -1
- package/lib/builtin/internal/common.js +1 -2
- package/lib/builtin/internal/common.js.map +1 -1
- package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +6 -6
- package/lib/builtin/internal/eacaggregatorproxy_processor.js +69 -77
- package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
- package/lib/builtin/internal/erc1155_processor.d.ts +6 -6
- package/lib/builtin/internal/erc1155_processor.js +30 -38
- package/lib/builtin/internal/erc1155_processor.js.map +1 -1
- package/lib/builtin/internal/erc20_processor.d.ts +5 -5
- package/lib/builtin/internal/erc20_processor.js +39 -47
- package/lib/builtin/internal/erc20_processor.js.map +1 -1
- package/lib/builtin/internal/erc20bytes_processor.d.ts +4 -4
- package/lib/builtin/internal/erc20bytes_processor.js +33 -41
- package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
- package/lib/builtin/internal/erc721_processor.d.ts +5 -5
- package/lib/builtin/internal/erc721_processor.js +42 -50
- package/lib/builtin/internal/erc721_processor.js.map +1 -1
- package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js +4 -8
- package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js.map +1 -1
- package/lib/builtin/internal/factories/ERC1155__factory.js +4 -8
- package/lib/builtin/internal/factories/ERC1155__factory.js.map +1 -1
- package/lib/builtin/internal/factories/ERC20Bytes__factory.js +4 -8
- package/lib/builtin/internal/factories/ERC20Bytes__factory.js.map +1 -1
- package/lib/builtin/internal/factories/ERC20__factory.js +4 -8
- package/lib/builtin/internal/factories/ERC20__factory.js.map +1 -1
- package/lib/builtin/internal/factories/ERC721__factory.js +4 -8
- package/lib/builtin/internal/factories/ERC721__factory.js.map +1 -1
- package/lib/builtin/internal/factories/WETH9__factory.js +4 -8
- package/lib/builtin/internal/factories/WETH9__factory.js.map +1 -1
- package/lib/builtin/internal/factories/index.d.ts +6 -6
- package/lib/builtin/internal/factories/index.js +6 -15
- package/lib/builtin/internal/factories/index.js.map +1 -1
- package/lib/builtin/internal/index.d.ts +13 -13
- package/lib/builtin/internal/index.js +7 -17
- package/lib/builtin/internal/index.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.d.ts +6 -6
- package/lib/builtin/internal/weth9_processor.js +33 -41
- package/lib/builtin/internal/weth9_processor.js.map +1 -1
- package/lib/builtin/weth9/index.d.ts +3 -2
- package/lib/builtin/weth9/index.js +3 -5
- package/lib/builtin/weth9/index.js.map +1 -1
- package/lib/builtin/weth9/test-utils.d.ts +1 -1
- package/lib/builtin/weth9/test-utils.js +9 -16
- package/lib/builtin/weth9/test-utils.js.map +1 -1
- package/lib/core/base-context.d.ts +4 -4
- package/lib/core/base-context.js +7 -11
- package/lib/core/base-context.js.map +1 -1
- package/lib/core/big-decimal.js +3 -7
- package/lib/core/big-decimal.js.map +1 -1
- package/lib/core/bind-options.js +6 -13
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +5 -5
- package/lib/core/context.js +14 -23
- package/lib/core/context.js.map +1 -1
- package/lib/core/core-plugin.js +9 -13
- package/lib/core/core-plugin.js.map +1 -1
- package/lib/core/event-tracker.d.ts +2 -2
- package/lib/core/event-tracker.js +6 -13
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +2 -2
- package/lib/core/exporter.js +4 -9
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/index.d.ts +12 -9
- package/lib/core/index.js +12 -32
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +2 -2
- package/lib/core/logger.js +7 -11
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +4 -0
- package/lib/core/metadata.js +21 -7
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +3 -7
- package/lib/core/meter.js +22 -57
- package/lib/core/meter.js.map +1 -1
- package/lib/core/meter.test.js.map +1 -1
- package/lib/core/numberish.d.ts +1 -1
- package/lib/core/numberish.js +12 -18
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/numberish.test.js.map +1 -1
- package/lib/core/sui-plugin.js +12 -16
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/core/sui-processor.d.ts +1 -1
- package/lib/core/sui-processor.js +6 -12
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/error.d.ts +1 -1
- package/lib/error.js +2 -7
- package/lib/error.js.map +1 -1
- package/lib/eth/account-processor-state.d.ts +1 -1
- package/lib/eth/account-processor-state.js +2 -6
- package/lib/eth/account-processor-state.js.map +1 -1
- package/lib/eth/account-processor.d.ts +7 -7
- package/lib/eth/account-processor.js +23 -27
- package/lib/eth/account-processor.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +5 -5
- package/lib/eth/base-processor-template.js +8 -14
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +4 -4
- package/lib/eth/base-processor.js +19 -26
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/binds.d.ts +3 -3
- package/lib/eth/binds.js +11 -19
- package/lib/eth/binds.js.map +1 -1
- package/lib/eth/eth-plugin.js +30 -34
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/generic-processor.d.ts +3 -3
- package/lib/eth/generic-processor.js +9 -13
- package/lib/eth/generic-processor.js.map +1 -1
- package/lib/{core → eth}/generic-processor.test.d.ts +0 -0
- package/lib/eth/generic-processor.test.js.map +1 -0
- package/lib/eth/index.d.ts +7 -6
- package/lib/eth/index.js +6 -14
- package/lib/eth/index.js.map +1 -1
- package/lib/eth/provider.js +12 -17
- package/lib/eth/provider.js.map +1 -1
- package/lib/eth/trace.js +1 -2
- package/lib/eth/trace.js.map +1 -1
- package/lib/index.d.ts +4 -5
- package/lib/index.js +5 -16
- package/lib/index.js.map +1 -1
- package/lib/promise-or-void.js +1 -2
- package/lib/target-ethers-sentio/{event-handler.js → event-handler.cjs} +4 -4
- package/lib/target-ethers-sentio/event-handler.cjs.map +1 -0
- package/lib/target-ethers-sentio/{event-handler.d.ts → event-handler.d.cts} +0 -0
- package/lib/target-ethers-sentio/{file.js → file.cjs} +19 -18
- package/lib/target-ethers-sentio/file.cjs.map +1 -0
- package/lib/target-ethers-sentio/{file.d.ts → file.d.cts} +0 -0
- package/lib/target-ethers-sentio/{functions-handler.js → functions-handler.cjs} +6 -7
- package/lib/target-ethers-sentio/functions-handler.cjs.map +1 -0
- package/lib/target-ethers-sentio/{functions-handler.d.ts → functions-handler.d.cts} +0 -0
- package/lib/target-ethers-sentio/{index.js → index.cjs} +8 -5
- package/lib/target-ethers-sentio/index.cjs.map +1 -0
- package/lib/target-ethers-sentio/{index.d.ts → index.d.cts} +0 -0
- package/lib/target-ethers-sentio/{types.js → types.cjs} +1 -1
- package/lib/target-ethers-sentio/types.cjs.map +1 -0
- package/lib/target-ethers-sentio/{types.d.ts → types.d.cts} +0 -0
- package/lib/target-ethers-sentio/{view-function.js → view-function.cjs} +5 -5
- package/lib/target-ethers-sentio/view-function.cjs.map +1 -0
- package/lib/target-ethers-sentio/{view-function.d.ts → view-function.d.cts} +0 -0
- package/lib/testing/index.d.ts +3 -2
- package/lib/testing/index.js +3 -10
- package/lib/testing/index.js.map +1 -1
- package/lib/testing/metric-utils.d.ts +1 -1
- package/lib/testing/metric-utils.js +7 -13
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +3 -4
- package/lib/testing/test-processor-server.js +24 -29
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +5 -9
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/tsup.config.ts +23 -0
- package/lib/utils/chain.js +7 -12
- package/lib/utils/chain.js.map +1 -1
- package/lib/utils/conversion.d.ts +2 -2
- package/lib/utils/conversion.js +6 -12
- package/lib/utils/conversion.js.map +1 -1
- package/lib/utils/dex-price.js +14 -19
- package/lib/utils/dex-price.js.map +1 -1
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/lib/utils/index.d.ts +4 -4
- package/lib/utils/index.js +4 -8
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/price.d.ts +11 -11
- package/lib/utils/price.js +10 -16
- package/lib/utils/price.js.map +1 -1
- package/lib/utils/token.d.ts +1 -1
- package/lib/utils/token.js +15 -21
- package/lib/utils/token.js.map +1 -1
- package/package.json +23 -19
- package/src/builtin/eacaggregatorproxy/index.ts +3 -2
- package/src/builtin/eacaggregatorproxy/test-utils.ts +1 -1
- package/src/builtin/erc1155/index.ts +3 -2
- package/src/builtin/erc1155/test-utils.ts +1 -1
- package/src/builtin/erc20/index.ts +3 -2
- package/src/builtin/erc20/test-utils.ts +1 -1
- package/src/builtin/erc20bytes/index.ts +3 -2
- package/src/builtin/erc20bytes/test-utils.ts +1 -1
- package/src/builtin/erc721/index.ts +3 -2
- package/src/builtin/erc721/test-utils.ts +1 -1
- package/src/builtin/index.ts +8 -4
- package/src/builtin/internal/EACAggregatorProxy.ts +1 -1
- package/src/builtin/internal/ERC1155.ts +1 -1
- package/src/builtin/internal/ERC20.ts +1 -1
- package/src/builtin/internal/ERC20Bytes.ts +1 -1
- package/src/builtin/internal/ERC721.ts +1 -1
- package/src/builtin/internal/WETH9.ts +1 -1
- package/src/builtin/internal/eacaggregatorproxy_processor.ts +2 -2
- package/src/builtin/internal/erc1155_processor.ts +2 -2
- package/src/builtin/internal/erc20_processor.ts +2 -2
- package/src/builtin/internal/erc20bytes_processor.ts +2 -2
- package/src/builtin/internal/erc721_processor.ts +2 -2
- package/src/builtin/internal/factories/index.ts +6 -6
- package/src/builtin/internal/index.ts +13 -13
- package/src/builtin/internal/weth9_processor.ts +2 -2
- package/src/builtin/weth9/index.ts +3 -2
- package/src/builtin/weth9/test-utils.ts +1 -1
- package/src/core/base-context.ts +4 -4
- package/src/core/context.ts +5 -6
- package/src/core/core-plugin.ts +3 -3
- package/src/core/event-tracker.ts +2 -2
- package/src/core/exporter.ts +3 -3
- package/src/core/index.ts +12 -9
- package/src/core/logger.ts +2 -2
- package/src/core/metadata.ts +23 -2
- package/src/core/meter.ts +3 -26
- package/src/core/numberish.ts +1 -1
- package/src/core/sui-plugin.ts +2 -2
- package/src/core/sui-processor.ts +1 -1
- package/src/error.ts +1 -1
- package/src/eth/account-processor-state.ts +1 -1
- package/src/eth/account-processor.ts +11 -11
- package/src/eth/base-processor-template.ts +5 -5
- package/src/eth/base-processor.ts +4 -4
- package/src/eth/binds.ts +3 -3
- package/src/eth/eth-plugin.ts +3 -3
- package/src/eth/generic-processor.ts +5 -5
- package/src/eth/index.ts +8 -6
- package/src/index.ts +4 -6
- package/src/target-ethers-sentio/{event-handler.ts → event-handler.cts} +1 -1
- package/src/target-ethers-sentio/{file.ts → file.cts} +10 -9
- package/src/target-ethers-sentio/{functions-handler.ts → functions-handler.cts} +3 -4
- package/src/target-ethers-sentio/{index.ts → index.cts} +4 -1
- package/src/target-ethers-sentio/tsconfig.json +1 -1
- package/src/target-ethers-sentio/{types.ts → types.cts} +0 -0
- package/src/target-ethers-sentio/{view-function.ts → view-function.cts} +1 -1
- package/src/testing/index.ts +3 -3
- package/src/testing/metric-utils.ts +2 -2
- package/src/testing/test-processor-server.ts +5 -5
- package/src/testing/test-provider.ts +1 -1
- package/src/tsup.config.ts +23 -0
- package/src/utils/conversion.ts +2 -2
- package/src/utils/dex-price.ts +4 -4
- package/src/utils/index.ts +4 -4
- package/src/utils/price.ts +1 -1
- package/src/utils/token.ts +6 -6
- package/lib/core/generic-processor.test.js.map +0 -1
- package/lib/target-ethers-sentio/event-handler.js.map +0 -1
- package/lib/target-ethers-sentio/file.js.map +0 -1
- package/lib/target-ethers-sentio/functions-handler.js.map +0 -1
- package/lib/target-ethers-sentio/index.js.map +0 -1
- package/lib/target-ethers-sentio/types.js.map +0 -1
- package/lib/target-ethers-sentio/view-function.js.map +0 -1
- package/lib/webpack.config.js +0 -50
- package/src/webpack.config.js +0 -50
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const context_1 = require("./context");
|
|
5
|
-
const runtime_1 = require("@sentio/runtime");
|
|
6
|
-
class SuiBindOptions {
|
|
1
|
+
import { SuiContext } from './context.js';
|
|
2
|
+
import { ListStateStorage } from '@sentio/runtime';
|
|
3
|
+
export class SuiBindOptions {
|
|
7
4
|
address;
|
|
8
5
|
// network?: Networkish = 1
|
|
9
6
|
// name?: string
|
|
10
7
|
startBlock;
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
class SuiProcessorState extends runtime_1.ListStateStorage {
|
|
9
|
+
export class SuiProcessorState extends ListStateStorage {
|
|
14
10
|
static INSTANCE = new SuiProcessorState();
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
class SuiBaseProcessor {
|
|
12
|
+
export class SuiBaseProcessor {
|
|
18
13
|
transactionHanlder;
|
|
19
14
|
address;
|
|
20
15
|
config = { startSeqNumber: 0n };
|
|
@@ -30,7 +25,7 @@ class SuiBaseProcessor {
|
|
|
30
25
|
return this;
|
|
31
26
|
}
|
|
32
27
|
handleTransaction(txn, slot) {
|
|
33
|
-
const ctx = new
|
|
28
|
+
const ctx = new SuiContext(this.address, slot);
|
|
34
29
|
if (txn) {
|
|
35
30
|
this.transactionHanlder(txn, ctx);
|
|
36
31
|
}
|
|
@@ -45,5 +40,4 @@ class SuiBaseProcessor {
|
|
|
45
40
|
return this;
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
|
-
exports.SuiBaseProcessor = SuiBaseProcessor;
|
|
49
43
|
//# sourceMappingURL=sui-processor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAOlD,MAAM,OAAO,cAAc;IACzB,OAAO,CAAQ;IACf,2BAA2B;IAC3B,gBAAgB;IAChB,UAAU,CAAkB;CAE7B;AAED,MAAM,OAAO,iBAAkB,SAAQ,gBAAkC;IACvE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;AAG3C,MAAM,OAAO,gBAAgB;IACpB,kBAAkB,CAA6C;IACtE,OAAO,CAAQ;IACf,MAAM,GAAmB,EAAE,cAAc,EAAE,EAAE,EAAE,CAAA;IAE/C,YAAY,IAAY,EAAE,OAAuB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SACnC;QACD,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3C,CAAC;IAEM,aAAa,CAAC,OAAoD;QACvE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,iBAAiB,CAAC,GAAQ,EAAE,IAAY;QAC7C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAE9C,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SAClC;QACD,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC/B,CAAC;IAEM,SAAS,CAAC,SAA0B;QACzC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;QAC9C,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAyB;QACvC,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { SuiContext } from './context.js'\nimport { ProcessResult } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\n\ntype IndexConfigure = {\n startSeqNumber: bigint\n endSeqNumber?: bigint\n}\n\nexport class SuiBindOptions {\n address: string\n // network?: Networkish = 1\n // name?: string\n startBlock?: bigint | number\n // endBlock?: Long | number\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: 0n }\n\n constructor(name: string, options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n this.transactionHanlder = handler\n return this\n }\n\n public handleTransaction(txn: any, slot: bigint): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return ctx.getProcessResult()\n }\n\n public startSlot(startSlot: bigint | number) {\n this.config.startSeqNumber = BigInt(startSlot)\n return this\n }\n\n public endBlock(endBlock: bigint | number) {\n this.config.endSeqNumber = BigInt(endBlock)\n return this\n }\n}\n"]}
|
package/lib/error.d.ts
CHANGED
package/lib/error.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformEtherError = exports.EthersError = void 0;
|
|
4
1
|
// import { errors } from 'ethers/providers'
|
|
5
|
-
class EthersError extends Error {
|
|
2
|
+
export class EthersError extends Error {
|
|
6
3
|
e;
|
|
7
4
|
constructor(message, e) {
|
|
8
5
|
super(message);
|
|
@@ -12,8 +9,7 @@ class EthersError extends Error {
|
|
|
12
9
|
return this.message + '\n' + this.stack?.toString();
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
function transformEtherError(e, ctx) {
|
|
12
|
+
export function transformEtherError(e, ctx) {
|
|
17
13
|
let msg = '';
|
|
18
14
|
// @ts-ignore expected error fields
|
|
19
15
|
if (e.code === errors.CALL_EXCEPTION) {
|
|
@@ -39,5 +35,4 @@ function transformEtherError(e, ctx) {
|
|
|
39
35
|
msg = 'ethers call error\n' + e.message + '\n' + e.stack?.toString();
|
|
40
36
|
return new Error(msg);
|
|
41
37
|
}
|
|
42
|
-
exports.transformEtherError = transformEtherError;
|
|
43
38
|
//# sourceMappingURL=error.js.map
|
package/lib/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAEA,4CAA4C;AAE5C,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,CAAC,CAAO;IAER,YAAY,OAAe,EAAE,CAAQ;QACnC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;IACtB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACrD,CAAC;CACF;AAED,MAAM,UAAU,mBAAmB,CAAC,CAAQ,EAAE,GAA0C;IACtF,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,mCAAmC;IACnC,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,cAAc,EAAE;QACpC,mCAAmC;QACnC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;YACnB,IAAI,GAAG,EAAE;gBACP,GAAG;oBACD,sEAAsE;wBACtE,GAAG,CAAC,OAAO;wBACX,IAAI;wBACJ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACpB;iBAAM;gBACL,GAAG,GAAG,8DAA8D,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACzF;SACF;QACD,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;KAC/B;IAED,IAAI,CAAC,YAAY,WAAW,EAAE;QAC5B,OAAO,CAAC,CAAA;KACT;IAED,qCAAqC;IAErC,GAAG,GAAG,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACpE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC","sourcesContent":["// Transform error in more readable format\nimport { ContractContext } from './core/context.js'\n// import { errors } from 'ethers/providers'\n\nexport class EthersError extends Error {\n e: Error\n\n constructor(message: string, e: Error) {\n super(message)\n this.stack = e.stack\n }\n\n toString() {\n return this.message + '\\n' + this.stack?.toString()\n }\n}\n\nexport function transformEtherError(e: Error, ctx: ContractContext<any, any> | undefined): Error {\n let msg = ''\n // @ts-ignore expected error fields\n if (e.code === errors.CALL_EXCEPTION) {\n // @ts-ignore expected error fields\n if (e.data === '0x') {\n if (ctx) {\n msg =\n \"jsonrpc eth_call return '0x' (likely contract not existed) at chain \" +\n ctx.chainId +\n ': ' +\n JSON.stringify(e)\n } else {\n msg = \"jsonrpc eth_call return '0x' (likely contract not existed): \" + JSON.stringify(e)\n }\n }\n return new EthersError(msg, e)\n }\n\n if (e instanceof EthersError) {\n return e\n }\n\n // TODO gracefully handle more errors\n\n msg = 'ethers call error\\n' + e.message + '\\n' + e.stack?.toString()\n return new Error(msg)\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ListStateStorage } from '@sentio/runtime';
|
|
2
|
-
import { AccountProcessor } from './account-processor';
|
|
2
|
+
import { AccountProcessor } from './account-processor.js';
|
|
3
3
|
export declare class AccountProcessorState extends ListStateStorage<AccountProcessor> {
|
|
4
4
|
static INSTANCE: AccountProcessorState;
|
|
5
5
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.AccountProcessorState = void 0;
|
|
4
|
-
const runtime_1 = require("@sentio/runtime");
|
|
5
|
-
class AccountProcessorState extends runtime_1.ListStateStorage {
|
|
1
|
+
import { ListStateStorage } from '@sentio/runtime';
|
|
2
|
+
export class AccountProcessorState extends ListStateStorage {
|
|
6
3
|
static INSTANCE = new AccountProcessorState();
|
|
7
4
|
}
|
|
8
|
-
exports.AccountProcessorState = AccountProcessorState;
|
|
9
5
|
//# sourceMappingURL=account-processor-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-processor-state.js","sourceRoot":"","sources":["../../src/eth/account-processor-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account-processor-state.js","sourceRoot":"","sources":["../../src/eth/account-processor-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD,MAAM,OAAO,qBAAsB,SAAQ,gBAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA","sourcesContent":["import { ListStateStorage } from '@sentio/runtime'\nimport { AccountProcessor } from './account-processor.js'\n\nexport class AccountProcessorState extends ListStateStorage<AccountProcessor> {\n static INSTANCE = new AccountProcessorState()\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { EthFetchConfig } from '@sentio/
|
|
2
|
-
import { AccountBindOptions } from '../core/bind-options';
|
|
3
|
-
import { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20';
|
|
4
|
-
import { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721';
|
|
5
|
-
import { AccountContext } from '../core/context';
|
|
6
|
-
import { PromiseOrVoid } from '../promise-or-void';
|
|
7
|
-
import { AddressOrTypeEventFilter, EventsHandler } from './base-processor';
|
|
1
|
+
import { EthFetchConfig } from '@sentio/protos';
|
|
2
|
+
import { AccountBindOptions } from '../core/bind-options.js';
|
|
3
|
+
import { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20.js';
|
|
4
|
+
import { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721.js';
|
|
5
|
+
import { AccountContext } from '../core/context.js';
|
|
6
|
+
import { PromiseOrVoid } from '../promise-or-void.js';
|
|
7
|
+
import { AddressOrTypeEventFilter, EventsHandler } from './base-processor.js';
|
|
8
8
|
import { LogDescription } from 'ethers';
|
|
9
9
|
export declare class AccountProcessor {
|
|
10
10
|
config: AccountBindOptions;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const ERC20_INTERFACE = internal_1.ERC20__factory.createInterface();
|
|
12
|
-
const ERC721_INTERFACE = internal_1.ERC721__factory.createInterface();
|
|
13
|
-
class AccountProcessor {
|
|
1
|
+
import { ERC20__factory, ERC721__factory } from '../builtin/internal/index.js';
|
|
2
|
+
import { AddressType, EthFetchConfig, ProcessResult } from '@sentio/protos';
|
|
3
|
+
import { Network } from 'ethers/providers';
|
|
4
|
+
import { ERC20Processor } from '../builtin/internal/erc20_processor.js';
|
|
5
|
+
import { ERC721Processor } from '../builtin/internal/erc721_processor.js';
|
|
6
|
+
import { AccountContext } from '../core/context.js';
|
|
7
|
+
import { AccountProcessorState } from './account-processor-state.js';
|
|
8
|
+
const ERC20_INTERFACE = ERC20__factory.createInterface();
|
|
9
|
+
const ERC721_INTERFACE = ERC721__factory.createInterface();
|
|
10
|
+
export class AccountProcessor {
|
|
14
11
|
config;
|
|
15
12
|
eventHandlers = [];
|
|
16
13
|
static bind(config) {
|
|
17
14
|
const processor = new AccountProcessor(config);
|
|
18
|
-
|
|
15
|
+
AccountProcessorState.INSTANCE.addValue(processor);
|
|
19
16
|
return processor;
|
|
20
17
|
}
|
|
21
18
|
constructor(config) {
|
|
@@ -28,7 +25,7 @@ class AccountProcessor {
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
getChainId() {
|
|
31
|
-
return Number(
|
|
28
|
+
return Number(Network.from(this.config.network || 1).chainId);
|
|
32
29
|
}
|
|
33
30
|
/**
|
|
34
31
|
* Register custom handler function to process erc20 transfer event to this account
|
|
@@ -37,7 +34,7 @@ class AccountProcessor {
|
|
|
37
34
|
* @param fetchConfig
|
|
38
35
|
*/
|
|
39
36
|
onERC20TransferIn(handler, tokensAddresses = [], fetchConfig) {
|
|
40
|
-
return this.onERC20(handler, tokensAddresses, (address) =>
|
|
37
|
+
return this.onERC20(handler, tokensAddresses, (address) => ERC721Processor.filters.Transfer(null, this.config.address), fetchConfig);
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
43
40
|
* Register custom handler function to process erc20 transfer event from this account
|
|
@@ -46,7 +43,7 @@ class AccountProcessor {
|
|
|
46
43
|
* @param fetchConfig
|
|
47
44
|
*/
|
|
48
45
|
onERC20TransferOut(handler, tokensAddresses = [], fetchConfig) {
|
|
49
|
-
return this.onERC20(handler, tokensAddresses, (address) =>
|
|
46
|
+
return this.onERC20(handler, tokensAddresses, (address) => ERC20Processor.filters.Transfer(this.config.address), fetchConfig);
|
|
50
47
|
}
|
|
51
48
|
/**
|
|
52
49
|
* Register custom handler function to process erc20 mint for this account
|
|
@@ -55,10 +52,10 @@ class AccountProcessor {
|
|
|
55
52
|
* @param fetchConfig
|
|
56
53
|
*/
|
|
57
54
|
onERC20Minted(handler, tokensAddresses = [], fetchConfig) {
|
|
58
|
-
return this.onERC20(handler, tokensAddresses, (address) =>
|
|
55
|
+
return this.onERC20(handler, tokensAddresses, (address) => ERC20Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address), fetchConfig);
|
|
59
56
|
}
|
|
60
57
|
onERC20(handler, tokensAddresses = [], defaultFilter, fetchConfig) {
|
|
61
|
-
return this.onERC(handler, tokensAddresses, defaultFilter,
|
|
58
|
+
return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20, fetchConfig);
|
|
62
59
|
}
|
|
63
60
|
/**
|
|
64
61
|
* Register custom handler function to process ERC721 transfer event to this account
|
|
@@ -67,7 +64,7 @@ class AccountProcessor {
|
|
|
67
64
|
* @param fetchConfig
|
|
68
65
|
*/
|
|
69
66
|
onERC721TransferIn(handler, collections, fetchConfig) {
|
|
70
|
-
return this.onERC721(handler, collections, (address) =>
|
|
67
|
+
return this.onERC721(handler, collections, (address) => ERC721Processor.filters.Transfer(null, this.config.address), fetchConfig);
|
|
71
68
|
}
|
|
72
69
|
/**
|
|
73
70
|
* Register custom handler function to process ERC721 transfer event from this account
|
|
@@ -76,7 +73,7 @@ class AccountProcessor {
|
|
|
76
73
|
* @param fetchConfig
|
|
77
74
|
*/
|
|
78
75
|
onERC721TransferOut(handler, collections, fetchConfig) {
|
|
79
|
-
return this.onERC721(handler, collections, (address) =>
|
|
76
|
+
return this.onERC721(handler, collections, (address) => ERC721Processor.filters.Transfer(this.config.address), fetchConfig);
|
|
80
77
|
}
|
|
81
78
|
/**
|
|
82
79
|
* Register custom handler function to process ERC721 mint for this account
|
|
@@ -85,10 +82,10 @@ class AccountProcessor {
|
|
|
85
82
|
* @param fetchConfig
|
|
86
83
|
*/
|
|
87
84
|
onERC721Minted(handler, collections = [], fetchConfig) {
|
|
88
|
-
return this.onERC721(handler, collections, (address) =>
|
|
85
|
+
return this.onERC721(handler, collections, (address) => ERC721Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address), fetchConfig);
|
|
89
86
|
}
|
|
90
87
|
onERC721(handler, collections, defaultFilter, fetchConfig) {
|
|
91
|
-
return this.onERC(handler, collections, defaultFilter,
|
|
88
|
+
return this.onERC(handler, collections, defaultFilter, AddressType.ERC721, fetchConfig);
|
|
92
89
|
}
|
|
93
90
|
onERC(handler, contractAddresses, defaultFilter, addressType, fetchConfig) {
|
|
94
91
|
const filters = [];
|
|
@@ -132,20 +129,19 @@ class AccountProcessor {
|
|
|
132
129
|
const config = this.config;
|
|
133
130
|
this.eventHandlers.push({
|
|
134
131
|
filters: _filters,
|
|
135
|
-
fetchConfig: fetchConfig ||
|
|
132
|
+
fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
|
|
136
133
|
handler: async function (data) {
|
|
137
134
|
const log = data.log;
|
|
138
|
-
const ctx = new
|
|
135
|
+
const ctx = new AccountContext(chainId, config.address, data.timestamp, data.block, log, undefined, data.transaction, data.transactionReceipt);
|
|
139
136
|
const parsed = ERC20_INTERFACE.parseLog(log);
|
|
140
137
|
if (parsed) {
|
|
141
138
|
await handler(parsed, ctx);
|
|
142
139
|
return ctx.getProcessResult();
|
|
143
140
|
}
|
|
144
|
-
return
|
|
141
|
+
return ProcessResult.fromPartial({});
|
|
145
142
|
},
|
|
146
143
|
});
|
|
147
144
|
return this;
|
|
148
145
|
}
|
|
149
146
|
}
|
|
150
|
-
exports.AccountProcessor = AccountProcessor;
|
|
151
147
|
//# sourceMappingURL=account-processor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-processor.js","sourceRoot":"","sources":["../../src/eth/account-processor.ts"],"names":[],"mappings":";;;AAAA,kDAAqE;AACrE,qCAAuF;AAGvF,gDAAqD;AAKrD,yEAAoE;AACpE,2EAAsE;AAEtE,6CAAgD;AAIhD,uEAAiE;AAEjE,MAAM,eAAe,GAAG,yBAAc,CAAC,eAAe,EAAE,CAAA;AACxD,MAAM,gBAAgB,GAAG,0BAAe,CAAC,eAAe,EAAE,CAAA;AAE1D,MAAa,gBAAgB;IAC3B,MAAM,CAAoB;IAC1B,aAAa,GAAoB,EAAE,CAAA;IAEnC,MAAM,CAAC,IAAI,CAAC,MAA0B;QACpC,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC9C,+CAAqB,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAClD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,YAAsB,MAA0B;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE;YAC3C,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;YAC3C,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBAC1B,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAA;aAC5B;SACF;IACH,CAAC;IAEM,UAAU;QACf,OAAO,MAAM,CAAC,mBAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IAC/D,CAAC;IAED;;;;;OAKG;IACH,iBAAiB,CACf,OAA0E,EAC1E,kBAA4B,EAAE,EAC9B,WAA4B;QAE5B,OAAO,IAAI,CAAC,OAAO,CACjB,OAAO,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G,CAAC,CAAA;gBAC5C,IAAI,MAAM,EAAE;oBACV,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;oBAC1B,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;iBAC9B;gBACD,OAAO,mBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;YACtC,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA/OD,4CA+OC","sourcesContent":["import { ERC20__factory, ERC721__factory } from '../builtin/internal'\nimport { AddressType, DummyProvider, EthFetchConfig, ProcessResult } from '@sentio/sdk'\nimport { AccountBindOptions } from '../core/bind-options'\n\nimport { Network, LogParams } from 'ethers/providers'\n\nimport { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20'\nimport { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721'\n\nimport { ERC20Processor } from '../builtin/internal/erc20_processor'\nimport { ERC721Processor } from '../builtin/internal/erc721_processor'\n\nimport { AccountContext } from '../core/context'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { AddressOrTypeEventFilter, EventsHandler } from './base-processor'\nimport { Transaction, Block, TransactionReceipt, LogDescription } from 'ethers'\nimport { AccountProcessorState } from './account-processor-state'\n\nconst ERC20_INTERFACE = ERC20__factory.createInterface()\nconst ERC721_INTERFACE = ERC721__factory.createInterface()\n\nexport class AccountProcessor {\n config: AccountBindOptions\n eventHandlers: EventsHandler[] = []\n\n static bind(config: AccountBindOptions): AccountProcessor {\n const processor = new AccountProcessor(config)\n AccountProcessorState.INSTANCE.addValue(processor)\n return processor\n }\n\n protected constructor(config: AccountBindOptions) {\n this.config = config\n if (typeof this.config.network === 'string') {\n const asInt = parseInt(this.config.network)\n if (Number.isFinite(asInt)) {\n this.config.network = asInt\n }\n }\n }\n\n public getChainId(): number {\n return Number(Network.from(this.config.network || 1).chainId)\n }\n\n /**\n * Register custom handler function to process erc20 transfer event to this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20TransferIn(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) => ERC721Processor.filters.Transfer(null, this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process erc20 transfer event from this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20TransferOut(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) => ERC20Processor.filters.Transfer(this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process erc20 mint for this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20Minted(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) =>\n ERC20Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),\n fetchConfig\n )\n }\n\n private onERC20(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20, fetchConfig)\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event to this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721TransferIn(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) => ERC721Processor.filters.Transfer(null, this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event from this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721TransferOut(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) => ERC721Processor.filters.Transfer(this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process ERC721 mint for this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721Minted(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) =>\n ERC721Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),\n fetchConfig\n )\n }\n\n private onERC721(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC(handler, collections, defaultFilter, AddressType.ERC721, fetchConfig)\n }\n\n private onERC(\n handler: (event: any, ctx: AccountContext) => PromiseOrVoid,\n contractAddresses: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n addressType: AddressType,\n fetchConfig?: EthFetchConfig\n ) {\n const filters = []\n for (const token of contractAddresses) {\n const filter = defaultFilter(this.config.address)\n filter.address = token\n filters.push(filter)\n }\n if (!filters.length) {\n const filter = defaultFilter(this.config.address)\n filter.address = undefined\n filter.addressType = addressType\n filters.push(filter)\n }\n return this.onEvent(handler, filters, fetchConfig)\n }\n\n protected onEvent(\n handler: (event: LogDescription, ctx: AccountContext) => PromiseOrVoid,\n filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[],\n fetchConfig?: EthFetchConfig\n ) {\n const chainId = this.getChainId()\n\n let _filters: AddressOrTypeEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // let hasVaildConfig = false\n // for (const filter of _filters) {\n // if (filter.address) {\n // hasVaildConfig = true\n // break\n // }\n // if (filter.topics && filter.topics.length) {\n // hasVaildConfig = true\n // break\n // }\n // }\n //\n // if (!hasVaildConfig) {\n // throw Error('no valid config has been found for this account')\n // }\n\n const config = this.config\n\n this.eventHandlers.push({\n filters: _filters,\n fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),\n handler: async function (data) {\n const log = data.log as { topics: Array<string>; data: string }\n const ctx = new AccountContext(\n chainId,\n config.address,\n data.timestamp,\n data.block as Block,\n log as any as LogParams,\n undefined,\n data.transaction as Transaction,\n data.transactionReceipt as TransactionReceipt\n )\n const parsed = ERC20_INTERFACE.parseLog(log)\n if (parsed) {\n await handler(parsed, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n\n return this\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"account-processor.js","sourceRoot":"","sources":["../../src/eth/account-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG3E,OAAO,EAAE,OAAO,EAAa,MAAM,kBAAkB,CAAA;AAKrD,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAA;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAInD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAEpE,MAAM,eAAe,GAAG,cAAc,CAAC,eAAe,EAAE,C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C20__factory, ERC721__factory } from '../builtin/internal/index.js'\nimport { AddressType, EthFetchConfig, ProcessResult } from '@sentio/protos'\nimport { AccountBindOptions } from '../core/bind-options.js'\n\nimport { Network, LogParams } from 'ethers/providers'\n\nimport { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20.js'\nimport { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721.js'\n\nimport { ERC20Processor } from '../builtin/internal/erc20_processor.js'\nimport { ERC721Processor } from '../builtin/internal/erc721_processor.js'\n\nimport { AccountContext } from '../core/context.js'\nimport { PromiseOrVoid } from '../promise-or-void.js'\nimport { AddressOrTypeEventFilter, EventsHandler } from './base-processor.js'\nimport { Transaction, Block, TransactionReceipt, LogDescription } from 'ethers'\nimport { AccountProcessorState } from './account-processor-state.js'\n\nconst ERC20_INTERFACE = ERC20__factory.createInterface()\nconst ERC721_INTERFACE = ERC721__factory.createInterface()\n\nexport class AccountProcessor {\n config: AccountBindOptions\n eventHandlers: EventsHandler[] = []\n\n static bind(config: AccountBindOptions): AccountProcessor {\n const processor = new AccountProcessor(config)\n AccountProcessorState.INSTANCE.addValue(processor)\n return processor\n }\n\n protected constructor(config: AccountBindOptions) {\n this.config = config\n if (typeof this.config.network === 'string') {\n const asInt = parseInt(this.config.network)\n if (Number.isFinite(asInt)) {\n this.config.network = asInt\n }\n }\n }\n\n public getChainId(): number {\n return Number(Network.from(this.config.network || 1).chainId)\n }\n\n /**\n * Register custom handler function to process erc20 transfer event to this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20TransferIn(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) => ERC721Processor.filters.Transfer(null, this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process erc20 transfer event from this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20TransferOut(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) => ERC20Processor.filters.Transfer(this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process erc20 mint for this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20Minted(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) =>\n ERC20Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),\n fetchConfig\n )\n }\n\n private onERC20(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20, fetchConfig)\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event to this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721TransferIn(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) => ERC721Processor.filters.Transfer(null, this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event from this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721TransferOut(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) => ERC721Processor.filters.Transfer(this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process ERC721 mint for this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721Minted(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) =>\n ERC721Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),\n fetchConfig\n )\n }\n\n private onERC721(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC(handler, collections, defaultFilter, AddressType.ERC721, fetchConfig)\n }\n\n private onERC(\n handler: (event: any, ctx: AccountContext) => PromiseOrVoid,\n contractAddresses: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n addressType: AddressType,\n fetchConfig?: EthFetchConfig\n ) {\n const filters = []\n for (const token of contractAddresses) {\n const filter = defaultFilter(this.config.address)\n filter.address = token\n filters.push(filter)\n }\n if (!filters.length) {\n const filter = defaultFilter(this.config.address)\n filter.address = undefined\n filter.addressType = addressType\n filters.push(filter)\n }\n return this.onEvent(handler, filters, fetchConfig)\n }\n\n protected onEvent(\n handler: (event: LogDescription, ctx: AccountContext) => PromiseOrVoid,\n filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[],\n fetchConfig?: EthFetchConfig\n ) {\n const chainId = this.getChainId()\n\n let _filters: AddressOrTypeEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // let hasVaildConfig = false\n // for (const filter of _filters) {\n // if (filter.address) {\n // hasVaildConfig = true\n // break\n // }\n // if (filter.topics && filter.topics.length) {\n // hasVaildConfig = true\n // break\n // }\n // }\n //\n // if (!hasVaildConfig) {\n // throw Error('no valid config has been found for this account')\n // }\n\n const config = this.config\n\n this.eventHandlers.push({\n filters: _filters,\n fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),\n handler: async function (data) {\n const log = data.log as { topics: Array<string>; data: string }\n const ctx = new AccountContext(\n chainId,\n config.address,\n data.timestamp,\n data.block as Block,\n log as any as LogParams,\n undefined,\n data.transaction as Transaction,\n data.transactionReceipt as TransactionReceipt\n )\n const parsed = ERC20_INTERFACE.parseLog(log)\n if (parsed) {\n await handler(parsed, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n\n return this\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { BoundContractView, ContractContext, ContractView } from '../core/context';
|
|
1
|
+
import { BoundContractView, ContractContext, ContractView } from '../core/context.js';
|
|
2
2
|
import { BaseContract, Block, LogDescription } from 'ethers';
|
|
3
|
-
import { BaseProcessor } from './base-processor';
|
|
4
|
-
import { BindOptions } from '../core/bind-options';
|
|
3
|
+
import { BaseProcessor } from './base-processor.js';
|
|
4
|
+
import { BindOptions } from '../core/bind-options.js';
|
|
5
5
|
import { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos';
|
|
6
|
-
import { PromiseOrVoid } from '../promise-or-void';
|
|
7
|
-
import { Trace } from './trace';
|
|
6
|
+
import { PromiseOrVoid } from '../promise-or-void.js';
|
|
7
|
+
import { Trace } from './trace.js';
|
|
8
8
|
import { ListStateStorage } from '@sentio/runtime';
|
|
9
9
|
import { DeferredTopicFilter } from 'ethers/contract';
|
|
10
10
|
export declare class ProcessorTemplateProcessorState extends ListStateStorage<BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>> {
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const runtime_1 = require("@sentio/runtime");
|
|
6
|
-
const providers_1 = require("ethers/providers");
|
|
7
|
-
class ProcessorTemplateProcessorState extends runtime_1.ListStateStorage {
|
|
1
|
+
import { getOptionsSignature } from '../core/bind-options.js';
|
|
2
|
+
import { ListStateStorage } from '@sentio/runtime';
|
|
3
|
+
import { Network } from 'ethers/providers';
|
|
4
|
+
export class ProcessorTemplateProcessorState extends ListStateStorage {
|
|
8
5
|
static INSTANCE = new ProcessorTemplateProcessorState();
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
class TemplateInstanceState extends runtime_1.ListStateStorage {
|
|
7
|
+
export class TemplateInstanceState extends ListStateStorage {
|
|
12
8
|
static INSTANCE = new TemplateInstanceState();
|
|
13
9
|
}
|
|
14
|
-
|
|
15
|
-
class BaseProcessorTemplate {
|
|
10
|
+
export class BaseProcessorTemplate {
|
|
16
11
|
id;
|
|
17
12
|
binds = new Set();
|
|
18
13
|
blockHandlers = [];
|
|
@@ -23,7 +18,7 @@ class BaseProcessorTemplate {
|
|
|
23
18
|
ProcessorTemplateProcessorState.INSTANCE.addValue(this);
|
|
24
19
|
}
|
|
25
20
|
bind(options) {
|
|
26
|
-
const sig =
|
|
21
|
+
const sig = getOptionsSignature(options);
|
|
27
22
|
if (this.binds.has(sig)) {
|
|
28
23
|
return;
|
|
29
24
|
}
|
|
@@ -43,7 +38,7 @@ class BaseProcessorTemplate {
|
|
|
43
38
|
contract: {
|
|
44
39
|
address: options.address,
|
|
45
40
|
name: options.name || '',
|
|
46
|
-
chainId: options.network ?
|
|
41
|
+
chainId: options.network ? Network.from(options.network).chainId.toString() : '1',
|
|
47
42
|
abi: '',
|
|
48
43
|
},
|
|
49
44
|
startBlock: 0n,
|
|
@@ -84,5 +79,4 @@ class BaseProcessorTemplate {
|
|
|
84
79
|
return this;
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
|
-
exports.BaseProcessorTemplate = BaseProcessorTemplate;
|
|
88
82
|
//# sourceMappingURL=base-processor-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAI1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAA0B,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAGlE,MAAM,OAAO,+BAAgC,SAAQ,gBAEpD;IACC,MAAM,CAAC,QAAQ,GAAG,IAAI,+BAA+B,EAAE,CAAA;;AAGzD,MAAM,OAAO,qBAAsB,SAAQ,gBAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA;;AAG/C,MAAM,OAAgB,qBAAqB;IAIzC,EAAE,CAAQ;IACV,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IACzB,aAAa,GAIP,EAAE,CAAA;IACR,aAAa,GAIP,EAAE,CAAA;IACR,aAAa,GAIP,EAAE,CAAA;IAER;QACE,IAAI,CAAC,EAAE,GAAG,+BAA+B,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,CAAA;QACrE,+BAA+B,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC;IAEM,IAAI,CAAC,OAAoB;QAC9B,MAAM,GAAG,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAA;QACxC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACvB,OAAM;SACP;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEnB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QAE5C,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,aAAa,EAAE;YACnC,SAAS,CAAC,OAAO,CAAC,EAAE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AAC,aAAa,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,OAAO;YAChB,MAAM,EAAE,MAAM;YACd,WAAW,EAAE,WAAW;SACzB,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,eAAe,CACpB,OAA6F,EAC7F,aAAa,GAAG,IAAI,EACpB,qBAAqB,GAAG,IAAI;QAE5B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE;YACzC,cAAc,EAAE,aAAa;YAC7B,gBAAgB,EAAE,qBAAqB;SACxC,CAAC,CAAA;IACJ,CAAC;IAEM,cAAc,CACnB,OAA6F,EAC7F,qBAAqB,GAAG,EAAE,EAC1B,qBAAqB,GAAG,GAAG;QAE3B,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,EAAE,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,EAClF,SAAS,CACV,CAAA;IACH,CAAC;IAEM,UAAU,CACf,OAA6F,EAC7F,YAAwC,EACxC,aAAyC;QAEzC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC,CAAA;QACvG,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CACZ,SAAiB,EACjB,OAA6F;QAE7F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC;CAGF","sourcesContent":["import { BoundContractView, ContractContext, ContractView } from '../core/context.js'\nimport { BaseContract, ContractEvent, Block, LogDescription } from 'ethers'\nimport { AddressOrTypeEventFilter, BaseProcessor } from './base-processor.js'\nimport { BindOptions, getOptionsSignature } from '../core/bind-options.js'\nimport { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos'\nimport { PromiseOrVoid } from '../promise-or-void.js'\nimport { Trace } from './trace.js'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { EventFilter, LogParams, Network } from 'ethers/providers'\nimport { DeferredTopicFilter } from 'ethers/contract'\n\nexport class ProcessorTemplateProcessorState extends ListStateStorage<\n BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>\n> {\n static INSTANCE = new ProcessorTemplateProcessorState()\n}\n\nexport class TemplateInstanceState extends ListStateStorage<TemplateInstance> {\n static INSTANCE = new TemplateInstanceState()\n}\n\nexport abstract class BaseProcessorTemplate<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n id: number\n binds = new Set<string>()\n blockHandlers: {\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n }[] = []\n traceHandlers: {\n signature: string\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n fetchConfig?: EthFetchConfig\n }[] = []\n eventHandlers: {\n handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n filter: DeferredTopicFilter | DeferredTopicFilter[]\n fetchConfig?: EthFetchConfig\n }[] = []\n\n constructor() {\n this.id = ProcessorTemplateProcessorState.INSTANCE.getValues().length\n ProcessorTemplateProcessorState.INSTANCE.addValue(this)\n }\n\n public bind(options: BindOptions) {\n const sig = getOptionsSignature(options)\n if (this.binds.has(sig)) {\n return\n }\n this.binds.add(sig)\n\n const processor = this.bindInternal(options)\n\n for (const eh of this.eventHandlers) {\n processor.onEvent(eh.handler, eh.filter, eh.fetchConfig)\n }\n for (const th of this.traceHandlers) {\n processor.onTrace(th.signature, th.handler, th.fetchConfig)\n }\n for (const bh of this.blockHandlers) {\n processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: options.network ? Network.from(options.network).chainId.toString() : '1',\n abi: '',\n },\n startBlock: 0n,\n endBlock: 0n,\n }\n if (options.startBlock) {\n instance.startBlock = BigInt(options.startBlock)\n }\n if (options.endBlock) {\n instance.endBlock = BigInt(options.endBlock)\n }\n TemplateInstanceState.INSTANCE.addValue(instance)\n return processor\n }\n\n public onEvent(\n handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: EthFetchConfig\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n fetchConfig: fetchConfig,\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000,\n backfillBlockInterval = 4000\n ) {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillBlockInterval = 240\n ) {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },\n undefined\n )\n }\n\n public onInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ) {\n this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval })\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n this.traceHandlers.push({ signature, handler })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Block, BaseContract, DeferredTopicFilter, LogDescription } from 'ethers';
|
|
2
|
-
import { BoundContractView, ContractContext, ContractView } from '../core/context';
|
|
2
|
+
import { BoundContractView, ContractContext, ContractView } from '../core/context.js';
|
|
3
3
|
import { AddressType, Data_EthBlock, Data_EthLog, Data_EthTrace, EthFetchConfig, HandleInterval, ProcessResult } from '@sentio/protos';
|
|
4
|
-
import { BindInternalOptions, BindOptions } from '../core/bind-options';
|
|
5
|
-
import { PromiseOrVoid } from '../promise-or-void';
|
|
6
|
-
import { Trace } from './trace';
|
|
4
|
+
import { BindInternalOptions, BindOptions } from '../core/bind-options.js';
|
|
5
|
+
import { PromiseOrVoid } from '../promise-or-void.js';
|
|
6
|
+
import { Trace } from './trace.js';
|
|
7
7
|
export interface AddressOrTypeEventFilter extends DeferredTopicFilter {
|
|
8
8
|
addressType?: AddressType;
|
|
9
9
|
address?: string;
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const protos_1 = require("@sentio/protos");
|
|
7
|
-
const nice_grpc_1 = require("nice-grpc");
|
|
8
|
-
class EventsHandler {
|
|
1
|
+
import { Network } from 'ethers/providers';
|
|
2
|
+
import { ContractContext } from '../core/context.js';
|
|
3
|
+
import { EthFetchConfig, ProcessResult, } from '@sentio/protos';
|
|
4
|
+
import { ServerError, Status } from 'nice-grpc';
|
|
5
|
+
export class EventsHandler {
|
|
9
6
|
filters;
|
|
10
7
|
handler;
|
|
11
8
|
fetchConfig;
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
class TraceHandler {
|
|
10
|
+
export class TraceHandler {
|
|
15
11
|
signature;
|
|
16
12
|
handler;
|
|
17
13
|
fetchConfig;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
class BlockHandlder {
|
|
15
|
+
export class BlockHandlder {
|
|
21
16
|
blockInterval;
|
|
22
17
|
timeIntervalInMinutes;
|
|
23
18
|
handler;
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
class BaseProcessor {
|
|
20
|
+
export class BaseProcessor {
|
|
27
21
|
blockHandlers = [];
|
|
28
22
|
eventHandlers = [];
|
|
29
23
|
traceHandlers = [];
|
|
@@ -49,7 +43,7 @@ class BaseProcessor {
|
|
|
49
43
|
}
|
|
50
44
|
}
|
|
51
45
|
getChainId() {
|
|
52
|
-
return Number(
|
|
46
|
+
return Number(Network.from(this.config.network).chainId);
|
|
53
47
|
}
|
|
54
48
|
onEvent(handler, filter, fetchConfig) {
|
|
55
49
|
const chainId = this.getChainId();
|
|
@@ -64,21 +58,21 @@ class BaseProcessor {
|
|
|
64
58
|
const processor = this;
|
|
65
59
|
this.eventHandlers.push({
|
|
66
60
|
filters: _filters,
|
|
67
|
-
fetchConfig: fetchConfig ||
|
|
61
|
+
fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
|
|
68
62
|
handler: async function (data) {
|
|
69
63
|
if (!data.log) {
|
|
70
|
-
throw new
|
|
64
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty');
|
|
71
65
|
}
|
|
72
66
|
const log = data.log;
|
|
73
67
|
const contractView = processor.CreateBoundContractView();
|
|
74
|
-
const ctx = new
|
|
68
|
+
const ctx = new ContractContext(contractName, contractView, chainId, data.timestamp, data.block, log, undefined, data.transaction, data.transactionReceipt);
|
|
75
69
|
const logParam = log;
|
|
76
70
|
const parsed = contractView.rawContract.interface.parseLog(logParam);
|
|
77
71
|
if (parsed) {
|
|
78
72
|
await handler(parsed, ctx);
|
|
79
73
|
return ctx.getProcessResult();
|
|
80
74
|
}
|
|
81
|
-
return
|
|
75
|
+
return ProcessResult.fromPartial({});
|
|
82
76
|
},
|
|
83
77
|
});
|
|
84
78
|
return this;
|
|
@@ -99,11 +93,11 @@ class BaseProcessor {
|
|
|
99
93
|
this.blockHandlers.push({
|
|
100
94
|
handler: async function (data) {
|
|
101
95
|
if (!data.block) {
|
|
102
|
-
throw new
|
|
96
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty');
|
|
103
97
|
}
|
|
104
98
|
const block = data.block;
|
|
105
99
|
const contractView = processor.CreateBoundContractView();
|
|
106
|
-
const ctx = new
|
|
100
|
+
const ctx = new ContractContext(contractName, contractView, chainId, new Date(block.timestamp * 1000), block, undefined, undefined);
|
|
107
101
|
await handler(block, ctx);
|
|
108
102
|
return ctx.getProcessResult();
|
|
109
103
|
},
|
|
@@ -131,21 +125,21 @@ class BaseProcessor {
|
|
|
131
125
|
const processor = this;
|
|
132
126
|
this.traceHandlers.push({
|
|
133
127
|
signature,
|
|
134
|
-
fetchConfig: fetchConfig ||
|
|
128
|
+
fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
|
|
135
129
|
handler: async function (data) {
|
|
136
130
|
const contractView = processor.CreateBoundContractView();
|
|
137
131
|
const contractInterface = contractView.rawContract.interface;
|
|
138
132
|
const fragment = contractInterface.getFunction(signature);
|
|
139
133
|
if (!data.trace || !fragment) {
|
|
140
|
-
throw new
|
|
134
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'trace is null');
|
|
141
135
|
}
|
|
142
136
|
const trace = data.trace;
|
|
143
137
|
if (!trace.action.input) {
|
|
144
|
-
return
|
|
138
|
+
return ProcessResult.fromPartial({});
|
|
145
139
|
}
|
|
146
140
|
const traceData = '0x' + trace.action.input.slice(10);
|
|
147
141
|
trace.args = contractInterface.getAbiCoder().decode(fragment.inputs, traceData);
|
|
148
|
-
const ctx = new
|
|
142
|
+
const ctx = new ContractContext(contractName, contractView, chainId, data.timestamp, data.block, undefined, trace, data.transaction, data.transactionReceipt);
|
|
149
143
|
await handler(trace, ctx);
|
|
150
144
|
return ctx.getProcessResult();
|
|
151
145
|
},
|
|
@@ -153,5 +147,4 @@ class BaseProcessor {
|
|
|
153
147
|
return this;
|
|
154
148
|
}
|
|
155
149
|
}
|
|
156
|
-
exports.BaseProcessor = BaseProcessor;
|
|
157
150
|
//# sourceMappingURL=base-processor.js.map
|