@sentio/sdk 2.14.5-rc.1 → 2.15.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/aptos/api.d.ts +1 -2
- package/lib/aptos/api.js +2 -2
- package/lib/aptos/api.js.map +1 -1
- package/lib/aptos/aptos-processor.js +3 -3
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +2 -2
- package/lib/aptos/context.js +3 -4
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/ext/coin.js +2 -2
- package/lib/aptos/ext/coin.js.map +1 -1
- package/lib/aptos/network.d.ts +7 -7
- package/lib/aptos/network.js +6 -19
- package/lib/aptos/network.js.map +1 -1
- package/lib/core/base-context.d.ts +2 -1
- package/lib/core/base-context.js.map +1 -1
- package/lib/core/chain.d.ts +194 -93
- package/lib/core/chain.js +112 -96
- package/lib/core/chain.js.map +1 -1
- package/lib/core/yaml-contract-config.d.ts +2 -1
- package/lib/core/yaml-contract-config.js.map +1 -1
- package/lib/eth/account-processor.d.ts +3 -2
- package/lib/eth/account-processor.js +3 -3
- package/lib/eth/account-processor.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +2 -3
- package/lib/eth/base-processor-template.js +1 -2
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +5 -5
- package/lib/eth/base-processor.js +5 -5
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/bind-options.d.ts +3 -3
- package/lib/eth/bind-options.js +3 -4
- package/lib/eth/bind-options.js.map +1 -1
- package/lib/eth/binds.d.ts +3 -3
- package/lib/eth/binds.js +1 -3
- package/lib/eth/binds.js.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +2 -4
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +2 -2
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-test-utils.js +5 -4
- package/lib/eth/builtin/internal/eacaggregatorproxy-test-utils.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.d.ts +2 -4
- package/lib/eth/builtin/internal/erc1155-processor.js +2 -2
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-test-utils.js +5 -4
- package/lib/eth/builtin/internal/erc1155-test-utils.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.d.ts +2 -4
- package/lib/eth/builtin/internal/erc20-processor.js +2 -2
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-test-utils.js +4 -3
- package/lib/eth/builtin/internal/erc20-test-utils.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +2 -4
- package/lib/eth/builtin/internal/erc20bytes-processor.js +2 -2
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-test-utils.js +3 -2
- package/lib/eth/builtin/internal/erc20bytes-test-utils.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.d.ts +2 -4
- package/lib/eth/builtin/internal/erc721-processor.js +2 -2
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-test-utils.js +4 -3
- package/lib/eth/builtin/internal/erc721-test-utils.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.d.ts +2 -4
- package/lib/eth/builtin/internal/weth9-processor.js +2 -2
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-test-utils.js +5 -4
- package/lib/eth/builtin/internal/weth9-test-utils.js.map +1 -1
- package/lib/eth/codegen/ethers-sentio.js +11 -4
- package/lib/eth/codegen/ethers-sentio.js.map +1 -1
- package/lib/eth/codegen/file.js +9 -6
- package/lib/eth/codegen/file.js.map +1 -1
- package/lib/eth/context.d.ts +6 -5
- package/lib/eth/context.js +2 -2
- package/lib/eth/context.js.map +1 -1
- package/lib/eth/eth-plugin.js +7 -9
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/index.d.ts +3 -1
- package/lib/eth/index.js +3 -1
- package/lib/eth/index.js.map +1 -1
- package/lib/eth/provider.d.ts +5 -5
- package/lib/eth/provider.js +12 -14
- package/lib/eth/provider.js.map +1 -1
- package/lib/eth/provider.test.js.map +1 -1
- package/lib/solana/solana-context.d.ts +4 -3
- package/lib/solana/solana-context.js +3 -2
- package/lib/solana/solana-context.js.map +1 -1
- package/lib/solana/solana-options.d.ts +2 -1
- package/lib/solana/solana-options.js.map +1 -1
- package/lib/solana/solana-processor.d.ts +2 -1
- package/lib/solana/solana-processor.js +2 -2
- package/lib/solana/solana-processor.js.map +1 -1
- package/lib/sui/context.d.ts +2 -2
- package/lib/sui/context.js +4 -5
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/network.d.ts +7 -7
- package/lib/sui/network.js +6 -19
- package/lib/sui/network.js.map +1 -1
- package/lib/sui/sui-plugin.js +1 -2
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.js +3 -3
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/testing/aptos-facet.js +2 -3
- package/lib/testing/aptos-facet.js.map +1 -1
- package/lib/testing/eth-facet.d.ts +14 -13
- package/lib/testing/eth-facet.js +17 -17
- package/lib/testing/eth-facet.js.map +1 -1
- package/lib/testing/sui-facet.js +2 -3
- package/lib/testing/sui-facet.js.map +1 -1
- package/lib/utils/dex-price.d.ts +3 -2
- package/lib/utils/dex-price.js +3 -2
- package/lib/utils/dex-price.js.map +1 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/lib/utils/price.d.ts +2 -1
- package/lib/utils/price.js.map +1 -1
- package/lib/utils/token.d.ts +3 -4
- package/lib/utils/token.js +2 -2
- package/lib/utils/token.js.map +1 -1
- package/package.json +3 -3
- package/src/aptos/api.ts +2 -2
- package/src/aptos/aptos-processor.ts +3 -3
- package/src/aptos/context.ts +6 -6
- package/src/aptos/ext/coin.ts +2 -2
- package/src/aptos/network.ts +6 -19
- package/src/core/base-context.ts +2 -1
- package/src/core/chain.ts +113 -96
- package/src/core/yaml-contract-config.ts +3 -1
- package/src/eth/account-processor.ts +7 -7
- package/src/eth/base-processor-template.ts +3 -5
- package/src/eth/base-processor.ts +9 -10
- package/src/eth/bind-options.ts +4 -6
- package/src/eth/binds.ts +5 -7
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +5 -5
- package/src/eth/builtin/internal/eacaggregatorproxy-test-utils.ts +17 -4
- package/src/eth/builtin/internal/erc1155-processor.ts +5 -5
- package/src/eth/builtin/internal/erc1155-test-utils.ts +5 -4
- package/src/eth/builtin/internal/erc20-processor.ts +5 -5
- package/src/eth/builtin/internal/erc20-test-utils.ts +4 -3
- package/src/eth/builtin/internal/erc20bytes-processor.ts +5 -5
- package/src/eth/builtin/internal/erc20bytes-test-utils.ts +3 -2
- package/src/eth/builtin/internal/erc721-processor.ts +5 -5
- package/src/eth/builtin/internal/erc721-test-utils.ts +4 -3
- package/src/eth/builtin/internal/weth9-processor.ts +5 -5
- package/src/eth/builtin/internal/weth9-test-utils.ts +5 -4
- package/src/eth/codegen/ethers-sentio.ts +12 -5
- package/src/eth/codegen/file.ts +9 -6
- package/src/eth/context.ts +8 -7
- package/src/eth/eth-plugin.ts +7 -10
- package/src/eth/index.ts +4 -1
- package/src/eth/provider.ts +13 -15
- package/src/solana/solana-context.ts +12 -5
- package/src/solana/solana-options.ts +2 -1
- package/src/solana/solana-processor.ts +3 -3
- package/src/sui/context.ts +7 -7
- package/src/sui/network.ts +6 -19
- package/src/sui/sui-plugin.ts +1 -2
- package/src/sui/sui-processor.ts +3 -3
- package/src/testing/aptos-facet.ts +2 -3
- package/src/testing/eth-facet.ts +33 -18
- package/src/testing/sui-facet.ts +2 -3
- package/src/utils/dex-price.ts +5 -4
- package/src/utils/price.ts +2 -1
- package/src/utils/token.ts +5 -6
package/lib/utils/price.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { CoinID, PriceServiceClient } from '@sentio/protos/price';
|
2
2
|
import { RetryOptions } from 'nice-grpc-client-middleware-retry';
|
3
|
+
import { ChainId } from '../core/chain.js';
|
3
4
|
export declare function getPriceClient(address?: string): import("nice-grpc").RawClient<import("nice-grpc/lib/service-definitions/ts-proto.js").FromTsProtoServiceDefinition<{
|
4
5
|
readonly name: "PriceService";
|
5
6
|
readonly fullName: "price_service.PriceService";
|
@@ -183,7 +184,7 @@ export declare function getPriceByTypeOrSymbolInternal(priceClient: PriceService
|
|
183
184
|
* @param date
|
184
185
|
* @param options other behavior options
|
185
186
|
*/
|
186
|
-
export declare function getPriceByType(chainId:
|
187
|
+
export declare function getPriceByType(chainId: ChainId, coinType: string, date: Date, options?: PriceOptions): Promise<number | undefined>;
|
187
188
|
/**
|
188
189
|
* @param symbol token symbol like BTC, etc
|
189
190
|
* @param date
|
package/lib/utils/price.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,eAAe,EAAgB,MAAM,mCAAmC,CAAA;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAA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CAAC,CAAA;IACT,CAAC,CAAC,CAAA;IACJ,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACxB,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAgB,EAChB,QAAgB,EAChB,IAAU,EACV,OAAsB;IAEtB,OAAO,sBAAsB,CAC3B,IAAI,EACJ;QACE,OAAO,EAAE;YACP,KAAK,EAAE,OAAO;YACd,OAAO,EAAE,QAAQ;SAClB;KACF,EACD,OAAO,CACR,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAc,EACd,IAAU,EACV,OAAsB;IAEtB,OAAO,sBAAsB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAA;AAC1D,CAAC;AAED,SAAS,UAAU,CAAC,IAAU;IAC5B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACrF,CAAC","sourcesContent":["import { CoinID, PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/price'\nimport { createChannel, createClientFactory, Status } from 'nice-grpc'\nimport { prometheusClientMiddleware } from 'nice-grpc-prometheus'\nimport { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'\nimport { Endpoints } from '@sentio/runtime'\nimport { ChainId } from '../core/chain.js'\n\nexport function getPriceClient(address?: string) {\n if (!address) {\n address = Endpoints.INSTANCE.priceFeedAPI\n }\n const channel = createChannel(address)\n\n return createClientFactory()\n .use(prometheusClientMiddleware())\n .use(retryMiddleware)\n .create(PriceServiceDefinition, channel)\n}\n\nconst priceMap = new Map<string, Promise<number | undefined>>()\nlet priceClient: PriceServiceClient<RetryOptions>\n\ninterface PriceOptions {\n toleranceInDays?: number\n}\nasync function getPriceByTypeOrSymbol(date: Date, coinId: CoinID, options?: PriceOptions): Promise<number | undefined> {\n if (!priceClient) {\n priceClient = getPriceClient()\n }\n return getPriceByTypeOrSymbolInternal(priceClient, date, coinId, options)\n}\n\nexport async function getPriceByTypeOrSymbolInternal(\n priceClient: PriceServiceClient<RetryOptions>,\n date: Date,\n coinId: CoinID,\n options?: PriceOptions\n): Promise<number | undefined> {\n const dateStr = dateString(date)\n const todayDateString = dateString(new Date())\n\n let key: string\n if (coinId.symbol) {\n key = `${coinId.symbol}-${dateStr}`\n } else {\n key = `${coinId.address?.address}-${coinId.address?.chain}-${dateStr}`\n }\n let price = priceMap.get(key)\n if (price) {\n return price\n }\n\n const response = priceClient.getPrice(\n {\n timestamp: date,\n coinId,\n },\n {\n retry: true,\n retryMaxAttempts: 5,\n }\n )\n price = response\n .then((res) => {\n if (res.timestamp) {\n const responseDateString = dateString(res.timestamp)\n if (responseDateString === todayDateString) {\n priceMap.delete(key)\n } else {\n // https://www.javatpoint.com/javascript-date-difference\n const diff = Math.abs(res.timestamp.getTime() - date.getTime())\n const daysDiff = diff / (1000 * 60 * 60 * 24)\n const tolerance = options?.toleranceInDays || 2\n if (daysDiff > tolerance) {\n priceMap.delete(key)\n return undefined\n }\n }\n } else {\n priceMap.delete(key)\n }\n return res.price\n })\n .catch((e) => {\n if (e.code === Status.NOT_FOUND) {\n return undefined\n }\n throw e\n })\n priceMap.set(key, price)\n return price\n}\n\n/**\n *\n * @param chainId chain id refers to CHAIN_MAP\n * @param coinType\n * @param date\n * @param options other behavior options\n */\nexport async function getPriceByType(\n chainId: ChainId,\n coinType: string,\n date: Date,\n options?: PriceOptions\n): Promise<number | undefined> {\n return getPriceByTypeOrSymbol(\n date,\n {\n address: {\n chain: chainId,\n address: coinType,\n },\n },\n options\n )\n}\n\n/**\n * @param symbol token symbol like BTC, etc\n * @param date\n * @param options other behavior options\n */\nexport async function getPriceBySymbol(\n symbol: string,\n date: Date,\n options?: PriceOptions\n): Promise<number | undefined> {\n return getPriceByTypeOrSymbol(date, { symbol }, options)\n}\n\nfunction dateString(date: Date) {\n return [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')\n}\n"]}
|
package/lib/utils/token.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { BigDecimal } from '../core/big-decimal.js';
|
2
|
-
import {
|
3
|
-
import { BaseContext } from '../core/index.js';
|
2
|
+
import { EthChainId, EthContext } from '../eth/index.js';
|
4
3
|
export interface TokenInfo {
|
5
4
|
symbol: string;
|
6
5
|
name: string;
|
@@ -11,5 +10,5 @@ export declare const NATIVE_ETH: {
|
|
11
10
|
decimal: number;
|
12
11
|
name: string;
|
13
12
|
};
|
14
|
-
export declare function getERC20TokenInfo(contextOrNetworkish:
|
15
|
-
export declare function getER20NormalizedAmount(contextOrNetworkish:
|
13
|
+
export declare function getERC20TokenInfo(contextOrNetworkish: EthContext | EthChainId, tokenAddress: string): Promise<TokenInfo>;
|
14
|
+
export declare function getER20NormalizedAmount(contextOrNetworkish: EthContext | EthChainId, tokenAddress: string, amount: bigint): Promise<BigDecimal>;
|
package/lib/utils/token.js
CHANGED
@@ -2,7 +2,7 @@ import { getERC20Contract } from '../eth/builtin/erc20.js';
|
|
2
2
|
import { getERC20BytesContract } from '../eth/builtin/erc20bytes.js';
|
3
3
|
import { scaleDown } from '../core/big-decimal.js';
|
4
4
|
import { decodeBytes32String } from 'ethers';
|
5
|
-
import {
|
5
|
+
import { getEthChainId } from '../eth/index.js';
|
6
6
|
export const NATIVE_ETH = {
|
7
7
|
symbol: 'ETH',
|
8
8
|
decimal: 18,
|
@@ -17,7 +17,7 @@ async function getTokenInfoPromise(symbol, name, decimal) {
|
|
17
17
|
};
|
18
18
|
}
|
19
19
|
export async function getERC20TokenInfo(contextOrNetworkish, tokenAddress) {
|
20
|
-
const chainId =
|
20
|
+
const chainId = getEthChainId(contextOrNetworkish);
|
21
21
|
const key = chainId + tokenAddress;
|
22
22
|
const res = TOKEN_INFOS.get(key);
|
23
23
|
if (res) {
|
package/lib/utils/token.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAc,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,EAAE,mBAAmB,
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAc,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAA0B,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAQvE,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,YAAY;CACnB,CAAA;AAED,MAAM,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAA;AAEzD,KAAK,UAAU,mBAAmB,CAChC,MAAuC,EACvC,IAAqC,EACrC,OAA+B;IAE/B,OAAO;QACL,MAAM,EAAE,MAAM,MAAM;QACpB,IAAI,EAAE,MAAM,IAAI;QAChB,OAAO,EAAE,MAAM,CAAC,MAAM,OAAO,CAAC;KAC/B,CAAA;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,mBAA4C,EAC5C,YAAoB;IAEpB,MAAM,OAAO,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAA;IAClD,MAAM,GAAG,GAAG,OAAO,GAAG,YAA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/erc20bytes.js'\nimport { BigDecimal, scaleDown } from '../core/big-decimal.js'\nimport { PromiseOrValue } from '../eth/builtin/internal/common.js'\nimport { decodeBytes32String } from 'ethers'\nimport { EthChainId, EthContext, getEthChainId } from '../eth/index.js'\n\nexport interface TokenInfo {\n symbol: string\n name: string\n decimal: number\n}\n\nexport const NATIVE_ETH = {\n symbol: 'ETH',\n decimal: 18,\n name: 'Native ETH',\n}\n\nconst TOKEN_INFOS = new Map<string, Promise<TokenInfo>>()\n\nasync function getTokenInfoPromise(\n symbol: PromiseOrValue<string> | string,\n name: PromiseOrValue<string> | string,\n decimal: PromiseOrValue<bigint>\n): Promise<TokenInfo> {\n return {\n symbol: await symbol,\n name: await name,\n decimal: Number(await decimal),\n }\n}\n\nexport async function getERC20TokenInfo(\n contextOrNetworkish: EthContext | EthChainId,\n tokenAddress: string\n): Promise<TokenInfo> {\n const chainId = getEthChainId(contextOrNetworkish)\n const key = chainId + tokenAddress\n const res = TOKEN_INFOS.get(key)\n if (res) {\n return res\n }\n const contract = getERC20Contract(chainId, tokenAddress)\n const bytesContract = getERC20BytesContract(chainId, tokenAddress)\n\n let name = ''\n try {\n name = await contract.name()\n } catch (e) {\n name = decodeBytes32String(await bytesContract.name())\n }\n\n let symbol = ''\n try {\n symbol = await contract.symbol()\n } catch (e) {\n symbol = decodeBytes32String(await bytesContract.symbol())\n }\n\n const decimal = await contract.decimals()\n const info = getTokenInfoPromise(symbol, name, decimal)\n\n TOKEN_INFOS.set(key, info)\n return info\n}\n\nexport async function getER20NormalizedAmount(\n contextOrNetworkish: EthContext | EthChainId,\n tokenAddress: string,\n amount: bigint\n): Promise<BigDecimal> {\n const tokenInfo = await getERC20TokenInfo(contextOrNetworkish, tokenAddress)\n return scaleDown(amount, tokenInfo.decimal)\n}\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.15.0-rc.1",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -68,8 +68,8 @@
|
|
68
68
|
"typechain": "^8.0.0",
|
69
69
|
"typedoc": "^0.24.1",
|
70
70
|
"yaml": "^2.2.1",
|
71
|
-
"@sentio/protos": "^2.
|
72
|
-
"@sentio/runtime": "^2.
|
71
|
+
"@sentio/protos": "^2.15.0-rc.1",
|
72
|
+
"@sentio/runtime": "^2.15.0-rc.1"
|
73
73
|
},
|
74
74
|
"peerDependencies": {
|
75
75
|
"tsup": "npm:@sentio/tsup@^6.7.0"
|
package/src/aptos/api.ts
CHANGED
@@ -4,7 +4,7 @@ import { Endpoints } from '@sentio/runtime'
|
|
4
4
|
import { retryMiddleware } from 'nice-grpc-client-middleware-retry'
|
5
5
|
import { prometheusClientMiddleware } from 'nice-grpc-prometheus'
|
6
6
|
import { AptosClient } from 'aptos-sdk'
|
7
|
-
import { AptosNetwork
|
7
|
+
import { AptosNetwork } from './network.js'
|
8
8
|
|
9
9
|
export function getChainQueryClient(address?: string): AptosQueryClient {
|
10
10
|
if (!address) {
|
@@ -19,7 +19,7 @@ export function getChainQueryClient(address?: string): AptosQueryClient {
|
|
19
19
|
}
|
20
20
|
|
21
21
|
export function getAptosClient(network = AptosNetwork.MAIN_NET): AptosClient | undefined {
|
22
|
-
const chainServer = Endpoints.INSTANCE.chainServer.get(
|
22
|
+
const chainServer = Endpoints.INSTANCE.chainServer.get(network)
|
23
23
|
if (chainServer) {
|
24
24
|
return new AptosClient(chainServer)
|
25
25
|
}
|
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
} from './move-types.js'
|
7
7
|
|
8
8
|
import { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
9
|
-
import { AptosBindOptions, AptosNetwork
|
9
|
+
import { AptosBindOptions, AptosNetwork } from './network.js'
|
10
10
|
import { AptosContext, AptosResourcesContext } from './context.js'
|
11
11
|
import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
|
12
12
|
import {
|
@@ -205,7 +205,7 @@ export class AptosBaseProcessor {
|
|
205
205
|
}
|
206
206
|
|
207
207
|
getChainId(): string {
|
208
|
-
return
|
208
|
+
return this.config.network
|
209
209
|
}
|
210
210
|
|
211
211
|
// loadTypes(registry: MoveCoder) {
|
@@ -240,7 +240,7 @@ export class AptosResourcesProcessor {
|
|
240
240
|
}
|
241
241
|
|
242
242
|
getChainId(): string {
|
243
|
-
return
|
243
|
+
return this.config.network
|
244
244
|
}
|
245
245
|
|
246
246
|
private onInterval(
|
package/src/aptos/context.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { RecordMetaData } from '@sentio/protos'
|
2
2
|
import { type Labels, BaseContext, normalizeLabels } from '@sentio/sdk'
|
3
3
|
import { Transaction_UserTransaction } from './move-types.js'
|
4
|
-
import { AptosNetwork
|
4
|
+
import { AptosNetwork } from './network.js'
|
5
5
|
import { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
6
6
|
import { Endpoints } from '@sentio/runtime'
|
7
7
|
import { ServerError, Status } from 'nice-grpc'
|
@@ -37,8 +37,8 @@ export class AptosContext extends BaseContext {
|
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
|
-
getChainId()
|
41
|
-
return
|
40
|
+
getChainId() {
|
41
|
+
return this.network
|
42
42
|
}
|
43
43
|
|
44
44
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
@@ -72,8 +72,8 @@ export class AptosResourcesContext extends BaseContext {
|
|
72
72
|
this.coder = defaultMoveCoder(network)
|
73
73
|
}
|
74
74
|
|
75
|
-
getChainId()
|
76
|
-
return
|
75
|
+
getChainId() {
|
76
|
+
return this.network
|
77
77
|
}
|
78
78
|
|
79
79
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
@@ -91,7 +91,7 @@ export class AptosResourcesContext extends BaseContext {
|
|
91
91
|
}
|
92
92
|
|
93
93
|
getClient(): AptosClient {
|
94
|
-
const chainServer = Endpoints.INSTANCE.chainServer.get(
|
94
|
+
const chainServer = Endpoints.INSTANCE.chainServer.get(this.network)
|
95
95
|
if (!chainServer) {
|
96
96
|
throw new ServerError(Status.INTERNAL, 'RPC endpoint not provided')
|
97
97
|
}
|
package/src/aptos/ext/coin.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { getPriceByType } from '@sentio/sdk/utils'
|
2
|
-
import { CHAIN_IDS } from '@sentio/sdk'
|
3
2
|
import fetch from 'node-fetch'
|
4
3
|
import { validateAndNormalizeAddress } from '../utils.js'
|
5
4
|
import { SPLITTER } from '../../move/index.js'
|
5
|
+
import { AptosChainId } from '../../core/chain.js'
|
6
6
|
|
7
7
|
const WHITELISTED_COINS = new Map<string, SimpleCoinInfo>()
|
8
8
|
|
@@ -74,7 +74,7 @@ export async function getPrice(coinType: string, timestamp: number): Promise<num
|
|
74
74
|
}
|
75
75
|
const date = new Date(timestamp / 1000)
|
76
76
|
try {
|
77
|
-
return (await getPriceByType(
|
77
|
+
return (await getPriceByType(AptosChainId.APTOS_MAINNET, coinType, date)) || 0
|
78
78
|
} catch (error) {
|
79
79
|
console.log(JSON.stringify(error))
|
80
80
|
throw error
|
package/src/aptos/network.ts
CHANGED
@@ -1,25 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import { AptosChainId } from '../core/chain.js'
|
2
2
|
import { AptosClient } from 'aptos-sdk'
|
3
3
|
import { Labels } from '../core/index.js'
|
4
4
|
|
5
|
-
export
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
export function getChainId(network: AptosNetwork): string {
|
12
|
-
switch (network) {
|
13
|
-
case AptosNetwork.TEST_NET:
|
14
|
-
return CHAIN_IDS.APTOS_TESTNET
|
15
|
-
case AptosNetwork.DEV_NET:
|
16
|
-
return CHAIN_IDS.APTOS_DEVNET
|
17
|
-
}
|
18
|
-
return CHAIN_IDS.APTOS_MAINNET
|
19
|
-
}
|
20
|
-
|
21
|
-
export function getAptosChainName(network: AptosNetwork): string {
|
22
|
-
return getChainName(getChainId(network))
|
5
|
+
export type AptosNetwork = AptosChainId
|
6
|
+
export const AptosNetwork = <const>{
|
7
|
+
MAIN_NET: AptosChainId.APTOS_MAINNET,
|
8
|
+
TEST_NET: AptosChainId.APTOS_TESTNET,
|
9
|
+
DEV_NET: AptosChainId.APTOS_DEVNET,
|
23
10
|
}
|
24
11
|
|
25
12
|
export class AptosBindOptions {
|
package/src/core/base-context.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { ProcessResult, RecordMetaData, StateResult } from '@sentio/protos'
|
2
2
|
import { EventLogger } from './event-logger.js'
|
3
3
|
import { Meter, Labels } from './meter.js'
|
4
|
+
import { ChainId } from './chain.js'
|
4
5
|
|
5
6
|
export abstract class BaseContext {
|
6
7
|
meter: Meter
|
@@ -36,5 +37,5 @@ export abstract class BaseContext {
|
|
36
37
|
|
37
38
|
protected abstract getMetaDataInternal(name: string, labels: Labels): RecordMetaData
|
38
39
|
|
39
|
-
abstract getChainId():
|
40
|
+
abstract getChainId(): ChainId
|
40
41
|
}
|
package/src/core/chain.ts
CHANGED
@@ -1,107 +1,124 @@
|
|
1
1
|
// copy from https://github.com/DefiLlama/chainlist/blob/main/constants/chainIds.js
|
2
2
|
// and https://besu.hyperledger.org/en/stable/Concepts/NetworkID-And-ChainID/
|
3
3
|
|
4
|
-
export
|
5
|
-
KARDIA
|
6
|
-
ETHEREUM
|
7
|
-
EXPANSE
|
8
|
-
ROPSTEN
|
9
|
-
RINKEBY
|
10
|
-
GOERLI
|
11
|
-
KOTTI
|
12
|
-
UBIQ
|
13
|
-
OPTIMISM
|
14
|
-
SONGBIRD
|
15
|
-
ELASTOS
|
16
|
-
CRONOS
|
17
|
-
RSK
|
18
|
-
TELOS
|
19
|
-
XDC
|
20
|
-
CSC
|
21
|
-
ZYX
|
22
|
-
BINANCE
|
23
|
-
SYSCOIN
|
24
|
-
GOCHAIN
|
25
|
-
ETHCLASSIC
|
26
|
-
MORDOR
|
27
|
-
OKEXCHAIN
|
28
|
-
HOO
|
29
|
-
METER
|
30
|
-
TOMOCHAIN
|
31
|
-
BINANCE_TEST
|
32
|
-
XDAI
|
33
|
-
VELAS
|
34
|
-
THUNDERCORE
|
35
|
-
FUSE
|
36
|
-
HECO
|
37
|
-
POLYGON
|
38
|
-
XDAIARB
|
39
|
-
ASTOR
|
40
|
-
ENERGYWEB
|
41
|
-
FANTOM
|
42
|
-
HPB
|
43
|
-
BOBA
|
44
|
-
KUCOIN
|
45
|
-
ZKSYNC_ERA
|
46
|
-
SHIDEN
|
47
|
-
THETA
|
48
|
-
SX
|
49
|
-
CANDLE
|
50
|
-
ASTAR
|
51
|
-
CALLISTO
|
52
|
-
WANCHAIN
|
53
|
-
POLYGON_ZKEVM
|
54
|
-
METIS
|
55
|
-
OMCHAIN
|
56
|
-
MOONBEAM
|
57
|
-
MOONRIVER
|
58
|
-
MOONBASE
|
59
|
-
DEV
|
60
|
-
RONIN
|
61
|
-
KAVA
|
62
|
-
EZCHAIN
|
63
|
-
PHI
|
64
|
-
IOTEX
|
65
|
-
XLC
|
66
|
-
NAHMII
|
67
|
-
NMACTEST
|
68
|
-
KLAYTN
|
69
|
-
EVMOS
|
70
|
-
BASE_GOERLI
|
71
|
-
SMARTBCH
|
72
|
-
CRYSTALEUM
|
73
|
-
FUSION
|
74
|
-
ARBITRUM
|
75
|
-
CELO
|
76
|
-
OASIS
|
77
|
-
AVALANCHE
|
78
|
-
GODWOKEN
|
79
|
-
AKROMA
|
80
|
-
POLIS
|
81
|
-
ARBITRUM_GOERLI
|
82
|
-
SEPOLIA
|
83
|
-
AURORA
|
84
|
-
HARMONY
|
85
|
-
PALM
|
86
|
-
CURIO
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
4
|
+
export enum EthChainId {
|
5
|
+
KARDIA = '0',
|
6
|
+
ETHEREUM = '1',
|
7
|
+
EXPANSE = '2',
|
8
|
+
ROPSTEN = '3',
|
9
|
+
RINKEBY = '4',
|
10
|
+
GOERLI = '5',
|
11
|
+
KOTTI = '6',
|
12
|
+
UBIQ = '8',
|
13
|
+
OPTIMISM = '10',
|
14
|
+
SONGBIRD = '19',
|
15
|
+
ELASTOS = '20',
|
16
|
+
CRONOS = '25',
|
17
|
+
RSK = '30',
|
18
|
+
TELOS = '40',
|
19
|
+
XDC = '50',
|
20
|
+
CSC = '52',
|
21
|
+
ZYX = '55',
|
22
|
+
BINANCE = '56',
|
23
|
+
SYSCOIN = '57',
|
24
|
+
GOCHAIN = '60',
|
25
|
+
ETHCLASSIC = '61',
|
26
|
+
MORDOR = '63',
|
27
|
+
OKEXCHAIN = '66',
|
28
|
+
HOO = '70',
|
29
|
+
METER = '82',
|
30
|
+
TOMOCHAIN = '88',
|
31
|
+
BINANCE_TEST = '97',
|
32
|
+
XDAI = '100',
|
33
|
+
VELAS = '106',
|
34
|
+
THUNDERCORE = '108',
|
35
|
+
FUSE = '122',
|
36
|
+
HECO = '128',
|
37
|
+
POLYGON = '137',
|
38
|
+
XDAIARB = '200',
|
39
|
+
ASTOR = '212',
|
40
|
+
ENERGYWEB = '246',
|
41
|
+
FANTOM = '250',
|
42
|
+
HPB = '269',
|
43
|
+
BOBA = '288',
|
44
|
+
KUCOIN = '321',
|
45
|
+
ZKSYNC_ERA = '324',
|
46
|
+
SHIDEN = '336',
|
47
|
+
THETA = '361',
|
48
|
+
SX = '416',
|
49
|
+
CANDLE = '534',
|
50
|
+
ASTAR = '592',
|
51
|
+
CALLISTO = '820',
|
52
|
+
WANCHAIN = '888',
|
53
|
+
POLYGON_ZKEVM = '1101',
|
54
|
+
METIS = '1088',
|
55
|
+
OMCHAIN = '1246',
|
56
|
+
MOONBEAM = '1284',
|
57
|
+
MOONRIVER = '1285',
|
58
|
+
MOONBASE = '1287',
|
59
|
+
DEV = '2018',
|
60
|
+
RONIN = '2020',
|
61
|
+
KAVA = '2222',
|
62
|
+
EZCHAIN = '2612',
|
63
|
+
PHI = '4181',
|
64
|
+
IOTEX = '4689',
|
65
|
+
XLC = '5050',
|
66
|
+
NAHMII = '5551',
|
67
|
+
NMACTEST = '7777',
|
68
|
+
KLAYTN = '8217',
|
69
|
+
EVMOS = '9001',
|
70
|
+
BASE_GOERLI = '84531',
|
71
|
+
SMARTBCH = '10000',
|
72
|
+
CRYSTALEUM = '103090',
|
73
|
+
FUSION = '32659',
|
74
|
+
ARBITRUM = '42161',
|
75
|
+
CELO = '42220',
|
76
|
+
OASIS = '42262',
|
77
|
+
AVALANCHE = '43114',
|
78
|
+
GODWOKEN = '71402',
|
79
|
+
AKROMA = '200625',
|
80
|
+
POLIS = '333999',
|
81
|
+
ARBITRUM_GOERLI = '421613',
|
82
|
+
SEPOLIA = '11155111',
|
83
|
+
AURORA = '1313161554',
|
84
|
+
HARMONY = '1666600000',
|
85
|
+
PALM = '11297108109',
|
86
|
+
CURIO = '836542336838601',
|
87
|
+
}
|
88
|
+
|
89
|
+
export enum AptosChainId {
|
90
|
+
APTOS_MAINNET = 'aptos_mainnet',
|
91
|
+
APTOS_TESTNET = 'aptos_testnet',
|
92
|
+
APTOS_DEVNET = 'aptos_devnet',
|
93
|
+
}
|
94
|
+
|
95
|
+
export enum SuiChainId {
|
96
|
+
SUI_MAINNET = 'sui_mainnet',
|
97
|
+
SUI_TESTNET = 'sui_testnet',
|
98
|
+
SUI_DEVNET = 'sui_devnet',
|
99
|
+
}
|
100
|
+
|
101
|
+
export enum SolanaChainId {
|
102
|
+
SOLANA_MAINNET = 'sol_mainnet',
|
103
|
+
SOLANA_DEVNET = 'sol_devnet',
|
104
|
+
SOLANA_TESTNET = 'sol_testnet',
|
105
|
+
SOLANA_PYTH = 'sol_pyth',
|
106
|
+
}
|
107
|
+
|
108
|
+
export type ChainId = EthChainId | AptosChainId | SuiChainId | SolanaChainId
|
109
|
+
export const ChainId = {
|
110
|
+
...EthChainId,
|
111
|
+
...AptosChainId,
|
112
|
+
...SuiChainId,
|
113
|
+
...SolanaChainId,
|
97
114
|
}
|
98
115
|
|
99
116
|
export const CHAIN_MAP: Record<string, string> = {}
|
100
117
|
|
101
|
-
for (const [key, value] of Object.entries(
|
102
|
-
if (value ===
|
118
|
+
for (const [key, value] of Object.entries(ChainId)) {
|
119
|
+
if (value === ChainId.POLYGON_ZKEVM) {
|
103
120
|
CHAIN_MAP[value] = 'Polygon zkEVM'
|
104
|
-
} else if (value ===
|
121
|
+
} else if (value === ChainId.ZKSYNC_ERA) {
|
105
122
|
CHAIN_MAP[value] = 'zkSync Era'
|
106
123
|
} else {
|
107
124
|
const parts = key.split('_')
|
@@ -1,17 +1,17 @@
|
|
1
1
|
import { ERC20__factory, ERC721__factory } from './builtin/internal/index.js'
|
2
2
|
import { AddressType, EthFetchConfig, ProcessResult } from '@sentio/protos'
|
3
3
|
|
4
|
-
import {
|
4
|
+
import { PartiallyOptional, PromiseOrVoid } from '../core/index.js'
|
5
5
|
|
6
6
|
import { AccountBindOptions } from './bind-options.js'
|
7
|
-
import { TransferEvent as ERC20TransferEvent
|
8
|
-
import { TransferEvent as ERC721TransferEvent
|
7
|
+
import { ERC20Processor, TransferEvent as ERC20TransferEvent } from './builtin/erc20.js'
|
8
|
+
import { ERC721Processor, TransferEvent as ERC721TransferEvent } from './builtin/erc721.js'
|
9
9
|
import { AccountContext } from './context.js'
|
10
10
|
import { AddressOrTypeEventFilter, EventsHandler } from './base-processor.js'
|
11
11
|
import { Block, LogDescription } from 'ethers'
|
12
12
|
import { AccountProcessorState } from './account-processor-state.js'
|
13
13
|
import { formatEthData } from './eth.js'
|
14
|
-
import {
|
14
|
+
import { EthChainId } from '../core/chain.js'
|
15
15
|
|
16
16
|
const ERC20_INTERFACE = ERC20__factory.createInterface()
|
17
17
|
const ERC721_INTERFACE = ERC721__factory.createInterface()
|
@@ -29,12 +29,12 @@ export class AccountProcessor {
|
|
29
29
|
protected constructor(config: PartiallyOptional<AccountBindOptions, 'network'>) {
|
30
30
|
this.config = {
|
31
31
|
...config,
|
32
|
-
network:
|
32
|
+
network: config.network || EthChainId.ETHEREUM,
|
33
33
|
}
|
34
34
|
}
|
35
35
|
|
36
|
-
public getChainId():
|
37
|
-
return
|
36
|
+
public getChainId(): EthChainId {
|
37
|
+
return this.config.network
|
38
38
|
}
|
39
39
|
|
40
40
|
/**
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BoundContractView, ContractContext, ContractView } from './context.js'
|
1
|
+
import { BoundContractView, ContractContext, ContractView, EthContext } from './context.js'
|
2
2
|
import { BaseContract } from 'ethers'
|
3
3
|
import { BaseProcessor } from './base-processor.js'
|
4
4
|
import { BindOptions, getOptionsSignature } from './bind-options.js'
|
@@ -8,8 +8,6 @@ import { ListStateStorage } from '@sentio/runtime'
|
|
8
8
|
import { BlockParams } from 'ethers/providers'
|
9
9
|
import { DeferredTopicFilter } from 'ethers/contract'
|
10
10
|
import { TypedEvent, TypedCallTrace } from './eth.js'
|
11
|
-
import { getNetworkFromCtxOrNetworkish } from './provider.js'
|
12
|
-
import { BaseContext } from '../core/index.js'
|
13
11
|
|
14
12
|
export class ProcessorTemplateProcessorState extends ListStateStorage<
|
15
13
|
BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>
|
@@ -54,7 +52,7 @@ export abstract class BaseProcessorTemplate<
|
|
54
52
|
* @param options
|
55
53
|
* @param ctx
|
56
54
|
*/
|
57
|
-
public bind(options: BindOptions, ctx:
|
55
|
+
public bind(options: BindOptions, ctx: EthContext): void {
|
58
56
|
if (!options.network) {
|
59
57
|
options.network = ctx.getChainId()
|
60
58
|
}
|
@@ -85,7 +83,7 @@ export abstract class BaseProcessorTemplate<
|
|
85
83
|
contract: {
|
86
84
|
address: options.address,
|
87
85
|
name: options.name || '',
|
88
|
-
chainId:
|
86
|
+
chainId: options.network,
|
89
87
|
abi: '',
|
90
88
|
},
|
91
89
|
startBlock: 0n,
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { BaseContract, DeferredTopicFilter, TransactionResponseParams } from 'ethers'
|
2
|
-
import { Network } from 'ethers/providers'
|
3
2
|
|
4
3
|
import { BoundContractView, ContractContext, ContractView, GlobalContext } from './context.js'
|
5
4
|
import {
|
@@ -15,10 +14,10 @@ import {
|
|
15
14
|
import { BindOptions } from './bind-options.js'
|
16
15
|
import { PromiseOrVoid } from '../core/promises.js'
|
17
16
|
import { ServerError, Status } from 'nice-grpc'
|
18
|
-
import { fixEmptyKey,
|
19
|
-
import { getNetworkFromCtxOrNetworkish } from './provider.js'
|
17
|
+
import { fixEmptyKey, formatEthData, RichBlock, TypedCallTrace, TypedEvent } from './eth.js'
|
20
18
|
import sha3 from 'js-sha3'
|
21
19
|
import { ListStateStorage } from '@sentio/runtime'
|
20
|
+
import { EthChainId } from '../core/chain.js'
|
22
21
|
|
23
22
|
export interface AddressOrTypeEventFilter extends DeferredTopicFilter {
|
24
23
|
addressType?: AddressType
|
@@ -51,7 +50,7 @@ export class TransactionHandler {
|
|
51
50
|
|
52
51
|
class BindInternalOptions {
|
53
52
|
address: string
|
54
|
-
network:
|
53
|
+
network: EthChainId
|
55
54
|
name: string
|
56
55
|
startBlock: bigint
|
57
56
|
endBlock?: bigint
|
@@ -77,7 +76,7 @@ export class GlobalProcessor {
|
|
77
76
|
this.config = {
|
78
77
|
address: '*',
|
79
78
|
name: config.name || 'Global',
|
80
|
-
network:
|
79
|
+
network: config.network || EthChainId.ETHEREUM,
|
81
80
|
startBlock: 0n,
|
82
81
|
}
|
83
82
|
if (config.startBlock) {
|
@@ -119,8 +118,8 @@ export class GlobalProcessor {
|
|
119
118
|
)
|
120
119
|
}
|
121
120
|
|
122
|
-
public getChainId():
|
123
|
-
return
|
121
|
+
public getChainId(): EthChainId {
|
122
|
+
return this.config.network
|
124
123
|
}
|
125
124
|
|
126
125
|
public onInterval(
|
@@ -186,7 +185,7 @@ export abstract class BaseProcessor<
|
|
186
185
|
this.config = {
|
187
186
|
address: config.address,
|
188
187
|
name: config.name || '',
|
189
|
-
network:
|
188
|
+
network: config.network || EthChainId.ETHEREUM,
|
190
189
|
startBlock: 0n,
|
191
190
|
baseLabels: config.baseLabels,
|
192
191
|
}
|
@@ -200,8 +199,8 @@ export abstract class BaseProcessor<
|
|
200
199
|
|
201
200
|
protected abstract CreateBoundContractView(): TBoundContractView
|
202
201
|
|
203
|
-
public getChainId():
|
204
|
-
return
|
202
|
+
public getChainId(): EthChainId {
|
203
|
+
return this.config.network
|
205
204
|
}
|
206
205
|
|
207
206
|
public onEvent(
|