@sentio/sdk 2.6.1 → 2.6.2-rc.2
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/eth/account-processor.d.ts +7 -7
- package/lib/eth/account-processor.js +1 -1
- package/lib/eth/account-processor.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +2 -2
- package/lib/eth/base-processor-template.js +4 -3
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +2 -2
- package/lib/eth/base-processor.js +2 -2
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +31 -31
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.d.ts +16 -16
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.d.ts +24 -24
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +13 -13
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.d.ts +20 -20
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.d.ts +19 -19
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/codegen/event-handler.js +1 -1
- package/lib/eth/codegen/event-handler.js.map +1 -1
- package/lib/eth/codegen/functions-handler.js +1 -1
- package/lib/eth/codegen/functions-handler.js.map +1 -1
- package/lib/tsup.config.ts +1 -0
- package/package.json +4 -4
- package/src/eth/account-processor.ts +11 -11
- package/src/eth/base-processor-template.ts +5 -4
- package/src/eth/base-processor.ts +4 -4
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +31 -31
- package/src/eth/builtin/internal/erc1155-processor.ts +16 -16
- package/src/eth/builtin/internal/erc20-processor.ts +24 -24
- package/src/eth/builtin/internal/erc20bytes-processor.ts +13 -13
- package/src/eth/builtin/internal/erc721-processor.ts +20 -20
- package/src/eth/builtin/internal/weth9-processor.ts +19 -19
- package/src/eth/codegen/event-handler.ts +1 -1
- package/src/eth/codegen/functions-handler.ts +1 -1
- package/src/tsup.config.ts +1 -0
@@ -18,21 +18,21 @@ export declare class AccountProcessor {
|
|
18
18
|
* @param tokensAddresses all the erc20 token address to watch
|
19
19
|
* @param fetchConfig
|
20
20
|
*/
|
21
|
-
onERC20TransferIn(handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid, tokensAddresses?: string[], fetchConfig?: EthFetchConfig): this;
|
21
|
+
onERC20TransferIn(handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid, tokensAddresses?: string[], fetchConfig?: Partial<EthFetchConfig>): this;
|
22
22
|
/**
|
23
23
|
* Register custom handler function to process erc20 transfer event from this account
|
24
24
|
* @param handler custom handler function
|
25
25
|
* @param tokensAddresses all the erc20 token address to watch
|
26
26
|
* @param fetchConfig
|
27
27
|
*/
|
28
|
-
onERC20TransferOut(handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid, tokensAddresses?: string[], fetchConfig?: EthFetchConfig): this;
|
28
|
+
onERC20TransferOut(handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid, tokensAddresses?: string[], fetchConfig?: Partial<EthFetchConfig>): this;
|
29
29
|
/**
|
30
30
|
* Register custom handler function to process erc20 mint for this account
|
31
31
|
* @param handler custom handler function
|
32
32
|
* @param tokensAddresses all the erc20 token address to watch
|
33
33
|
* @param fetchConfig
|
34
34
|
*/
|
35
|
-
onERC20Minted(handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid, tokensAddresses?: string[], fetchConfig?: EthFetchConfig): this;
|
35
|
+
onERC20Minted(handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid, tokensAddresses?: string[], fetchConfig?: Partial<EthFetchConfig>): this;
|
36
36
|
private onERC20;
|
37
37
|
/**
|
38
38
|
* Register custom handler function to process ERC721 transfer event to this account
|
@@ -40,22 +40,22 @@ export declare class AccountProcessor {
|
|
40
40
|
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
41
41
|
* @param fetchConfig
|
42
42
|
*/
|
43
|
-
onERC721TransferIn(handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid, collections: string[], fetchConfig?: EthFetchConfig): this;
|
43
|
+
onERC721TransferIn(handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid, collections: string[], fetchConfig?: Partial<EthFetchConfig>): this;
|
44
44
|
/**
|
45
45
|
* Register custom handler function to process ERC721 transfer event from this account
|
46
46
|
* @param handler custom handler function
|
47
47
|
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
48
48
|
* @param fetchConfig
|
49
49
|
*/
|
50
|
-
onERC721TransferOut(handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid, collections: string[], fetchConfig?: EthFetchConfig): this;
|
50
|
+
onERC721TransferOut(handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid, collections: string[], fetchConfig?: Partial<EthFetchConfig>): this;
|
51
51
|
/**
|
52
52
|
* Register custom handler function to process ERC721 mint for this account
|
53
53
|
* @param handler custom handler function
|
54
54
|
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
55
55
|
* @param fetchConfig
|
56
56
|
*/
|
57
|
-
onERC721Minted(handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid, collections?: string[], fetchConfig?: EthFetchConfig): this;
|
57
|
+
onERC721Minted(handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid, collections?: string[], fetchConfig?: Partial<EthFetchConfig>): this;
|
58
58
|
private onERC721;
|
59
59
|
private onERC;
|
60
|
-
protected onEvent(handler: (event: LogDescription, ctx: AccountContext) => PromiseOrVoid, filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[], fetchConfig?: EthFetchConfig): this;
|
60
|
+
protected onEvent(handler: (event: LogDescription, ctx: AccountContext) => PromiseOrVoid, filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
61
61
|
}
|
@@ -130,7 +130,7 @@ export class AccountProcessor {
|
|
130
130
|
const config = this.config;
|
131
131
|
this.eventHandlers.push({
|
132
132
|
filters: _filters,
|
133
|
-
fetchConfig: fetchConfig ||
|
133
|
+
fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
|
134
134
|
handler: async function (data) {
|
135
135
|
const { log, block, transaction, transactionReceipt } = formatEthData(data);
|
136
136
|
// const log = data.log as { topics: Array<string>; data: string }
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"account-processor.js","sourceRoot":"","sources":["../../src/eth/account-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG3E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,OAAO,EAAuC,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxF,OAAO,EAAwC,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE3F,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAI7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,eAAe,GAAG,cAAc,CAAC,eAAe,EAAE,CAAA;AACxD,MAAM,gBAAgB,GAAG,eAAe,CAAC,eAAe,EAAE,CAAA;AAE1D,MAAM,OAAO,gBAAgB;IAC3B,MAAM,CAAoB;IAC1B,aAAa,GAAoB,EAAE,CAAA;IAEnC,MAAM,CAAC,IAAI,CAAC,MAA0B;QACpC,MAAM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AAC,CAAA;SACtB;QAED,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,cAAc,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1D,OAAO,EAAE,KAAK,WAAW,IAAI;gBAC3B,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;gBAE3E,kEAAkE;gBAClE,MAAM,GAAG,GAAG,IAAI,cAAc,CAC5B,OAAO,EACP,MAAM,CAAC,OAAO,EACd,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,KAAc,EACnB,GAAG,EACH,SAAS,EACT,WAAW,EACX,kBAAkB,CACnB,CAAA;gBACD,MAAM,QAAQ,GAAG,GAAqD,CAAA;gBACtE,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;gBACjD,IAAI,MAAM,EAAE;oBACV,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;oBAC1B,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;iBAC9B;gBACD,OAAO,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;YACtC,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { ERC20__factory, ERC721__factory } from './builtin/internal/index.js'\nimport { AddressType, EthFetchConfig, ProcessResult } from '@sentio/protos'\nimport { AccountBindOptions } from './bind-options.js'\n\nimport { Network } from 'ethers/providers'\n\nimport { TransferEvent as ERC20TransferEvent, ERC20Processor } from './builtin/erc20.js'\nimport { TransferEvent as ERC721TransferEvent, ERC721Processor } from './builtin/erc721.js'\n\nimport { AccountContext } from './context.js'\nimport { PromiseOrVoid } from '../promise-or-void.js'\nimport { AddressOrTypeEventFilter, EventsHandler } from './base-processor.js'\nimport { Block, LogDescription } from 'ethers'\nimport { AccountProcessorState } from './account-processor-state.js'\nimport { formatEthData } from './eth.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, block, transaction, transactionReceipt } = formatEthData(data)\n\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,\n undefined,\n transaction,\n transactionReceipt\n )\n const logParam = log as any as { topics: Array<string>; data: string }\n const parsed = ERC20_INTERFACE.parseLog(logParam)\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,6BAA6B,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG3E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,OAAO,EAAuC,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxF,OAAO,EAAwC,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE3F,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAI7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,eAAe,GAAG,cAAc,CAAC,eAAe,EAAE,CAAA;AACxD,MAAM,gBAAgB,GAAG,eAAe,CAAC,eAAe,EAAE,CAAA;AAE1D,MAAM,OAAO,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,qBAAqB,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAClD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,YAAsB,MAA0B;QAC9C,IAAI,CAAC,MAAM,GAAG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;QAEJ,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QAE1B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,QAAQ;YACjB,WAAW,EAAE,cAAc,CAAC,WAAW,CAAC,WAAW,IAAI,EAAE,CAAC;YAC1D,OAAO,EAAE,KAAK,WAAW,IAAI;gBAC3B,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;gBAE3E,kEAAkE;gBAClE,MAAM,GAAG,GAAG,IAAI,cAAc,CAC5B,OAAO,EACP,MAAM,CAAC,OAAO,EACd,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,KAAc,EACnB,GAAG,EACH,SAAS,EACT,WAAW,EACX,kBAAkB,CACnB,CAAA;gBACD,MAAM,QAAQ,GAAG,GAAqD,CAAA;gBACtE,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;gBACjD,IAAI,MAAM,EAAE;oBACV,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;oBAC1B,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;iBAC9B;gBACD,OAAO,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;YACtC,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { ERC20__factory, ERC721__factory } from './builtin/internal/index.js'\nimport { AddressType, EthFetchConfig, ProcessResult } from '@sentio/protos'\nimport { AccountBindOptions } from './bind-options.js'\n\nimport { Network } from 'ethers/providers'\n\nimport { TransferEvent as ERC20TransferEvent, ERC20Processor } from './builtin/erc20.js'\nimport { TransferEvent as ERC721TransferEvent, ERC721Processor } from './builtin/erc721.js'\n\nimport { AccountContext } from './context.js'\nimport { PromiseOrVoid } from '../promise-or-void.js'\nimport { AddressOrTypeEventFilter, EventsHandler } from './base-processor.js'\nimport { Block, LogDescription } from 'ethers'\nimport { AccountProcessorState } from './account-processor-state.js'\nimport { formatEthData } from './eth.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?: Partial<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?: Partial<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?: Partial<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?: Partial<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?: Partial<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?: Partial<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?: Partial<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?: Partial<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?: Partial<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?: Partial<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: EthFetchConfig.fromPartial(fetchConfig || {}),\n handler: async function (data) {\n const { log, block, transaction, transactionReceipt } = formatEthData(data)\n\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,\n undefined,\n transaction,\n transactionReceipt\n )\n const logParam = log as any as { topics: Array<string>; data: string }\n const parsed = ERC20_INTERFACE.parseLog(logParam)\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"]}
|
@@ -35,10 +35,10 @@ export declare abstract class BaseProcessorTemplate<TContract extends BaseContra
|
|
35
35
|
}[];
|
36
36
|
constructor();
|
37
37
|
bind(options: BindOptions): BaseProcessor<TContract, TBoundContractView> | undefined;
|
38
|
-
onEvent(handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: EthFetchConfig): this;
|
38
|
+
onEvent(handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
39
39
|
onBlockInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number): this;
|
40
40
|
onTimeInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillBlockInterval?: number): this;
|
41
41
|
onInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeInterval: HandleInterval | undefined, blockInterval: HandleInterval | undefined): this;
|
42
|
-
onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
42
|
+
onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, fetchConfig?: Partial<EthFetchConfig>): this;
|
43
43
|
protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>;
|
44
44
|
}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { getOptionsSignature } from './bind-options.js';
|
2
|
+
import { EthFetchConfig } from '@sentio/protos';
|
2
3
|
import { ListStateStorage } from '@sentio/runtime';
|
3
4
|
import { Network } from 'ethers/providers';
|
4
5
|
export class ProcessorTemplateProcessorState extends ListStateStorage {
|
@@ -57,7 +58,7 @@ export class BaseProcessorTemplate {
|
|
57
58
|
this.eventHandlers.push({
|
58
59
|
handler: handler,
|
59
60
|
filter: filter,
|
60
|
-
fetchConfig: fetchConfig,
|
61
|
+
fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
|
61
62
|
});
|
62
63
|
return this;
|
63
64
|
}
|
@@ -74,8 +75,8 @@ export class BaseProcessorTemplate {
|
|
74
75
|
this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval });
|
75
76
|
return this;
|
76
77
|
}
|
77
|
-
onTrace(signature, handler) {
|
78
|
-
this.traceHandlers.push({ signature, handler });
|
78
|
+
onTrace(signature, handler, fetchConfig) {
|
79
|
+
this.traceHandlers.push({ signature, handler, fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}) });
|
79
80
|
return this;
|
80
81
|
}
|
81
82
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;
|
1
|
+
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAoC,MAAM,gBAAgB,CAAA;AAGjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAe,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAIvD,MAAM,OAAO,+BAAgC,SAAQ,gBAEpD;IACC,MAAM,CAAC,QAAQ,GAAG,IAAI,+BAA+B,EAAE,CAAA;;AAGzD,MAAM,OAAO,qBAAsB,SAAQ,gBAAkC;IAC3E,MAAM,C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AG,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,OAAmG,EACnG,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,EAC7F,WAAqC;QAErC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,WAAW,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;QAC3G,OAAO,IAAI,CAAA;IACb,CAAC;CAGF","sourcesContent":["import { BoundContractView, ContractContext, ContractView } from './context.js'\nimport { BaseContract } from 'ethers'\nimport { BaseProcessor } from './base-processor.js'\nimport { BindOptions, getOptionsSignature } from './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 { BlockParams, Network } from 'ethers/providers'\nimport { DeferredTopicFilter } from 'ethers/contract'\nimport { EthEvent } from './eth.js'\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: BlockParams, 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: EthEvent, 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: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: Partial<EthFetchConfig>\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: BlockParams, 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: BlockParams, 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: BlockParams, 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 fetchConfig?: Partial<EthFetchConfig>\n ) {\n this.traceHandlers.push({ signature, handler, fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}) })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>\n}\n"]}
|
@@ -33,10 +33,10 @@ export declare abstract class BaseProcessor<TContract extends BaseContract, TBou
|
|
33
33
|
constructor(config: BindOptions);
|
34
34
|
protected abstract CreateBoundContractView(): TBoundContractView;
|
35
35
|
getChainId(): number;
|
36
|
-
onEvent(handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: EthFetchConfig): this;
|
36
|
+
onEvent(handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
37
37
|
onBlockInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number): this;
|
38
38
|
onTimeInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number): this;
|
39
39
|
onInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeInterval: HandleInterval | undefined, blockInterval: HandleInterval | undefined): this;
|
40
40
|
onAllEvents(handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
|
41
|
-
onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, fetchConfig?: EthFetchConfig): this;
|
41
|
+
onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, fetchConfig?: Partial<EthFetchConfig>): this;
|
42
42
|
}
|
@@ -59,7 +59,7 @@ export class BaseProcessor {
|
|
59
59
|
const processor = this;
|
60
60
|
this.eventHandlers.push({
|
61
61
|
filters: _filters,
|
62
|
-
fetchConfig: fetchConfig ||
|
62
|
+
fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
|
63
63
|
handler: async function (data) {
|
64
64
|
const { log, block, transaction, transactionReceipt } = formatEthData(data);
|
65
65
|
if (!log) {
|
@@ -127,7 +127,7 @@ export class BaseProcessor {
|
|
127
127
|
const processor = this;
|
128
128
|
this.traceHandlers.push({
|
129
129
|
signature,
|
130
|
-
fetchConfig: fetchConfig ||
|
130
|
+
fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),
|
131
131
|
handler: async function (data) {
|
132
132
|
const contractView = processor.CreateBoundContractView();
|
133
133
|
const contractInterface = contractView.rawContract.interface;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base-processor.js","sourceR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AAE,CAAC,CAAA;gBACrD,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;gBAErF,MAAM,GAAG,GAAG,IAAI,eAAe,CAC7B,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,IAAI,CAAC,SAAS,EACd,KAAK,EACL,SAAS,EACT,KAAK,EACL,WAAW,EACX,kBAAkB,CACnB,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","sourcesContent":["import { BaseContract, DeferredTopicFilter } from 'ethers'\nimport { BlockParams, Network } from 'ethers/providers'\n\nimport { BoundContractView, ContractContext, ContractView } from './context.js'\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 './bind-options.js'\nimport { PromiseOrVoid } from '../promise-or-void.js'\nimport { Trace } from './trace.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { decodeResult, EthEvent, formatEthData } from './eth.js'\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: EthEvent, 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 const { log, block, transaction, transactionReceipt } = formatEthData(data)\n if (!log) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')\n }\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n block,\n log,\n undefined,\n transaction,\n transactionReceipt\n )\n const logParam = log as any as { topics: Array<string>; data: string }\n\n const parsed = contractView.rawContract.interface.parseLog(logParam)\n\n if (parsed) {\n const event: EthEvent = { ...log, name: parsed.name, args: decodeResult(parsed) }\n await handler(event, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 250,\n backfillBlockInterval = 1000\n ) {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: BlockParams, 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: BlockParams, 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 const { block } = formatEthData(data)\n\n if (!block) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')\n }\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(handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\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 const { trace, block, transaction, transactionReceipt } = formatEthData(data)\n if (!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, true)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n block,\n undefined,\n trace,\n transaction,\n transactionReceipt\n )\n await handler(trace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/eth/base-processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,EAAqB,eAAe,EAAgB,MAAM,cAAc,CAAA;AAC/E,OAAO,EAKL,cAAc,EAEd,aAAa,GACd,MAAM,gBAAgB,CAAA;AAIvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAY,aAAa,EAAE,MAAM,UAAU,CAAA;AAOhE,MAAM,OAAO,aAAa;IACxB,OAAO,CAA4B;IACnC,OAAO,CAAgD;IACvD,WAAW,CAAgB;CAC5B;AAED,MAAM,OAAO,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAAkD;IACzD,WAAW,CAAgB;CAC5B;AAED,MAAM,OAAO,aAAa;IACxB,aAAa,CAAiB;IAC9B,qBAAqB,CAAiB;IACtC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BAC1C,MAAM,YAAY,GAAG,SAAS,CAAC,uBAAuB,EAAE,CAAA;gBACxD,MAAM,iBAAiB,GAAG,YAAY,CAAC,WAAW,CAAC,SAAS,CAAA;gBAC5D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;gBACzD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;gBAC7E,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE;oBACvB,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAA;iBAChE;gBACD,oCAAoC;gBACpC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;oBACxB,OAAO,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;iBACrC;gBACD,MAAM,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;gBACrD,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;gBAErF,MAAM,GAAG,GAAG,IAAI,eAAe,CAC7B,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,IAAI,CAAC,SAAS,EACd,KAAK,EACL,SAAS,EACT,KAAK,EACL,WAAW,EACX,kBAAkB,CACnB,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","sourcesContent":["import { BaseContract, DeferredTopicFilter } from 'ethers'\nimport { BlockParams, Network } from 'ethers/providers'\n\nimport { BoundContractView, ContractContext, ContractView } from './context.js'\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 './bind-options.js'\nimport { PromiseOrVoid } from '../promise-or-void.js'\nimport { Trace } from './trace.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { decodeResult, EthEvent, formatEthData } from './eth.js'\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: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: Partial<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: EthFetchConfig.fromPartial(fetchConfig || {}),\n handler: async function (data: Data_EthLog) {\n const { log, block, transaction, transactionReceipt } = formatEthData(data)\n if (!log) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty')\n }\n const contractView = processor.CreateBoundContractView()\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n block,\n log,\n undefined,\n transaction,\n transactionReceipt\n )\n const logParam = log as any as { topics: Array<string>; data: string }\n\n const parsed = contractView.rawContract.interface.parseLog(logParam)\n\n if (parsed) {\n const event: EthEvent = { ...log, name: parsed.name, args: decodeResult(parsed) }\n await handler(event, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 250,\n backfillBlockInterval = 1000\n ) {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: BlockParams, 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: BlockParams, 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 const { block } = formatEthData(data)\n\n if (!block) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty')\n }\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(handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\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?: Partial<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: EthFetchConfig.fromPartial(fetchConfig || {}),\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 const { trace, block, transaction, transactionReceipt } = formatEthData(data)\n if (!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, true)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n data.timestamp,\n block,\n undefined,\n trace,\n transaction,\n transactionReceipt\n )\n await handler(trace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n}\n"]}
|
@@ -242,33 +242,33 @@ export declare class EACAggregatorProxyBoundContractView extends BoundContractVi
|
|
242
242
|
}
|
243
243
|
export type EACAggregatorProxyContext = ContractContext<EACAggregatorProxy, EACAggregatorProxyBoundContractView>;
|
244
244
|
export declare class EACAggregatorProxyProcessor extends BaseProcessor<EACAggregatorProxy, EACAggregatorProxyBoundContractView> {
|
245
|
-
onEventAnswerUpdated(handler: (event: AnswerUpdatedEvent, ctx: EACAggregatorProxyContext) => void, filter?: AnswerUpdatedEventFilter | AnswerUpdatedEventFilter[], fetchConfig?: EthFetchConfig): this;
|
246
|
-
onEventNewRound(handler: (event: NewRoundEvent, ctx: EACAggregatorProxyContext) => void, filter?: NewRoundEventFilter | NewRoundEventFilter[], fetchConfig?: EthFetchConfig): this;
|
247
|
-
onEventOwnershipTransferRequested(handler: (event: OwnershipTransferRequestedEvent, ctx: EACAggregatorProxyContext) => void, filter?: OwnershipTransferRequestedEventFilter | OwnershipTransferRequestedEventFilter[], fetchConfig?: EthFetchConfig): this;
|
248
|
-
onEventOwnershipTransferred(handler: (event: OwnershipTransferredEvent, ctx: EACAggregatorProxyContext) => void, filter?: OwnershipTransferredEventFilter | OwnershipTransferredEventFilter[], fetchConfig?: EthFetchConfig): this;
|
249
|
-
onCallAcceptOwnership(handler: (call: AcceptOwnershipCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
250
|
-
onCallAccessController(handler: (call: AccessControllerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
251
|
-
onCallAggregator(handler: (call: AggregatorCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
252
|
-
onCallConfirmAggregator(handler: (call: ConfirmAggregatorCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
253
|
-
onCallDecimals(handler: (call: DecimalsCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
254
|
-
onCallDescription(handler: (call: DescriptionCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
255
|
-
onCallGetAnswer(handler: (call: GetAnswerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
256
|
-
onCallGetRoundData(handler: (call: GetRoundDataCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
257
|
-
onCallGetTimestamp(handler: (call: GetTimestampCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
258
|
-
onCallLatestAnswer(handler: (call: LatestAnswerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
259
|
-
onCallLatestRound(handler: (call: LatestRoundCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
260
|
-
onCallLatestRoundData(handler: (call: LatestRoundDataCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
261
|
-
onCallLatestTimestamp(handler: (call: LatestTimestampCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
262
|
-
onCallOwner(handler: (call: OwnerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
263
|
-
onCallPhaseAggregators(handler: (call: PhaseAggregatorsCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
264
|
-
onCallPhaseId(handler: (call: PhaseIdCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
265
|
-
onCallProposeAggregator(handler: (call: ProposeAggregatorCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
266
|
-
onCallProposedAggregator(handler: (call: ProposedAggregatorCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
267
|
-
onCallProposedGetRoundData(handler: (call: ProposedGetRoundDataCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
268
|
-
onCallProposedLatestRoundData(handler: (call: ProposedLatestRoundDataCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
269
|
-
onCallSetController(handler: (call: SetControllerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
270
|
-
onCallTransferOwnership(handler: (call: TransferOwnershipCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
271
|
-
onCallVersion(handler: (call: VersionCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: EthFetchConfig): this;
|
245
|
+
onEventAnswerUpdated(handler: (event: AnswerUpdatedEvent, ctx: EACAggregatorProxyContext) => void, filter?: AnswerUpdatedEventFilter | AnswerUpdatedEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
246
|
+
onEventNewRound(handler: (event: NewRoundEvent, ctx: EACAggregatorProxyContext) => void, filter?: NewRoundEventFilter | NewRoundEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
247
|
+
onEventOwnershipTransferRequested(handler: (event: OwnershipTransferRequestedEvent, ctx: EACAggregatorProxyContext) => void, filter?: OwnershipTransferRequestedEventFilter | OwnershipTransferRequestedEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
248
|
+
onEventOwnershipTransferred(handler: (event: OwnershipTransferredEvent, ctx: EACAggregatorProxyContext) => void, filter?: OwnershipTransferredEventFilter | OwnershipTransferredEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
249
|
+
onCallAcceptOwnership(handler: (call: AcceptOwnershipCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
250
|
+
onCallAccessController(handler: (call: AccessControllerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
251
|
+
onCallAggregator(handler: (call: AggregatorCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
252
|
+
onCallConfirmAggregator(handler: (call: ConfirmAggregatorCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
253
|
+
onCallDecimals(handler: (call: DecimalsCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
254
|
+
onCallDescription(handler: (call: DescriptionCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
255
|
+
onCallGetAnswer(handler: (call: GetAnswerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
256
|
+
onCallGetRoundData(handler: (call: GetRoundDataCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
257
|
+
onCallGetTimestamp(handler: (call: GetTimestampCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
258
|
+
onCallLatestAnswer(handler: (call: LatestAnswerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
259
|
+
onCallLatestRound(handler: (call: LatestRoundCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
260
|
+
onCallLatestRoundData(handler: (call: LatestRoundDataCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
261
|
+
onCallLatestTimestamp(handler: (call: LatestTimestampCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
262
|
+
onCallOwner(handler: (call: OwnerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
263
|
+
onCallPhaseAggregators(handler: (call: PhaseAggregatorsCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
264
|
+
onCallPhaseId(handler: (call: PhaseIdCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
265
|
+
onCallProposeAggregator(handler: (call: ProposeAggregatorCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
266
|
+
onCallProposedAggregator(handler: (call: ProposedAggregatorCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
267
|
+
onCallProposedGetRoundData(handler: (call: ProposedGetRoundDataCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
268
|
+
onCallProposedLatestRoundData(handler: (call: ProposedLatestRoundDataCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
269
|
+
onCallSetController(handler: (call: SetControllerCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
270
|
+
onCallTransferOwnership(handler: (call: TransferOwnershipCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
271
|
+
onCallVersion(handler: (call: VersionCallTrace, ctx: EACAggregatorProxyContext) => void, fetchConfig?: Partial<EthFetchConfig>): this;
|
272
272
|
static filters: {
|
273
273
|
AnswerUpdated(current?: BigNumberish | null, roundId?: BigNumberish | null, updatedAt?: null): import("ethers").DeferredTopicFilter;
|
274
274
|
NewRound(roundId?: BigNumberish | null, startedBy?: string | null, startedAt?: null): import("ethers").DeferredTopicFilter;
|
@@ -280,9 +280,9 @@ export declare class EACAggregatorProxyProcessor extends BaseProcessor<EACAggreg
|
|
280
280
|
}
|
281
281
|
export declare class EACAggregatorProxyProcessorTemplate extends BaseProcessorTemplate<EACAggregatorProxy, EACAggregatorProxyBoundContractView> {
|
282
282
|
bindInternal(options: BindOptions): EACAggregatorProxyProcessor;
|
283
|
-
onEventAnswerUpdated(handler: (event: AnswerUpdatedEvent, ctx: EACAggregatorProxyContext) => void, filter?: AnswerUpdatedEventFilter | AnswerUpdatedEventFilter[], fetchConfig?: EthFetchConfig): this;
|
284
|
-
onEventNewRound(handler: (event: NewRoundEvent, ctx: EACAggregatorProxyContext) => void, filter?: NewRoundEventFilter | NewRoundEventFilter[], fetchConfig?: EthFetchConfig): this;
|
285
|
-
onEventOwnershipTransferRequested(handler: (event: OwnershipTransferRequestedEvent, ctx: EACAggregatorProxyContext) => void, filter?: OwnershipTransferRequestedEventFilter | OwnershipTransferRequestedEventFilter[], fetchConfig?: EthFetchConfig): this;
|
286
|
-
onEventOwnershipTransferred(handler: (event: OwnershipTransferredEvent, ctx: EACAggregatorProxyContext) => void, filter?: OwnershipTransferredEventFilter | OwnershipTransferredEventFilter[], fetchConfig?: EthFetchConfig): this;
|
283
|
+
onEventAnswerUpdated(handler: (event: AnswerUpdatedEvent, ctx: EACAggregatorProxyContext) => void, filter?: AnswerUpdatedEventFilter | AnswerUpdatedEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
284
|
+
onEventNewRound(handler: (event: NewRoundEvent, ctx: EACAggregatorProxyContext) => void, filter?: NewRoundEventFilter | NewRoundEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
285
|
+
onEventOwnershipTransferRequested(handler: (event: OwnershipTransferRequestedEvent, ctx: EACAggregatorProxyContext) => void, filter?: OwnershipTransferRequestedEventFilter | OwnershipTransferRequestedEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
286
|
+
onEventOwnershipTransferred(handler: (event: OwnershipTransferredEvent, ctx: EACAggregatorProxyContext) => void, filter?: OwnershipTransferredEventFilter | OwnershipTransferredEventFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
287
287
|
}
|
288
288
|
export declare function getEACAggregatorProxyContract(address: string, network?: Networkish): EACAggregatorProxyContractView;
|