@sentio/sdk 1.40.5-rc.6 → 1.41.0-rc.1
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.js +3 -16
- package/lib/builtin/eacaggregatorproxy/index.js.map +1 -1
- package/lib/builtin/eacaggregatorproxy/test-utils.d.ts +5 -5
- package/lib/builtin/eacaggregatorproxy/test-utils.js +8 -4
- package/lib/builtin/eacaggregatorproxy/test-utils.js.map +1 -1
- package/lib/builtin/erc1155/index.js +3 -16
- package/lib/builtin/erc1155/index.js.map +1 -1
- package/lib/builtin/erc1155/test-utils.d.ts +5 -5
- package/lib/builtin/erc1155/test-utils.js +8 -4
- package/lib/builtin/erc1155/test-utils.js.map +1 -1
- package/lib/builtin/erc20/index.js +3 -16
- package/lib/builtin/erc20/index.js.map +1 -1
- package/lib/builtin/erc20/test-utils.d.ts +4 -4
- package/lib/builtin/erc20/test-utils.js +6 -3
- package/lib/builtin/erc20/test-utils.js.map +1 -1
- package/lib/builtin/erc20bytes/index.js +3 -16
- package/lib/builtin/erc20bytes/index.js.map +1 -1
- package/lib/builtin/erc20bytes/test-utils.d.ts +3 -3
- package/lib/builtin/erc20bytes/test-utils.js +4 -2
- package/lib/builtin/erc20bytes/test-utils.js.map +1 -1
- package/lib/builtin/erc721/index.js +3 -16
- package/lib/builtin/erc721/index.js.map +1 -1
- package/lib/builtin/erc721/test-utils.d.ts +4 -4
- package/lib/builtin/erc721/test-utils.js +6 -3
- package/lib/builtin/erc721/test-utils.js.map +1 -1
- package/lib/builtin/index.js +5 -27
- package/lib/builtin/index.js.map +1 -1
- package/lib/builtin/internal/EACAggregatorProxy.d.ts +19 -430
- package/lib/builtin/internal/EACAggregatorProxy.js.map +1 -1
- package/lib/builtin/internal/ERC1155.d.ts +18 -161
- package/lib/builtin/internal/ERC1155.js.map +1 -1
- package/lib/builtin/internal/ERC20.d.ts +12 -279
- package/lib/builtin/internal/ERC20.js.map +1 -1
- package/lib/builtin/internal/ERC20Bytes.d.ts +11 -146
- package/lib/builtin/internal/ERC20Bytes.js.map +1 -1
- package/lib/builtin/internal/ERC721.d.ts +12 -222
- package/lib/builtin/internal/ERC721.js.map +1 -1
- package/lib/builtin/internal/WETH9.d.ts +16 -191
- package/lib/builtin/internal/WETH9.js.map +1 -1
- package/lib/builtin/internal/common.d.ts +3 -18
- package/lib/builtin/internal/common.js +6 -0
- package/lib/builtin/internal/common.js.map +1 -1
- package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +161 -168
- package/lib/builtin/internal/eacaggregatorproxy_processor.js +94 -288
- package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
- package/lib/builtin/internal/erc1155_processor.d.ts +45 -50
- package/lib/builtin/internal/erc1155_processor.js +68 -132
- package/lib/builtin/internal/erc1155_processor.js.map +1 -1
- package/lib/builtin/internal/erc20_processor.d.ts +59 -63
- package/lib/builtin/internal/erc20_processor.js +64 -155
- package/lib/builtin/internal/erc20_processor.js.map +1 -1
- package/lib/builtin/internal/erc20bytes_processor.d.ts +37 -40
- package/lib/builtin/internal/erc20bytes_processor.js +50 -118
- package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
- package/lib/builtin/internal/erc721_processor.d.ts +56 -60
- package/lib/builtin/internal/erc721_processor.js +66 -167
- package/lib/builtin/internal/erc721_processor.js.map +1 -1
- package/lib/builtin/internal/factories/EACAggregatorProxy__factory.d.ts +1 -2
- package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js +1 -1
- package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js.map +1 -1
- package/lib/builtin/internal/factories/ERC1155__factory.d.ts +1 -2
- package/lib/builtin/internal/factories/ERC1155__factory.js +1 -1
- package/lib/builtin/internal/factories/ERC1155__factory.js.map +1 -1
- package/lib/builtin/internal/factories/ERC20Bytes__factory.d.ts +1 -2
- package/lib/builtin/internal/factories/ERC20Bytes__factory.js +1 -1
- package/lib/builtin/internal/factories/ERC20Bytes__factory.js.map +1 -1
- package/lib/builtin/internal/factories/ERC20__factory.d.ts +1 -2
- package/lib/builtin/internal/factories/ERC20__factory.js +1 -1
- package/lib/builtin/internal/factories/ERC20__factory.js.map +1 -1
- package/lib/builtin/internal/factories/ERC721__factory.d.ts +1 -2
- package/lib/builtin/internal/factories/ERC721__factory.js +1 -1
- package/lib/builtin/internal/factories/ERC721__factory.js.map +1 -1
- package/lib/builtin/internal/factories/WETH9__factory.d.ts +1 -2
- package/lib/builtin/internal/factories/WETH9__factory.js +1 -1
- package/lib/builtin/internal/factories/WETH9__factory.js.map +1 -1
- package/lib/builtin/internal/index.js +2 -24
- package/lib/builtin/internal/index.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.d.ts +44 -49
- package/lib/builtin/internal/weth9_processor.js +70 -144
- package/lib/builtin/internal/weth9_processor.js.map +1 -1
- package/lib/builtin/weth9/index.js +3 -16
- package/lib/builtin/weth9/index.js.map +1 -1
- package/lib/builtin/weth9/test-utils.d.ts +5 -5
- package/lib/builtin/weth9/test-utils.js +8 -4
- package/lib/builtin/weth9/test-utils.js.map +1 -1
- package/lib/core/big-decimal.d.ts +6 -0
- package/lib/core/big-decimal.js +6 -2
- package/lib/core/big-decimal.js.map +1 -1
- package/lib/core/bind-options.d.ts +1 -1
- package/lib/core/bind-options.js +2 -2
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +8 -14
- package/lib/core/context.js +7 -6
- package/lib/core/context.js.map +1 -1
- package/lib/core/core-plugin.d.ts +1 -1
- package/lib/core/core-plugin.js +1 -1
- package/lib/core/core-plugin.js.map +1 -1
- package/lib/core/generic-processor.test.js.map +1 -1
- package/lib/core/index.d.ts +0 -5
- package/lib/core/index.js +1 -9
- package/lib/core/index.js.map +1 -1
- package/lib/core/numberish.d.ts +2 -3
- package/lib/core/numberish.js +35 -33
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/numberish.test.js.map +1 -1
- package/lib/core/sui-plugin.d.ts +1 -1
- package/lib/core/sui-plugin.js +1 -1
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/error.js +2 -2
- package/lib/error.js.map +1 -1
- package/lib/eth/account-processor-state.d.ts +5 -0
- package/lib/eth/account-processor-state.js +9 -0
- package/lib/eth/account-processor-state.js.map +1 -0
- package/lib/{core → eth}/account-processor.d.ts +4 -8
- package/lib/{core → eth}/account-processor.js +33 -42
- package/lib/eth/account-processor.js.map +1 -0
- package/lib/{core → eth}/base-processor-template.d.ts +7 -8
- package/lib/{core → eth}/base-processor-template.js +3 -3
- package/lib/eth/base-processor-template.js.map +1 -0
- package/lib/{core → eth}/base-processor.d.ts +7 -7
- package/lib/{core → eth}/base-processor.js +13 -18
- package/lib/eth/base-processor.js.map +1 -0
- package/lib/{binds.d.ts → eth/binds.d.ts} +4 -3
- package/lib/{binds.js → eth/binds.js} +3 -3
- package/lib/eth/binds.js.map +1 -0
- package/lib/{core → eth}/eth-plugin.d.ts +2 -2
- package/lib/{core → eth}/eth-plugin.js +19 -13
- package/lib/eth/eth-plugin.js.map +1 -0
- package/lib/{core → eth}/generic-processor.d.ts +3 -3
- package/lib/{core → eth}/generic-processor.js +5 -5
- package/lib/eth/generic-processor.js.map +1 -0
- package/lib/eth/index.d.ts +6 -0
- package/lib/eth/index.js +15 -0
- package/lib/eth/index.js.map +1 -0
- package/lib/eth/provider.d.ts +4 -0
- package/lib/eth/provider.js +74 -0
- package/lib/eth/provider.js.map +1 -0
- package/lib/{core → eth}/trace.d.ts +2 -2
- package/lib/{core → eth}/trace.js +0 -0
- package/lib/eth/trace.js.map +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +7 -23
- package/lib/index.js.map +1 -1
- package/lib/target-ethers-sentio/event-handler.d.ts +1 -0
- package/lib/target-ethers-sentio/event-handler.js +21 -5
- package/lib/target-ethers-sentio/event-handler.js.map +1 -1
- package/lib/target-ethers-sentio/file.js +59 -57
- package/lib/target-ethers-sentio/file.js.map +1 -1
- package/lib/target-ethers-sentio/functions-handler.js +7 -4
- package/lib/target-ethers-sentio/functions-handler.js.map +1 -1
- package/lib/target-ethers-sentio/index.d.ts +1 -1
- package/lib/target-ethers-sentio/index.js +3 -5
- package/lib/target-ethers-sentio/index.js.map +1 -1
- package/lib/target-ethers-sentio/view-function.js +15 -15
- package/lib/target-ethers-sentio/view-function.js.map +1 -1
- package/lib/testing/metric-utils.js +2 -2
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +11 -11
- package/lib/testing/test-processor-server.js +7 -12
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +1 -6
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/utils/conversion.d.ts +2 -2
- package/lib/utils/conversion.js +12 -5
- package/lib/utils/conversion.js.map +1 -1
- package/lib/utils/dex-price.d.ts +1 -1
- package/lib/utils/dex-price.js +5 -6
- 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.js +5 -27
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/token.d.ts +2 -3
- package/lib/utils/token.js +5 -6
- package/lib/utils/token.js.map +1 -1
- package/lib/webpack.config.js +1 -1
- package/package.json +7 -13
- package/src/builtin/eacaggregatorproxy/test-utils.ts +13 -9
- package/src/builtin/erc1155/test-utils.ts +13 -9
- package/src/builtin/erc20/test-utils.ts +10 -7
- package/src/builtin/erc20bytes/test-utils.ts +7 -5
- package/src/builtin/erc721/test-utils.ts +10 -7
- package/src/builtin/internal/EACAggregatorProxy.ts +20 -815
- package/src/builtin/internal/ERC1155.ts +20 -483
- package/src/builtin/internal/ERC20.ts +15 -641
- package/src/builtin/internal/ERC20Bytes.ts +13 -357
- package/src/builtin/internal/ERC721.ts +15 -601
- package/src/builtin/internal/WETH9.ts +20 -439
- package/src/builtin/internal/common.ts +33 -33
- package/src/builtin/internal/eacaggregatorproxy_processor.ts +344 -425
- package/src/builtin/internal/erc1155_processor.ts +202 -209
- package/src/builtin/internal/erc20_processor.ts +191 -225
- package/src/builtin/internal/erc20bytes_processor.ts +136 -165
- package/src/builtin/internal/erc721_processor.ts +218 -242
- package/src/builtin/internal/factories/EACAggregatorProxy__factory.ts +2 -3
- package/src/builtin/internal/factories/ERC1155__factory.ts +2 -3
- package/src/builtin/internal/factories/ERC20Bytes__factory.ts +2 -3
- package/src/builtin/internal/factories/ERC20__factory.ts +2 -3
- package/src/builtin/internal/factories/ERC721__factory.ts +2 -3
- package/src/builtin/internal/factories/WETH9__factory.ts +2 -3
- package/src/builtin/internal/weth9_processor.ts +176 -208
- package/src/builtin/weth9/test-utils.ts +13 -9
- package/src/core/big-decimal.ts +11 -0
- package/src/core/bind-options.ts +2 -3
- package/src/core/context.ts +14 -13
- package/src/core/core-plugin.ts +1 -1
- package/src/core/index.ts +0 -6
- package/src/core/numberish.ts +39 -40
- package/src/core/sui-plugin.ts +1 -1
- package/src/error.ts +1 -1
- package/src/eth/account-processor-state.ts +6 -0
- package/src/{core → eth}/account-processor.ts +40 -50
- package/src/{core → eth}/base-processor-template.ts +11 -12
- package/src/{core → eth}/base-processor.ts +37 -31
- package/src/{binds.ts → eth/binds.ts} +6 -5
- package/src/{core → eth}/eth-plugin.ts +19 -12
- package/src/{core → eth}/generic-processor.ts +5 -5
- package/src/eth/index.ts +6 -0
- package/src/eth/provider.ts +82 -0
- package/src/{core → eth}/trace.ts +2 -3
- package/src/index.ts +2 -3
- package/src/target-ethers-sentio/event-handler.ts +22 -5
- package/src/target-ethers-sentio/file.ts +65 -65
- package/src/target-ethers-sentio/functions-handler.ts +8 -4
- package/src/target-ethers-sentio/index.ts +1 -1
- package/src/target-ethers-sentio/view-function.ts +17 -18
- package/src/testing/metric-utils.ts +2 -2
- package/src/testing/test-processor-server.ts +23 -24
- package/src/testing/test-provider.ts +2 -7
- package/src/utils/conversion.ts +12 -5
- package/src/utils/dex-price.ts +3 -3
- package/src/utils/token.ts +10 -11
- package/src/webpack.config.js +1 -1
- package/lib/binds.js.map +0 -1
- package/lib/core/account-processor.js.map +0 -1
- package/lib/core/base-processor-template.js.map +0 -1
- package/lib/core/base-processor.js.map +0 -1
- package/lib/core/eth-plugin.js.map +0 -1
- package/lib/core/generic-processor.js.map +0 -1
- package/lib/core/trace.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numberish.test.js","sourceRoot":"","sources":["../../src/core/numberish.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,2CAAyD;AACzD,mCAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"numberish.test.js","sourceRoot":"","sources":["../../src/core/numberish.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,2CAAyD;AACzD,mCAAkC;AAClC,2CAAwC;AACxC,2CAA2C;AAC3C,wBAA8B;AAC9B,oDAAmD;AAEnD,oCAAoC;AACpC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,MAAM,GAAa,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,sCAAsC,EAAE,KAAK,EAAE,CAAC,SAAS,EAAE,IAAI,IAAI,IAAI,CAAC,CAAA;IAE3G,IAAI,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACrD,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;YACtB,MAAM,CAAC,GAAG,IAAA,wBAAY,EAAC,CAAC,CAAC,CAAA;YACzB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;YAC/B,MAAM,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;YAC3B,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;SAC1B;IACH,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC5D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,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\nimport { toBigInteger, toMetricValue } from './numberish'\nimport { webcrypto } from 'crypto'\nimport { performance } from 'perf_hooks'\nimport { BigInteger } from '@sentio/protos'\nimport { BigDecimal } from '.'\nimport { bytesToBigInt } from '../utils/conversion'\n\n// TODO add test for type conversion\ndescribe('Numberish tests', () => {\n const values: bigint[] = [0n, -0n, 3815372408723498172304781320847103784n, 2132n, -18708707n, 123n << 100n]\n\n test('big integer conversion correctness ', async () => {\n for (const v of values) {\n const b = toBigInteger(v)\n const hex1 = BigIntegerToHex(b)\n const hex2 = v.toString(16)\n expect(hex1).equals(hex2)\n }\n })\n\n test('random big integer conversion correctness ', async () => {\n for (let i = 0; i < 1000; i++) {\n const random = webcrypto.getRandomValues(new Uint8Array(256))\n const v = bytesToBigInt(random)\n const b = toBigInteger(v)\n\n expect(bytesToBigInt(b.data)).equals(v)\n }\n })\n\n test.skip('random big integer performance', async () => {\n jest.setTimeout(100000)\n jest.retryTimes(3)\n\n let timer1 = 0\n let timer2 = 0\n for (let i = 0; i < 1000; i++) {\n // Use higher value for local debugging\n const random = webcrypto.getRandomValues(new Uint8Array(256))\n const v = bytesToBigInt(random)\n\n let start = performance.now()\n toBigInteger(v)\n timer1 += performance.now() - start\n\n start = performance.now()\n v.toString(16)\n timer2 += performance.now() - start\n }\n\n console.log(timer1, timer2)\n expect(timer1).to.lessThan(timer2 * 3)\n })\n\n test('metric values', async () => {\n const longDec = '12.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002'\n expect(toMetricValue(new BigDecimal(longDec)).bigDecimal == longDec)\n\n const complexDec = '-7.350918e-428'\n expect(toMetricValue(new BigDecimal(complexDec)).bigDecimal == complexDec)\n\n expect(\n BigIntegerToBigInt(toMetricValue(new BigDecimal('100000')).bigInteger || BigInteger.fromPartial({})) === 100000n\n )\n })\n})\n\n// Performance very bad\nfunction BigIntegerToHex(b: BigInteger): string {\n let res = bytesToBigInt(b.data).toString(16)\n if (b.negative) {\n res = '-' + res\n }\n return res\n}\n\nfunction BigIntegerToBigInt(b: BigInteger): bigint {\n let res = bytesToBigInt(b.data)\n if (b.negative) {\n res = -res\n }\n return res\n}\n"]}
|
package/lib/core/sui-plugin.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Plugin } from '@sentio/runtime';
|
|
|
2
2
|
import { DataBinding, ProcessConfigResponse, ProcessResult } from '@sentio/protos';
|
|
3
3
|
export declare class SuiPlugin extends Plugin {
|
|
4
4
|
name: string;
|
|
5
|
-
configure(config: ProcessConfigResponse): void
|
|
5
|
+
configure(config: ProcessConfigResponse): Promise<void>;
|
|
6
6
|
supportedHandlers: never[];
|
|
7
7
|
processBinding(request: DataBinding): Promise<ProcessResult>;
|
|
8
8
|
}
|
package/lib/core/sui-plugin.js
CHANGED
|
@@ -8,7 +8,7 @@ const chain_1 = require("../utils/chain");
|
|
|
8
8
|
const sui_processor_1 = require("./sui-processor");
|
|
9
9
|
class SuiPlugin extends runtime_1.Plugin {
|
|
10
10
|
name = 'SuiPlugin';
|
|
11
|
-
configure(config) {
|
|
11
|
+
async configure(config) {
|
|
12
12
|
for (const suiProcessor of sui_processor_1.SuiProcessorState.INSTANCE.getValues()) {
|
|
13
13
|
const contractConfig = {
|
|
14
14
|
transactionConfig: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/core/sui-plugin.ts"],"names":[],"mappings":";;;AAAA,6CAAuE;AACvE,2CAA+G;AAE/G,yCAA+C;AAE/C,0CAA0C;AAC1C,mDAAmD;AAEnD,MAAa,SAAU,SAAQ,gBAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAE1B,SAAS,CAAC,MAA6B;
|
|
1
|
+
{"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/core/sui-plugin.ts"],"names":[],"mappings":";;;AAAA,6CAAuE;AACvE,2CAA+G;AAE/G,yCAA+C;AAE/C,0CAA0C;AAC1C,mDAAmD;AAEnD,MAAa,SAAU,SAAQ,gBAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAE1B,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,KAAK,MAAM,YAAY,IAAI,iCAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACjE,MAAM,cAAc,GAAmB;gBACrC,iBAAiB,EAAE,EAAE;gBACrB,aAAa,EAAE,wBAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,iBAAS,CAAC,UAAU;oBAC7B,OAAO,EAAE,YAAY,CAAC,OAAO;oBAC7B,GAAG,EAAE,EAAE;iBACR;gBACD,UAAU,EAAE,EAAE;gBACd,eAAe,EAAE,EAAE;gBACnB,YAAY,EAAE,EAAE;gBAChB,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,cAAc;gBAC9C,QAAQ,EAAE,EAAE;gBACZ,iBAAiB,EAAE,SAAS;gBAC5B,iBAAiB,EAAE,EAAE;gBACrB,gBAAgB,EAAE,EAAE;aACrB,CAAA;YACD,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SAC5C;IACH,CAAC;IAED,iBAAiB,GAAG,EAAE,CAAA;IAEtB,cAAc,CAAC,OAAoB;QACjC,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,oBAAW,CAAC,eAAe,CAAC;YACjC,6CAA6C;YAC7C;gBACE,MAAM,IAAI,uBAAW,CAAC,kBAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AArCD,8BAqCC;AAED,uBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport { ContractConfig, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { CHAIN_IDS } from '../utils/chain'\nimport { SuiProcessorState } from './sui-processor'\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n\n async configure(config: ProcessConfigResponse) {\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig: ContractConfig = {\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: 'sui contract',\n chainId: CHAIN_IDS.SUI_DEVNET,\n address: suiProcessor.address,\n abi: '',\n },\n logConfigs: [],\n intervalConfigs: [],\n traceConfigs: [],\n startBlock: suiProcessor.config.startSeqNumber,\n endBlock: 0n,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n config.contractConfigs.push(contractConfig)\n }\n }\n\n supportedHandlers = []\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_TRANSACTION:\n // return this.processSolInstruction(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
|
package/lib/error.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformEtherError = exports.EthersError = void 0;
|
|
4
|
-
|
|
4
|
+
// import { errors } from 'ethers/providers'
|
|
5
5
|
class EthersError extends Error {
|
|
6
6
|
e;
|
|
7
7
|
constructor(message, e) {
|
|
@@ -16,7 +16,7 @@ exports.EthersError = EthersError;
|
|
|
16
16
|
function transformEtherError(e, ctx) {
|
|
17
17
|
let msg = '';
|
|
18
18
|
// @ts-ignore expected error fields
|
|
19
|
-
if (e.code ===
|
|
19
|
+
if (e.code === errors.CALL_EXCEPTION) {
|
|
20
20
|
// @ts-ignore expected error fields
|
|
21
21
|
if (e.data === '0x') {
|
|
22
22
|
if (ctx) {
|
package/lib/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAEA,4CAA4C;AAE5C,MAAa,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;AAXD,kCAWC;AAED,SAAgB,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;AA3BD,kDA2BC","sourcesContent":["// Transform error in more readable format\nimport { ContractContext } from './core/context'\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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccountProcessorState = void 0;
|
|
4
|
+
const runtime_1 = require("@sentio/runtime");
|
|
5
|
+
class AccountProcessorState extends runtime_1.ListStateStorage {
|
|
6
|
+
static INSTANCE = new AccountProcessorState();
|
|
7
|
+
}
|
|
8
|
+
exports.AccountProcessorState = AccountProcessorState;
|
|
9
|
+
//# sourceMappingURL=account-processor-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-processor-state.js","sourceRoot":"","sources":["../../src/eth/account-processor-state.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAGlD,MAAa,qBAAsB,SAAQ,0BAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA;;AAD/C,sDAEC","sourcesContent":["import { ListStateStorage } from '@sentio/runtime'\nimport { AccountProcessor } from './account-processor'\n\nexport class AccountProcessorState extends ListStateStorage<AccountProcessor> {\n static INSTANCE = new AccountProcessorState()\n}\n"]}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { ListStateStorage } from '@sentio/runtime';
|
|
2
1
|
import { EthFetchConfig } from '@sentio/sdk';
|
|
3
|
-
import { AccountBindOptions } from '
|
|
2
|
+
import { AccountBindOptions } from '../core/bind-options';
|
|
4
3
|
import { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20';
|
|
5
4
|
import { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721';
|
|
6
|
-
import { AccountContext } from '
|
|
5
|
+
import { AccountContext } from '../core/context';
|
|
7
6
|
import { PromiseOrVoid } from '../promise-or-void';
|
|
8
|
-
import { Event } from '@ethersproject/contracts';
|
|
9
7
|
import { AddressOrTypeEventFilter, EventsHandler } from './base-processor';
|
|
10
|
-
|
|
11
|
-
static INSTANCE: AccountProcessorState;
|
|
12
|
-
}
|
|
8
|
+
import { LogDescription } from 'ethers';
|
|
13
9
|
export declare class AccountProcessor {
|
|
14
10
|
config: AccountBindOptions;
|
|
15
11
|
eventHandlers: EventsHandler[];
|
|
@@ -61,5 +57,5 @@ export declare class AccountProcessor {
|
|
|
61
57
|
onERC721Minted(handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid, collections?: string[], fetchConfig?: EthFetchConfig): this;
|
|
62
58
|
private onERC721;
|
|
63
59
|
private onERC;
|
|
64
|
-
protected onEvent(handler: (event:
|
|
60
|
+
protected onEvent(handler: (event: LogDescription, ctx: AccountContext) => PromiseOrVoid, filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[], fetchConfig?: EthFetchConfig): this;
|
|
65
61
|
}
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccountProcessor =
|
|
4
|
-
const runtime_1 = require("@sentio/runtime");
|
|
3
|
+
exports.AccountProcessor = void 0;
|
|
5
4
|
const internal_1 = require("../builtin/internal");
|
|
6
5
|
const sdk_1 = require("@sentio/sdk");
|
|
7
|
-
const providers_1 = require("
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const ERC721_CONTRACT = internal_1.ERC721__factory.connect('', sdk_1.DummyProvider);
|
|
6
|
+
const providers_1 = require("ethers/providers");
|
|
7
|
+
const erc20_processor_1 = require("../builtin/internal/erc20_processor");
|
|
8
|
+
const erc721_processor_1 = require("../builtin/internal/erc721_processor");
|
|
9
|
+
const context_1 = require("../core/context");
|
|
10
|
+
const account_processor_state_1 = require("./account-processor-state");
|
|
11
|
+
const ERC20_INTERFACE = internal_1.ERC20__factory.createInterface();
|
|
12
|
+
const ERC721_INTERFACE = internal_1.ERC721__factory.createInterface();
|
|
15
13
|
class AccountProcessor {
|
|
16
14
|
config;
|
|
17
15
|
eventHandlers = [];
|
|
18
16
|
static bind(config) {
|
|
19
17
|
const processor = new AccountProcessor(config);
|
|
20
|
-
AccountProcessorState.INSTANCE.addValue(processor);
|
|
18
|
+
account_processor_state_1.AccountProcessorState.INSTANCE.addValue(processor);
|
|
21
19
|
return processor;
|
|
22
20
|
}
|
|
23
21
|
constructor(config) {
|
|
@@ -30,7 +28,7 @@ class AccountProcessor {
|
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
getChainId() {
|
|
33
|
-
return (
|
|
31
|
+
return Number(providers_1.Network.from(this.config.network || 1).chainId);
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
34
|
* Register custom handler function to process erc20 transfer event to this account
|
|
@@ -39,7 +37,7 @@ class AccountProcessor {
|
|
|
39
37
|
* @param fetchConfig
|
|
40
38
|
*/
|
|
41
39
|
onERC20TransferIn(handler, tokensAddresses = [], fetchConfig) {
|
|
42
|
-
return this.onERC20(handler, tokensAddresses, (address) =>
|
|
40
|
+
return this.onERC20(handler, tokensAddresses, (address) => erc721_processor_1.ERC721Processor.filters.Transfer(null, this.config.address), fetchConfig);
|
|
43
41
|
}
|
|
44
42
|
/**
|
|
45
43
|
* Register custom handler function to process erc20 transfer event from this account
|
|
@@ -48,7 +46,7 @@ class AccountProcessor {
|
|
|
48
46
|
* @param fetchConfig
|
|
49
47
|
*/
|
|
50
48
|
onERC20TransferOut(handler, tokensAddresses = [], fetchConfig) {
|
|
51
|
-
return this.onERC20(handler, tokensAddresses, (address) =>
|
|
49
|
+
return this.onERC20(handler, tokensAddresses, (address) => erc20_processor_1.ERC20Processor.filters.Transfer(this.config.address), fetchConfig);
|
|
52
50
|
}
|
|
53
51
|
/**
|
|
54
52
|
* Register custom handler function to process erc20 mint for this account
|
|
@@ -57,7 +55,7 @@ class AccountProcessor {
|
|
|
57
55
|
* @param fetchConfig
|
|
58
56
|
*/
|
|
59
57
|
onERC20Minted(handler, tokensAddresses = [], fetchConfig) {
|
|
60
|
-
return this.onERC20(handler, tokensAddresses, (address) =>
|
|
58
|
+
return this.onERC20(handler, tokensAddresses, (address) => erc20_processor_1.ERC20Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address), fetchConfig);
|
|
61
59
|
}
|
|
62
60
|
onERC20(handler, tokensAddresses = [], defaultFilter, fetchConfig) {
|
|
63
61
|
return this.onERC(handler, tokensAddresses, defaultFilter, sdk_1.AddressType.ERC20, fetchConfig);
|
|
@@ -69,7 +67,7 @@ class AccountProcessor {
|
|
|
69
67
|
* @param fetchConfig
|
|
70
68
|
*/
|
|
71
69
|
onERC721TransferIn(handler, collections, fetchConfig) {
|
|
72
|
-
return this.onERC721(handler, collections, (address) =>
|
|
70
|
+
return this.onERC721(handler, collections, (address) => erc721_processor_1.ERC721Processor.filters.Transfer(null, this.config.address), fetchConfig);
|
|
73
71
|
}
|
|
74
72
|
/**
|
|
75
73
|
* Register custom handler function to process ERC721 transfer event from this account
|
|
@@ -78,7 +76,7 @@ class AccountProcessor {
|
|
|
78
76
|
* @param fetchConfig
|
|
79
77
|
*/
|
|
80
78
|
onERC721TransferOut(handler, collections, fetchConfig) {
|
|
81
|
-
return this.onERC721(handler, collections, (address) =>
|
|
79
|
+
return this.onERC721(handler, collections, (address) => erc721_processor_1.ERC721Processor.filters.Transfer(this.config.address), fetchConfig);
|
|
82
80
|
}
|
|
83
81
|
/**
|
|
84
82
|
* Register custom handler function to process ERC721 mint for this account
|
|
@@ -87,7 +85,7 @@ class AccountProcessor {
|
|
|
87
85
|
* @param fetchConfig
|
|
88
86
|
*/
|
|
89
87
|
onERC721Minted(handler, collections = [], fetchConfig) {
|
|
90
|
-
return this.onERC721(handler, collections, (address) =>
|
|
88
|
+
return this.onERC721(handler, collections, (address) => erc721_processor_1.ERC721Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address), fetchConfig);
|
|
91
89
|
}
|
|
92
90
|
onERC721(handler, collections, defaultFilter, fetchConfig) {
|
|
93
91
|
return this.onERC(handler, collections, defaultFilter, sdk_1.AddressType.ERC721, fetchConfig);
|
|
@@ -116,20 +114,21 @@ class AccountProcessor {
|
|
|
116
114
|
else {
|
|
117
115
|
_filters.push(filter);
|
|
118
116
|
}
|
|
119
|
-
let hasVaildConfig = false
|
|
120
|
-
for (const filter of _filters) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
// let hasVaildConfig = false
|
|
118
|
+
// for (const filter of _filters) {
|
|
119
|
+
// if (filter.address) {
|
|
120
|
+
// hasVaildConfig = true
|
|
121
|
+
// break
|
|
122
|
+
// }
|
|
123
|
+
// if (filter.topics && filter.topics.length) {
|
|
124
|
+
// hasVaildConfig = true
|
|
125
|
+
// break
|
|
126
|
+
// }
|
|
127
|
+
// }
|
|
128
|
+
//
|
|
129
|
+
// if (!hasVaildConfig) {
|
|
130
|
+
// throw Error('no valid config has been found for this account')
|
|
131
|
+
// }
|
|
133
132
|
const config = this.config;
|
|
134
133
|
this.eventHandlers.push({
|
|
135
134
|
filters: _filters,
|
|
@@ -137,17 +136,9 @@ class AccountProcessor {
|
|
|
137
136
|
handler: async function (data) {
|
|
138
137
|
const log = data.log;
|
|
139
138
|
const ctx = new context_1.AccountContext(chainId, config.address, data.timestamp, data.block, log, undefined, data.transaction, data.transactionReceipt);
|
|
140
|
-
const
|
|
141
|
-
const parsed = ERC20_CONTRACT.interface.parseLog(log);
|
|
139
|
+
const parsed = ERC20_INTERFACE.parseLog(log);
|
|
142
140
|
if (parsed) {
|
|
143
|
-
|
|
144
|
-
event.decode = (data, topics) => {
|
|
145
|
-
return ERC20_CONTRACT.interface.decodeEventLog(parsed.eventFragment, data, topics);
|
|
146
|
-
};
|
|
147
|
-
event.event = parsed.name;
|
|
148
|
-
event.eventSignature = parsed.signature;
|
|
149
|
-
// TODO fix this bug
|
|
150
|
-
await handler(event, ctx);
|
|
141
|
+
await handler(parsed, ctx);
|
|
151
142
|
return ctx.getProcessResult();
|
|
152
143
|
}
|
|
153
144
|
return sdk_1.ProcessResult.fromPartial({});
|
|
@@ -0,0 +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,C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AED,6BAA6B;QAC7B,mCAAmC;QACnC,0BAA0B;QAC1B,4BAA4B;QAC5B,YAAY;QACZ,MAAM;QACN,iDAAiD;QACjD,4BAA4B;QAC5B,YAAY;QACZ,MAAM;QACN,IAAI;QACJ,EAAE;QACF,yBAAyB;QACzB,mEAAmE;QACnE,IAAI;QAEJ,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QAE1B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,QAAQ;YACjB,WAAW,EAAE,WAAW,IAAI,oBAAc,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1D,OAAO,EAAE,KAAK,WAAW,IAAI;gBAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAA8C,CAAA;gBAC/D,MAAM,GAAG,GAAG,IAAI,wBAAc,CAC5B,OAAO,EACP,MAAM,CAAC,OAAO,EACd,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,KAAc,EACnB,GAAuB,EACvB,SAAS,EACT,IAAI,CAAC,WAA0B,EAC/B,IAAI,CAAC,kBAAwC,CAC9C,CAAA;gBACD,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,GAAG,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,13 +1,12 @@
|
|
|
1
|
-
import { BoundContractView, ContractContext, ContractView } from '
|
|
2
|
-
import { Block } from '
|
|
3
|
-
import { BaseContract, EventFilter } from 'ethers';
|
|
4
|
-
import { Event } from '@ethersproject/contracts';
|
|
1
|
+
import { BoundContractView, ContractContext, ContractView } from '../core/context';
|
|
2
|
+
import { BaseContract, Block, LogDescription } from 'ethers';
|
|
5
3
|
import { BaseProcessor } from './base-processor';
|
|
6
|
-
import { BindOptions } from '
|
|
4
|
+
import { BindOptions } from '../core/bind-options';
|
|
7
5
|
import { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos';
|
|
8
6
|
import { PromiseOrVoid } from '../promise-or-void';
|
|
9
7
|
import { Trace } from './trace';
|
|
10
8
|
import { ListStateStorage } from '@sentio/runtime';
|
|
9
|
+
import { DeferredTopicFilter } from 'ethers/contract';
|
|
11
10
|
export declare class ProcessorTemplateProcessorState extends ListStateStorage<BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>> {
|
|
12
11
|
static INSTANCE: ProcessorTemplateProcessorState;
|
|
13
12
|
}
|
|
@@ -28,13 +27,13 @@ export declare abstract class BaseProcessorTemplate<TContract extends BaseContra
|
|
|
28
27
|
fetchConfig?: EthFetchConfig;
|
|
29
28
|
}[];
|
|
30
29
|
eventHandlers: {
|
|
31
|
-
handler: (event:
|
|
32
|
-
filter:
|
|
30
|
+
handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid;
|
|
31
|
+
filter: DeferredTopicFilter | DeferredTopicFilter[];
|
|
33
32
|
fetchConfig?: EthFetchConfig;
|
|
34
33
|
}[];
|
|
35
34
|
constructor();
|
|
36
35
|
bind(options: BindOptions): BaseProcessor<TContract, TBoundContractView> | undefined;
|
|
37
|
-
onEvent(handler: (event:
|
|
36
|
+
onEvent(handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: EthFetchConfig): this;
|
|
38
37
|
onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
39
38
|
onBlockInterval(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number): this;
|
|
40
39
|
onTimeInterval(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillBlockInterval?: number): this;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseProcessorTemplate = exports.TemplateInstanceState = exports.ProcessorTemplateProcessorState = void 0;
|
|
4
|
-
const bind_options_1 = require("
|
|
5
|
-
const providers_1 = require("@ethersproject/providers");
|
|
4
|
+
const bind_options_1 = require("../core/bind-options");
|
|
6
5
|
const runtime_1 = require("@sentio/runtime");
|
|
6
|
+
const providers_1 = require("ethers/providers");
|
|
7
7
|
class ProcessorTemplateProcessorState extends runtime_1.ListStateStorage {
|
|
8
8
|
static INSTANCE = new ProcessorTemplateProcessorState();
|
|
9
9
|
}
|
|
@@ -43,7 +43,7 @@ class BaseProcessorTemplate {
|
|
|
43
43
|
contract: {
|
|
44
44
|
address: options.address,
|
|
45
45
|
name: options.name || '',
|
|
46
|
-
chainId: options.network ?
|
|
46
|
+
chainId: options.network ? providers_1.Network.from(options.network).chainId.toString() : '1',
|
|
47
47
|
abi: '',
|
|
48
48
|
},
|
|
49
49
|
startBlock: 0n,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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CAAC,OAA6F;QAC1G,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IACtC,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;AA7HD,sDA6HC","sourcesContent":["import { BoundContractView, ContractContext, ContractView } from '../core/context'\nimport { BaseContract, ContractEvent, Block, LogDescription } from 'ethers'\nimport { AddressOrTypeEventFilter, BaseProcessor } from './base-processor'\nimport { BindOptions, getOptionsSignature } from '../core/bind-options'\nimport { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\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 onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n return this.onBlockInterval(handler)\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,12 +1,12 @@
|
|
|
1
|
-
import { Block,
|
|
2
|
-
import {
|
|
3
|
-
import { BoundContractView, ContractContext, ContractView } from './context';
|
|
1
|
+
import { Block, BaseContract, DeferredTopicFilter, LogDescription } from 'ethers';
|
|
2
|
+
import { BoundContractView, ContractContext, ContractView } from '../core/context';
|
|
4
3
|
import { AddressType, Data_EthBlock, Data_EthLog, Data_EthTrace, EthFetchConfig, HandleInterval, ProcessResult } from '@sentio/protos';
|
|
5
|
-
import { BindInternalOptions, BindOptions } from '
|
|
4
|
+
import { BindInternalOptions, BindOptions } from '../core/bind-options';
|
|
6
5
|
import { PromiseOrVoid } from '../promise-or-void';
|
|
7
6
|
import { Trace } from './trace';
|
|
8
|
-
export interface AddressOrTypeEventFilter extends
|
|
7
|
+
export interface AddressOrTypeEventFilter extends DeferredTopicFilter {
|
|
9
8
|
addressType?: AddressType;
|
|
9
|
+
address?: string;
|
|
10
10
|
}
|
|
11
11
|
export declare class EventsHandler {
|
|
12
12
|
filters: AddressOrTypeEventFilter[];
|
|
@@ -31,11 +31,11 @@ export declare abstract class BaseProcessor<TContract extends BaseContract, TBou
|
|
|
31
31
|
constructor(config: BindOptions);
|
|
32
32
|
protected abstract CreateBoundContractView(): TBoundContractView;
|
|
33
33
|
getChainId(): number;
|
|
34
|
-
onEvent(handler: (event:
|
|
34
|
+
onEvent(handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: EthFetchConfig): this;
|
|
35
35
|
onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
36
36
|
onBlockInterval(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number): this;
|
|
37
37
|
onTimeInterval(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number): this;
|
|
38
38
|
onInterval(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeInterval: HandleInterval | undefined, blockInterval: HandleInterval | undefined): this;
|
|
39
|
-
onAllEvents(handler: (event:
|
|
39
|
+
onAllEvents(handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
|
40
40
|
onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, fetchConfig?: EthFetchConfig): this;
|
|
41
41
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseProcessor = exports.BlockHandlder = exports.TraceHandler = exports.EventsHandler = void 0;
|
|
4
|
-
const providers_1 = require("
|
|
5
|
-
const context_1 = require("
|
|
4
|
+
const providers_1 = require("ethers/providers");
|
|
5
|
+
const context_1 = require("../core/context");
|
|
6
6
|
const protos_1 = require("@sentio/protos");
|
|
7
7
|
const nice_grpc_1 = require("nice-grpc");
|
|
8
8
|
class EventsHandler {
|
|
@@ -49,7 +49,7 @@ class BaseProcessor {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
getChainId() {
|
|
52
|
-
return (
|
|
52
|
+
return Number(providers_1.Network.from(this.config.network).chainId);
|
|
53
53
|
}
|
|
54
54
|
onEvent(handler, filter, fetchConfig) {
|
|
55
55
|
const chainId = this.getChainId();
|
|
@@ -72,18 +72,10 @@ class BaseProcessor {
|
|
|
72
72
|
const log = data.log;
|
|
73
73
|
const contractView = processor.CreateBoundContractView();
|
|
74
74
|
const ctx = new context_1.ContractContext(contractName, contractView, chainId, data.timestamp, data.block, log, undefined, data.transaction, data.transactionReceipt);
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
const parsed = contractView.rawContract.interface.parseLog(log);
|
|
75
|
+
const logParam = log;
|
|
76
|
+
const parsed = contractView.rawContract.interface.parseLog(logParam);
|
|
78
77
|
if (parsed) {
|
|
79
|
-
|
|
80
|
-
event.decode = (data, topics) => {
|
|
81
|
-
return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics);
|
|
82
|
-
};
|
|
83
|
-
event.event = parsed.name;
|
|
84
|
-
event.eventSignature = parsed.signature;
|
|
85
|
-
// TODO fix this bug
|
|
86
|
-
await handler(event, ctx);
|
|
78
|
+
await handler(parsed, ctx);
|
|
87
79
|
return ctx.getProcessResult();
|
|
88
80
|
}
|
|
89
81
|
return protos_1.ProcessResult.fromPartial({});
|
|
@@ -126,8 +118,11 @@ class BaseProcessor {
|
|
|
126
118
|
onAllEvents(handler) {
|
|
127
119
|
const _filters = [];
|
|
128
120
|
const tmpContract = this.CreateBoundContractView();
|
|
129
|
-
for (const
|
|
130
|
-
|
|
121
|
+
for (const fragment of tmpContract.rawContract.interface.fragments) {
|
|
122
|
+
if (fragment.type === 'event') {
|
|
123
|
+
const filter = tmpContract.rawContract.filters[fragment.format()];
|
|
124
|
+
_filters.push(filter());
|
|
125
|
+
}
|
|
131
126
|
}
|
|
132
127
|
return this.onEvent(function (log, ctx) {
|
|
133
128
|
return handler(log, ctx);
|
|
@@ -144,7 +139,7 @@ class BaseProcessor {
|
|
|
144
139
|
const contractView = processor.CreateBoundContractView();
|
|
145
140
|
const contractInterface = contractView.rawContract.interface;
|
|
146
141
|
const fragment = contractInterface.getFunction(signature);
|
|
147
|
-
if (!data.trace) {
|
|
142
|
+
if (!data.trace || !fragment) {
|
|
148
143
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'trace is null');
|
|
149
144
|
}
|
|
150
145
|
const trace = data.trace;
|
|
@@ -152,7 +147,7 @@ class BaseProcessor {
|
|
|
152
147
|
return protos_1.ProcessResult.fromPartial({});
|
|
153
148
|
}
|
|
154
149
|
const traceData = '0x' + trace.action.input.slice(10);
|
|
155
|
-
trace.args = contractInterface.
|
|
150
|
+
trace.args = contractInterface.getAbiCoder().decode(fragment.inputs, traceData);
|
|
156
151
|
const ctx = new context_1.ContractContext(contractName, contractView, chainId, data.timestamp, data.block, undefined, trace, data.transaction, data.transactionReceipt);
|
|
157
152
|
await handler(trace, ctx);
|
|
158
153
|
return ctx.getProcessResult();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/eth/base-processor.ts"],"names":[],"mappings":";;;AAYA,gDAAkE;AAElE,6CAAkF;AAClF,2CAQuB;AAIvB,yCAA+C;AAO/C,MAAa,aAAa;IACxB,OAAO,CAA4B;IACnC,OAAO,CAAgD;IACvD,WAAW,CAAgB;CAC5B;AAJD,sCAIC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAAkD;IACzD,WAAW,CAAgB;CAC5B;AAJD,oCAIC;AAED,MAAa,aAAa;IACxB,aAAa,CAAiB;IAC9B,qBAAqB,CAAiB;IACtC,OAAO,CAAkD;CAC1D;AAJD,sCAIC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAoB,EAAE,CAAA;IACnC,aAAa,GAAoB,EAAE,CAAA;IACnC,aAAa,GAAmB,EAAE,CAAA;IAElC,MAAM,CAAqB;IAE3B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,UAAU,EAAE,EAAE;SACf,CAAA;QACD,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;QACD,IAAI,MAAM,CAAC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G,GAAG,IAAI,yBAAe,CAC7B,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,KAAc,EACnB,SAAS,EACT,KAAK,EACL,IAAI,CAAC,WAA0B,EAC/B,IAAI,CAAC,kBAAwC,CAC9C,CAAA;gBACD,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBACzB,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;YAC/B,CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAnND,sCAmNC","sourcesContent":["import {\n Block,\n ContractEvent,\n Log,\n TransactionReceipt,\n BytesLike,\n BaseContract,\n Transaction,\n DeferredTopicFilter,\n LogDescription,\n EventFragment,\n} from 'ethers'\nimport { EventFilter, LogParams, Network } from 'ethers/providers'\n\nimport { BoundContractView, ContractContext, ContractView } from '../core/context'\nimport {\n AddressType,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\n EthFetchConfig,\n HandleInterval,\n ProcessResult,\n} from '@sentio/protos'\nimport { BindInternalOptions, BindOptions } from '../core/bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\nimport { ServerError, Status } from 'nice-grpc'\n\nexport interface AddressOrTypeEventFilter extends DeferredTopicFilter {\n addressType?: AddressType\n address?: string\n}\n\nexport class EventsHandler {\n filters: AddressOrTypeEventFilter[]\n handler: (event: Data_EthLog) => Promise<ProcessResult>\n fetchConfig: EthFetchConfig\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Data_EthTrace) => Promise<ProcessResult>\n fetchConfig: EthFetchConfig\n}\n\nexport class BlockHandlder {\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (block: Data_EthBlock) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: BlockHandlder[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: 0n,\n }\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 if (config.startBlock) {\n this.config.startBlock = BigInt(config.startBlock)\n }\n if (config.endBlock) {\n this.config.endBlock = BigInt(config.endBlock)\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return Number(Network.from(this.config.network).chainId)\n }\n\n public onEvent(\n handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: EthFetchConfig\n ) {\n const chainId = this.getChainId()\n let _filters: DeferredTopicFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractName = this.config.name\n const processor = this\n this.eventHandlers.push({\n filters: _filters,\n fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),\n handler: async function (data: Data_EthLog) {\n if (!data.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')\n }\n const log = data.log as LogParams\n\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n data.block as Block,\n log,\n undefined,\n data.transaction as Transaction,\n data.transactionReceipt as TransactionReceipt\n )\n const logParam = log as any as { topics: Array<string>; data: string }\n\n const parsed = contractView.rawContract.interface.parseLog(logParam)\n if (parsed) {\n await handler(parsed, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n return this.onBlockInterval(handler)\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 backfillTimeIntervalInMinutes = 240\n ) {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillTimeIntervalInMinutes },\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 const chainId = this.getChainId()\n const processor = this\n const contractName = this.config.name\n\n this.blockHandlers.push({\n handler: async function (data: Data_EthBlock) {\n if (!data.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')\n }\n const block = data.block as Block\n\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n new Date(block.timestamp * 1000),\n block,\n undefined,\n undefined\n )\n await handler(block, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\n })\n return this\n }\n\n public onAllEvents(\n handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const _filters: DeferredTopicFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const fragment of tmpContract.rawContract.interface.fragments) {\n if (fragment.type === 'event') {\n const filter = tmpContract.rawContract.filters[fragment.format()]\n _filters.push(filter())\n }\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: EthFetchConfig\n ) {\n const chainId = this.getChainId()\n const contractName = this.config.name\n const processor = this\n\n this.traceHandlers.push({\n signature,\n fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),\n handler: async function (data: Data_EthTrace) {\n const contractView = processor.CreateBoundContractView()\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!data.trace || !fragment) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'trace is null')\n }\n const trace = data.trace as Trace\n if (!trace.action.input) {\n return ProcessResult.fromPartial({})\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface.getAbiCoder().decode(fragment.inputs, traceData)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n data.block as Block,\n undefined,\n trace,\n data.transaction as Transaction,\n data.transactionReceipt as TransactionReceipt\n )\n await handler(trace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { BindOptions } from '
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { BindOptions } from '../core/bind-options';
|
|
2
|
+
import { ContractView } from '../core';
|
|
3
|
+
import { BaseProcessor } from './base-processor';
|
|
4
|
+
import { Networkish } from 'ethers/providers';
|
|
4
5
|
import { BaseContract } from 'ethers';
|
|
5
6
|
import { MapStateStorage } from '@sentio/runtime';
|
|
6
7
|
export declare class ProcessorState extends MapStateStorage<BaseProcessor<any, any>> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addContractByABI = exports.getContractByABI = exports.addProcessor = exports.getProcessor = exports.ProcessorState = void 0;
|
|
4
|
-
const bind_options_1 = require("
|
|
5
|
-
const providers_1 = require("
|
|
4
|
+
const bind_options_1 = require("../core/bind-options");
|
|
5
|
+
const providers_1 = require("ethers/providers");
|
|
6
6
|
const runtime_1 = require("@sentio/runtime");
|
|
7
7
|
class ProcessorState extends runtime_1.MapStateStorage {
|
|
8
8
|
static INSTANCE = new ProcessorState();
|
|
@@ -11,7 +11,7 @@ exports.ProcessorState = ProcessorState;
|
|
|
11
11
|
// from abiName_address_chainId => contract wrapper
|
|
12
12
|
const contracts = new Map();
|
|
13
13
|
function getKey(abiName, address, network) {
|
|
14
|
-
const chainId =
|
|
14
|
+
const chainId = providers_1.Network.from(network).chainId.toString();
|
|
15
15
|
return [abiName, address.toLowerCase(), chainId].join('_');
|
|
16
16
|
}
|
|
17
17
|
// Dedup processor that bind multiple times
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binds.js","sourceRoot":"","sources":["../../src/eth/binds.ts"],"names":[],"mappings":";;;AAAA,uDAAuE;AAGvE,gDAAsD;AAGtD,6CAAiD;AAEjD,MAAa,cAAe,SAAQ,yBAAwC;IAC1E,MAAM,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAA;;AADxC,wCAEC;AAED,mDAAmD;AACnD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAsC,CAAA;AAE/D,SAAS,MAAM,CAAC,OAAe,EAAE,OAAe,EAAE,OAAmB;IACnE,MAAM,OAAO,GAAG,mBAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAA;IACxD,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC5D,CAAC;AAED,2CAA2C;AAC3C,SAAgB,YAAY,CAAC,IAAiB;IAC5C,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,CAAA;IACrC,OAAO,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAC9C,CAAC;AAHD,oCAGC;AAED,SAAgB,YAAY,CAAC,IAAiB,EAAE,SAAkC;IAChF,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,CAAA;IAErC,cAAc,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AACvD,CAAC;AAJD,oCAIC;AAED,SAAgB,gBAAgB,CAAC,OAAe,EAAE,OAAe,EAAE,OAAmB;IACpF,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAC3B,CAAC;AAHD,4CAGC;AAED,SAAgB,gBAAgB,CAC9B,OAAe,EACf,OAAe,EACf,OAAmB,EACnB,QAAoC;IAEpC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACrC,CAAC;AARD,4CAQC","sourcesContent":["import { BindOptions, getOptionsSignature } from '../core/bind-options'\nimport { ContractView } from '../core'\nimport { BaseProcessor } from './base-processor'\nimport { Networkish, Network } from 'ethers/providers'\n\nimport { BaseContract } from 'ethers'\nimport { MapStateStorage } from '@sentio/runtime'\n\nexport class ProcessorState extends MapStateStorage<BaseProcessor<any, any>> {\n static INSTANCE = new ProcessorState()\n}\n\n// from abiName_address_chainId => contract wrapper\nconst contracts = new Map<string, ContractView<BaseContract>>()\n\nfunction getKey(abiName: string, address: string, network: Networkish) {\n const chainId = Network.from(network).chainId.toString()\n return [abiName, address.toLowerCase(), chainId].join('_')\n}\n\n// Dedup processor that bind multiple times\nexport function getProcessor(opts: BindOptions) {\n const sig = getOptionsSignature(opts)\n return ProcessorState.INSTANCE.getValue(sig)\n}\n\nexport function addProcessor(opts: BindOptions, processor: BaseProcessor<any, any>) {\n const sig = getOptionsSignature(opts)\n\n ProcessorState.INSTANCE.getOrSetValue(sig, processor)\n}\n\nexport function getContractByABI(abiName: string, address: string, network: Networkish) {\n const key = getKey(abiName, address, network)\n return contracts.get(key)\n}\n\nexport function addContractByABI(\n abiName: string,\n address: string,\n network: Networkish,\n contract: ContractView<BaseContract>\n) {\n const key = getKey(abiName, address, network)\n return contracts.set(key, contract)\n}\n"]}
|
|
@@ -5,10 +5,10 @@ export declare class EthPlugin extends Plugin {
|
|
|
5
5
|
private eventHandlers;
|
|
6
6
|
private traceHandlers;
|
|
7
7
|
private blockHandlers;
|
|
8
|
-
configure(config: ProcessConfigResponse): void
|
|
8
|
+
configure(config: ProcessConfigResponse): Promise<void>;
|
|
9
9
|
supportedHandlers: HandlerType[];
|
|
10
10
|
processBinding(request: DataBinding): Promise<ProcessResult>;
|
|
11
|
-
start(request: StartRequest): void
|
|
11
|
+
start(request: StartRequest): Promise<void>;
|
|
12
12
|
stateDiff(config: ProcessConfigResponse): boolean;
|
|
13
13
|
processLog(request: DataBinding): Promise<ProcessResult>;
|
|
14
14
|
processTrace(binding: DataBinding): Promise<ProcessResult>;
|