@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/src/eth/bind-options.ts
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import { getNetworkFromCtxOrNetworkish } from './provider.js'
|
1
|
+
import { EthChainId } from '../core/chain.js'
|
3
2
|
|
4
3
|
export class BindOptions {
|
5
4
|
// Contract address
|
6
5
|
address: string
|
7
6
|
// Optional, if not set, then use eth mainnet
|
8
|
-
network?:
|
7
|
+
network?: EthChainId = EthChainId.ETHEREUM
|
9
8
|
// Optional, override default contract name
|
10
9
|
name?: string
|
11
10
|
startBlock?: bigint | number
|
@@ -16,8 +15,7 @@ export class BindOptions {
|
|
16
15
|
export function getOptionsSignature(opts: BindOptions): string {
|
17
16
|
const sig = [opts.address]
|
18
17
|
if (opts.network) {
|
19
|
-
|
20
|
-
sig.push(n.chainId.toString())
|
18
|
+
sig.push(opts.network)
|
21
19
|
}
|
22
20
|
if (opts.name) {
|
23
21
|
sig.push(opts.name)
|
@@ -33,7 +31,7 @@ export function getOptionsSignature(opts: BindOptions): string {
|
|
33
31
|
|
34
32
|
export class AccountBindOptions {
|
35
33
|
address: string
|
36
|
-
network:
|
34
|
+
network: EthChainId
|
37
35
|
startBlock?: bigint | number
|
38
36
|
baseLabels?: { [key: string]: string }
|
39
37
|
}
|
package/src/eth/binds.ts
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
import { BindOptions, getOptionsSignature } from './bind-options.js'
|
2
2
|
import { ContractView } from './context.js'
|
3
3
|
import { BaseProcessor } from './base-processor.js'
|
4
|
-
import { Networkish } from 'ethers/providers'
|
5
4
|
|
6
5
|
import { BaseContract } from 'ethers'
|
7
6
|
import { MapStateStorage } from '@sentio/runtime'
|
8
|
-
import {
|
7
|
+
import { EthChainId } from '../core/chain.js'
|
9
8
|
|
10
9
|
export class ProcessorState extends MapStateStorage<BaseProcessor<any, any>> {
|
11
10
|
static INSTANCE = new ProcessorState()
|
@@ -14,9 +13,8 @@ export class ProcessorState extends MapStateStorage<BaseProcessor<any, any>> {
|
|
14
13
|
// from abiName_address_chainId => contract wrapper
|
15
14
|
const contracts = new Map<string, ContractView<BaseContract>>()
|
16
15
|
|
17
|
-
function getKey(abiName: string, address: string, network:
|
18
|
-
|
19
|
-
return [abiName, address.toLowerCase(), chainId].join('_')
|
16
|
+
function getKey(abiName: string, address: string, network: EthChainId) {
|
17
|
+
return [abiName, address.toLowerCase(), network].join('_')
|
20
18
|
}
|
21
19
|
|
22
20
|
// Dedup processor that bind multiple times
|
@@ -31,7 +29,7 @@ export function addProcessor(opts: BindOptions, processor: BaseProcessor<any, an
|
|
31
29
|
ProcessorState.INSTANCE.getOrSetValue(sig, processor)
|
32
30
|
}
|
33
31
|
|
34
|
-
export function getContractByABI(abiName: string, address: string, network:
|
32
|
+
export function getContractByABI(abiName: string, address: string, network: EthChainId) {
|
35
33
|
const key = getKey(abiName, address, network)
|
36
34
|
return contracts.get(key)
|
37
35
|
}
|
@@ -39,7 +37,7 @@ export function getContractByABI(abiName: string, address: string, network: Netw
|
|
39
37
|
export function addContractByABI(
|
40
38
|
abiName: string,
|
41
39
|
address: string,
|
42
|
-
network:
|
40
|
+
network: EthChainId,
|
43
41
|
contract: ContractView<BaseContract>
|
44
42
|
) {
|
45
43
|
const key = getKey(abiName, address, network)
|
@@ -2,7 +2,6 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { BigNumberish, Overrides } from "ethers";
|
5
|
-
import { Networkish } from "ethers/providers";
|
6
5
|
import {
|
7
6
|
addContractByABI,
|
8
7
|
getContractByABI,
|
@@ -17,11 +16,12 @@ import {
|
|
17
16
|
ContractContext,
|
18
17
|
ContractView,
|
19
18
|
DummyProvider,
|
19
|
+
EthChainId,
|
20
20
|
TypedCallTrace,
|
21
|
-
|
21
|
+
getEthChainId,
|
22
|
+
EthContext,
|
22
23
|
EthFetchConfig,
|
23
24
|
} from "@sentio/sdk/eth";
|
24
|
-
import { BaseContext } from "@sentio/sdk";
|
25
25
|
|
26
26
|
import { EACAggregatorProxy, EACAggregatorProxy__factory } from "./index.js";
|
27
27
|
import {
|
@@ -1067,10 +1067,10 @@ export class EACAggregatorProxyProcessorTemplate extends BaseProcessorTemplate<
|
|
1067
1067
|
}
|
1068
1068
|
|
1069
1069
|
export function getEACAggregatorProxyContract(
|
1070
|
-
contextOrNetwork:
|
1070
|
+
contextOrNetwork: EthContext | EthChainId,
|
1071
1071
|
address: string
|
1072
1072
|
): EACAggregatorProxyContractView {
|
1073
|
-
const network =
|
1073
|
+
const network = getEthChainId(contextOrNetwork);
|
1074
1074
|
let contract = getContractByABI(
|
1075
1075
|
"EACAggregatorProxy",
|
1076
1076
|
address,
|
@@ -2,6 +2,7 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { LogParams } from "ethers/providers";
|
5
|
+
import { EthChainId } from "@sentio/sdk/eth";
|
5
6
|
import {
|
6
7
|
AnswerUpdatedEventObject,
|
7
8
|
NewRoundEventObject,
|
@@ -24,7 +25,10 @@ export function mockAnswerUpdatedLog(
|
|
24
25
|
contractAddress: string,
|
25
26
|
event: AnswerUpdatedEventObject
|
26
27
|
): LogParams {
|
27
|
-
const contract = getEACAggregatorProxyContract(
|
28
|
+
const contract = getEACAggregatorProxyContract(
|
29
|
+
EthChainId.ETHEREUM,
|
30
|
+
contractAddress
|
31
|
+
);
|
28
32
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
29
33
|
"AnswerUpdated(int256,uint256,uint256)",
|
30
34
|
[event.current, event.roundId, event.updatedAt]
|
@@ -42,7 +46,10 @@ export function mockNewRoundLog(
|
|
42
46
|
contractAddress: string,
|
43
47
|
event: NewRoundEventObject
|
44
48
|
): LogParams {
|
45
|
-
const contract = getEACAggregatorProxyContract(
|
49
|
+
const contract = getEACAggregatorProxyContract(
|
50
|
+
EthChainId.ETHEREUM,
|
51
|
+
contractAddress
|
52
|
+
);
|
46
53
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
47
54
|
"NewRound(uint256,address,uint256)",
|
48
55
|
[event.roundId, event.startedBy, event.startedAt]
|
@@ -60,7 +67,10 @@ export function mockOwnershipTransferRequestedLog(
|
|
60
67
|
contractAddress: string,
|
61
68
|
event: OwnershipTransferRequestedEventObject
|
62
69
|
): LogParams {
|
63
|
-
const contract = getEACAggregatorProxyContract(
|
70
|
+
const contract = getEACAggregatorProxyContract(
|
71
|
+
EthChainId.ETHEREUM,
|
72
|
+
contractAddress
|
73
|
+
);
|
64
74
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
65
75
|
"OwnershipTransferRequested(address,address)",
|
66
76
|
[event.from, event.to]
|
@@ -78,7 +88,10 @@ export function mockOwnershipTransferredLog(
|
|
78
88
|
contractAddress: string,
|
79
89
|
event: OwnershipTransferredEventObject
|
80
90
|
): LogParams {
|
81
|
-
const contract = getEACAggregatorProxyContract(
|
91
|
+
const contract = getEACAggregatorProxyContract(
|
92
|
+
EthChainId.ETHEREUM,
|
93
|
+
contractAddress
|
94
|
+
);
|
82
95
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
83
96
|
"OwnershipTransferred(address,address)",
|
84
97
|
[event.from, event.to]
|
@@ -2,7 +2,6 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { BigNumberish, Overrides, BytesLike } from "ethers";
|
5
|
-
import { Networkish } from "ethers/providers";
|
6
5
|
import {
|
7
6
|
addContractByABI,
|
8
7
|
getContractByABI,
|
@@ -17,11 +16,12 @@ import {
|
|
17
16
|
ContractContext,
|
18
17
|
ContractView,
|
19
18
|
DummyProvider,
|
19
|
+
EthChainId,
|
20
20
|
TypedCallTrace,
|
21
|
-
|
21
|
+
getEthChainId,
|
22
|
+
EthContext,
|
22
23
|
EthFetchConfig,
|
23
24
|
} from "@sentio/sdk/eth";
|
24
|
-
import { BaseContext } from "@sentio/sdk";
|
25
25
|
|
26
26
|
import { ERC1155, ERC1155__factory } from "./index.js";
|
27
27
|
import {
|
@@ -502,10 +502,10 @@ export class ERC1155ProcessorTemplate extends BaseProcessorTemplate<
|
|
502
502
|
}
|
503
503
|
|
504
504
|
export function getERC1155Contract(
|
505
|
-
contextOrNetwork:
|
505
|
+
contextOrNetwork: EthContext | EthChainId,
|
506
506
|
address: string
|
507
507
|
): ERC1155ContractView {
|
508
|
-
const network =
|
508
|
+
const network = getEthChainId(contextOrNetwork);
|
509
509
|
let contract = getContractByABI(
|
510
510
|
"ERC1155",
|
511
511
|
address,
|
@@ -2,6 +2,7 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { LogParams } from "ethers/providers";
|
5
|
+
import { EthChainId } from "@sentio/sdk/eth";
|
5
6
|
import {
|
6
7
|
ApprovalForAllEventObject,
|
7
8
|
TransferBatchEventObject,
|
@@ -24,7 +25,7 @@ export function mockApprovalForAllLog(
|
|
24
25
|
contractAddress: string,
|
25
26
|
event: ApprovalForAllEventObject
|
26
27
|
): LogParams {
|
27
|
-
const contract = getERC1155Contract(
|
28
|
+
const contract = getERC1155Contract(EthChainId.ETHEREUM, contractAddress);
|
28
29
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
29
30
|
"ApprovalForAll(address,address,bool)",
|
30
31
|
[event.account, event.operator, event.approved]
|
@@ -42,7 +43,7 @@ export function mockTransferBatchLog(
|
|
42
43
|
contractAddress: string,
|
43
44
|
event: TransferBatchEventObject
|
44
45
|
): LogParams {
|
45
|
-
const contract = getERC1155Contract(
|
46
|
+
const contract = getERC1155Contract(EthChainId.ETHEREUM, contractAddress);
|
46
47
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
47
48
|
"TransferBatch(address,address,address,uint256[],uint256[])",
|
48
49
|
[event.operator, event.from, event.to, event.ids, event.values]
|
@@ -60,7 +61,7 @@ export function mockTransferSingleLog(
|
|
60
61
|
contractAddress: string,
|
61
62
|
event: TransferSingleEventObject
|
62
63
|
): LogParams {
|
63
|
-
const contract = getERC1155Contract(
|
64
|
+
const contract = getERC1155Contract(EthChainId.ETHEREUM, contractAddress);
|
64
65
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
65
66
|
"TransferSingle(address,address,address,uint256,uint256)",
|
66
67
|
[event.operator, event.from, event.to, event.id, event.value]
|
@@ -78,7 +79,7 @@ export function mockURILog(
|
|
78
79
|
contractAddress: string,
|
79
80
|
event: URIEventObject
|
80
81
|
): LogParams {
|
81
|
-
const contract = getERC1155Contract(
|
82
|
+
const contract = getERC1155Contract(EthChainId.ETHEREUM, contractAddress);
|
82
83
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
83
84
|
"URI(string,uint256)",
|
84
85
|
[event.value, event.id]
|
@@ -2,7 +2,6 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { Overrides } from "ethers";
|
5
|
-
import { Networkish } from "ethers/providers";
|
6
5
|
import {
|
7
6
|
addContractByABI,
|
8
7
|
getContractByABI,
|
@@ -17,11 +16,12 @@ import {
|
|
17
16
|
ContractContext,
|
18
17
|
ContractView,
|
19
18
|
DummyProvider,
|
19
|
+
EthChainId,
|
20
20
|
TypedCallTrace,
|
21
|
-
|
21
|
+
getEthChainId,
|
22
|
+
EthContext,
|
22
23
|
EthFetchConfig,
|
23
24
|
} from "@sentio/sdk/eth";
|
24
|
-
import { BaseContext } from "@sentio/sdk";
|
25
25
|
|
26
26
|
import { ERC20, ERC20__factory } from "./index.js";
|
27
27
|
import {
|
@@ -610,10 +610,10 @@ export class ERC20ProcessorTemplate extends BaseProcessorTemplate<
|
|
610
610
|
}
|
611
611
|
|
612
612
|
export function getERC20Contract(
|
613
|
-
contextOrNetwork:
|
613
|
+
contextOrNetwork: EthContext | EthChainId,
|
614
614
|
address: string
|
615
615
|
): ERC20ContractView {
|
616
|
-
const network =
|
616
|
+
const network = getEthChainId(contextOrNetwork);
|
617
617
|
let contract = getContractByABI(
|
618
618
|
"ERC20",
|
619
619
|
address,
|
@@ -2,6 +2,7 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { LogParams } from "ethers/providers";
|
5
|
+
import { EthChainId } from "@sentio/sdk/eth";
|
5
6
|
import {
|
6
7
|
ApprovalEventObject,
|
7
8
|
OwnershipTransferredEventObject,
|
@@ -23,7 +24,7 @@ export function mockApprovalLog(
|
|
23
24
|
contractAddress: string,
|
24
25
|
event: ApprovalEventObject
|
25
26
|
): LogParams {
|
26
|
-
const contract = getERC20Contract(
|
27
|
+
const contract = getERC20Contract(EthChainId.ETHEREUM, contractAddress);
|
27
28
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
28
29
|
"Approval(address,address,uint256)",
|
29
30
|
[event.owner, event.spender, event.value]
|
@@ -41,7 +42,7 @@ export function mockOwnershipTransferredLog(
|
|
41
42
|
contractAddress: string,
|
42
43
|
event: OwnershipTransferredEventObject
|
43
44
|
): LogParams {
|
44
|
-
const contract = getERC20Contract(
|
45
|
+
const contract = getERC20Contract(EthChainId.ETHEREUM, contractAddress);
|
45
46
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
46
47
|
"OwnershipTransferred(address,address)",
|
47
48
|
[event.previousOwner, event.newOwner]
|
@@ -59,7 +60,7 @@ export function mockTransferLog(
|
|
59
60
|
contractAddress: string,
|
60
61
|
event: TransferEventObject
|
61
62
|
): LogParams {
|
62
|
-
const contract = getERC20Contract(
|
63
|
+
const contract = getERC20Contract(EthChainId.ETHEREUM, contractAddress);
|
63
64
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
64
65
|
"Transfer(address,address,uint256)",
|
65
66
|
[event.from, event.to, event.value]
|
@@ -2,7 +2,6 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { Overrides } from "ethers";
|
5
|
-
import { Networkish } from "ethers/providers";
|
6
5
|
import {
|
7
6
|
addContractByABI,
|
8
7
|
getContractByABI,
|
@@ -17,11 +16,12 @@ import {
|
|
17
16
|
ContractContext,
|
18
17
|
ContractView,
|
19
18
|
DummyProvider,
|
19
|
+
EthChainId,
|
20
20
|
TypedCallTrace,
|
21
|
-
|
21
|
+
getEthChainId,
|
22
|
+
EthContext,
|
22
23
|
EthFetchConfig,
|
23
24
|
} from "@sentio/sdk/eth";
|
24
|
-
import { BaseContext } from "@sentio/sdk";
|
25
25
|
|
26
26
|
import { ERC20Bytes, ERC20Bytes__factory } from "./index.js";
|
27
27
|
import {
|
@@ -412,10 +412,10 @@ export class ERC20BytesProcessorTemplate extends BaseProcessorTemplate<
|
|
412
412
|
}
|
413
413
|
|
414
414
|
export function getERC20BytesContract(
|
415
|
-
contextOrNetwork:
|
415
|
+
contextOrNetwork: EthContext | EthChainId,
|
416
416
|
address: string
|
417
417
|
): ERC20BytesContractView {
|
418
|
-
const network =
|
418
|
+
const network = getEthChainId(contextOrNetwork);
|
419
419
|
let contract = getContractByABI(
|
420
420
|
"ERC20Bytes",
|
421
421
|
address,
|
@@ -2,6 +2,7 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { LogParams } from "ethers/providers";
|
5
|
+
import { EthChainId } from "@sentio/sdk/eth";
|
5
6
|
import { ApprovalEventObject, TransferEventObject } from "./ERC20Bytes.js";
|
6
7
|
import { getERC20BytesContract } from "./erc20bytes-processor.js";
|
7
8
|
const mockField = {
|
@@ -19,7 +20,7 @@ export function mockApprovalLog(
|
|
19
20
|
contractAddress: string,
|
20
21
|
event: ApprovalEventObject
|
21
22
|
): LogParams {
|
22
|
-
const contract = getERC20BytesContract(
|
23
|
+
const contract = getERC20BytesContract(EthChainId.ETHEREUM, contractAddress);
|
23
24
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
24
25
|
"Approval(address,address,uint256)",
|
25
26
|
[event.owner, event.spender, event.value]
|
@@ -37,7 +38,7 @@ export function mockTransferLog(
|
|
37
38
|
contractAddress: string,
|
38
39
|
event: TransferEventObject
|
39
40
|
): LogParams {
|
40
|
-
const contract = getERC20BytesContract(
|
41
|
+
const contract = getERC20BytesContract(EthChainId.ETHEREUM, contractAddress);
|
41
42
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
42
43
|
"Transfer(address,address,uint256)",
|
43
44
|
[event.from, event.to, event.value]
|
@@ -2,7 +2,6 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { BigNumberish, Overrides, BytesLike } from "ethers";
|
5
|
-
import { Networkish } from "ethers/providers";
|
6
5
|
import {
|
7
6
|
addContractByABI,
|
8
7
|
getContractByABI,
|
@@ -17,11 +16,12 @@ import {
|
|
17
16
|
ContractContext,
|
18
17
|
ContractView,
|
19
18
|
DummyProvider,
|
19
|
+
EthChainId,
|
20
20
|
TypedCallTrace,
|
21
|
-
|
21
|
+
getEthChainId,
|
22
|
+
EthContext,
|
22
23
|
EthFetchConfig,
|
23
24
|
} from "@sentio/sdk/eth";
|
24
|
-
import { BaseContext } from "@sentio/sdk";
|
25
25
|
|
26
26
|
import { ERC721, ERC721__factory } from "./index.js";
|
27
27
|
import {
|
@@ -627,10 +627,10 @@ export class ERC721ProcessorTemplate extends BaseProcessorTemplate<
|
|
627
627
|
}
|
628
628
|
|
629
629
|
export function getERC721Contract(
|
630
|
-
contextOrNetwork:
|
630
|
+
contextOrNetwork: EthContext | EthChainId,
|
631
631
|
address: string
|
632
632
|
): ERC721ContractView {
|
633
|
-
const network =
|
633
|
+
const network = getEthChainId(contextOrNetwork);
|
634
634
|
let contract = getContractByABI(
|
635
635
|
"ERC721",
|
636
636
|
address,
|
@@ -2,6 +2,7 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { LogParams } from "ethers/providers";
|
5
|
+
import { EthChainId } from "@sentio/sdk/eth";
|
5
6
|
import {
|
6
7
|
ApprovalEventObject,
|
7
8
|
ApprovalForAllEventObject,
|
@@ -23,7 +24,7 @@ export function mockApprovalLog(
|
|
23
24
|
contractAddress: string,
|
24
25
|
event: ApprovalEventObject
|
25
26
|
): LogParams {
|
26
|
-
const contract = getERC721Contract(
|
27
|
+
const contract = getERC721Contract(EthChainId.ETHEREUM, contractAddress);
|
27
28
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
28
29
|
"Approval(address,address,uint256)",
|
29
30
|
[event.owner, event.approved, event.tokenId]
|
@@ -41,7 +42,7 @@ export function mockApprovalForAllLog(
|
|
41
42
|
contractAddress: string,
|
42
43
|
event: ApprovalForAllEventObject
|
43
44
|
): LogParams {
|
44
|
-
const contract = getERC721Contract(
|
45
|
+
const contract = getERC721Contract(EthChainId.ETHEREUM, contractAddress);
|
45
46
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
46
47
|
"ApprovalForAll(address,address,bool)",
|
47
48
|
[event.owner, event.operator, event.approved]
|
@@ -59,7 +60,7 @@ export function mockTransferLog(
|
|
59
60
|
contractAddress: string,
|
60
61
|
event: TransferEventObject
|
61
62
|
): LogParams {
|
62
|
-
const contract = getERC721Contract(
|
63
|
+
const contract = getERC721Contract(EthChainId.ETHEREUM, contractAddress);
|
63
64
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
64
65
|
"Transfer(address,address,uint256)",
|
65
66
|
[event.from, event.to, event.tokenId]
|
@@ -2,7 +2,6 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { Overrides } from "ethers";
|
5
|
-
import { Networkish } from "ethers/providers";
|
6
5
|
import {
|
7
6
|
addContractByABI,
|
8
7
|
getContractByABI,
|
@@ -17,11 +16,12 @@ import {
|
|
17
16
|
ContractContext,
|
18
17
|
ContractView,
|
19
18
|
DummyProvider,
|
19
|
+
EthChainId,
|
20
20
|
TypedCallTrace,
|
21
|
-
|
21
|
+
getEthChainId,
|
22
|
+
EthContext,
|
22
23
|
EthFetchConfig,
|
23
24
|
} from "@sentio/sdk/eth";
|
24
|
-
import { BaseContext } from "@sentio/sdk";
|
25
25
|
|
26
26
|
import { WETH9, WETH9__factory } from "./index.js";
|
27
27
|
import {
|
@@ -485,10 +485,10 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
|
|
485
485
|
}
|
486
486
|
|
487
487
|
export function getWETH9Contract(
|
488
|
-
contextOrNetwork:
|
488
|
+
contextOrNetwork: EthContext | EthChainId,
|
489
489
|
address: string
|
490
490
|
): WETH9ContractView {
|
491
|
-
const network =
|
491
|
+
const network = getEthChainId(contextOrNetwork);
|
492
492
|
let contract = getContractByABI(
|
493
493
|
"WETH9",
|
494
494
|
address,
|
@@ -2,6 +2,7 @@
|
|
2
2
|
/* tslint:disable */
|
3
3
|
/* eslint-disable */
|
4
4
|
import { LogParams } from "ethers/providers";
|
5
|
+
import { EthChainId } from "@sentio/sdk/eth";
|
5
6
|
import {
|
6
7
|
ApprovalEventObject,
|
7
8
|
TransferEventObject,
|
@@ -24,7 +25,7 @@ export function mockApprovalLog(
|
|
24
25
|
contractAddress: string,
|
25
26
|
event: ApprovalEventObject
|
26
27
|
): LogParams {
|
27
|
-
const contract = getWETH9Contract(
|
28
|
+
const contract = getWETH9Contract(EthChainId.ETHEREUM, contractAddress);
|
28
29
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
29
30
|
"Approval(address,address,uint256)",
|
30
31
|
[event.src, event.guy, event.wad]
|
@@ -42,7 +43,7 @@ export function mockTransferLog(
|
|
42
43
|
contractAddress: string,
|
43
44
|
event: TransferEventObject
|
44
45
|
): LogParams {
|
45
|
-
const contract = getWETH9Contract(
|
46
|
+
const contract = getWETH9Contract(EthChainId.ETHEREUM, contractAddress);
|
46
47
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
47
48
|
"Transfer(address,address,uint256)",
|
48
49
|
[event.src, event.dst, event.wad]
|
@@ -60,7 +61,7 @@ export function mockDepositLog(
|
|
60
61
|
contractAddress: string,
|
61
62
|
event: DepositEventObject
|
62
63
|
): LogParams {
|
63
|
-
const contract = getWETH9Contract(
|
64
|
+
const contract = getWETH9Contract(EthChainId.ETHEREUM, contractAddress);
|
64
65
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
65
66
|
"Deposit(address,uint256)",
|
66
67
|
[event.dst, event.wad]
|
@@ -78,7 +79,7 @@ export function mockWithdrawalLog(
|
|
78
79
|
contractAddress: string,
|
79
80
|
event: WithdrawalEventObject
|
80
81
|
): LogParams {
|
81
|
-
const contract = getWETH9Contract(
|
82
|
+
const contract = getWETH9Contract(EthChainId.ETHEREUM, contractAddress);
|
82
83
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
83
84
|
"Withdrawal(address,uint256)",
|
84
85
|
[event.src, event.wad]
|
@@ -11,6 +11,7 @@ import {
|
|
11
11
|
import { dirname, join, relative } from 'path'
|
12
12
|
import { codeGenIndex, codeGenSentioFile, codeGenTestUtilsFile } from './file.js'
|
13
13
|
import { YamlContractConfig } from '../../core/yaml-contract-config.js'
|
14
|
+
import { ChainId, EthChainId } from '../../core/chain.js'
|
14
15
|
|
15
16
|
export interface SentioEthersConfig extends Config {
|
16
17
|
contractsToGenExample: YamlContractConfig[]
|
@@ -98,17 +99,23 @@ export default class EthersSentio extends Ethers.default {
|
|
98
99
|
const contractsToGenExample = (this.cfg as SentioEthersConfig).contractsToGenExample
|
99
100
|
if (contractsToGenExample.length > 0) {
|
100
101
|
const processors = this.processedABIs.map((abi) => `${abi.name}Processor`).join(',')
|
101
|
-
let exampleContent = `
|
102
|
+
let exampleContent = `
|
103
|
+
import { EthChainId } from '@sentio/sdk/eth'
|
104
|
+
import { ${processors} } from './types/eth/index.js'`
|
105
|
+
|
106
|
+
const ethChainIdValues = new Map<ChainId, string>()
|
107
|
+
for (const [key, value] of Object.entries(EthChainId)) {
|
108
|
+
ethChainIdValues.set(value, key)
|
109
|
+
}
|
102
110
|
|
103
111
|
for (const contract of contractsToGenExample) {
|
104
|
-
const
|
105
|
-
if (
|
112
|
+
const chainKey = ethChainIdValues.get(contract.chain)
|
113
|
+
if (!chainKey) {
|
106
114
|
continue
|
107
115
|
}
|
108
|
-
|
109
116
|
const content = `
|
110
117
|
|
111
|
-
${contract.name}Processor.bind({ address: '${contract.address}', network:
|
118
|
+
${contract.name}Processor.bind({ address: '${contract.address}', network: EthChainId.${chainKey} })
|
112
119
|
.onAllEvents((evt, ctx) => {
|
113
120
|
ctx.meter.Counter('event_count').add(1, { name: evt.name })
|
114
121
|
ctx.eventLogger.emit(evt.name, {
|
package/src/eth/codegen/file.ts
CHANGED
@@ -106,10 +106,10 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
|
|
106
106
|
.join('\n')}
|
107
107
|
}
|
108
108
|
|
109
|
-
export function get${contract.name}Contract(contextOrNetwork:
|
109
|
+
export function get${contract.name}Contract(contextOrNetwork: EthContext | EthChainId, address: string): ${
|
110
110
|
contract.name
|
111
111
|
}ContractView {
|
112
|
-
const network =
|
112
|
+
const network = getEthChainId(contextOrNetwork)
|
113
113
|
let contract = getContractByABI("${contract.name}", address, network) as ${contract.name}ContractView
|
114
114
|
if (!contract) {
|
115
115
|
const rawContract = ${contract.name}__factory.connect(address, getProvider(network))
|
@@ -148,7 +148,7 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
|
|
148
148
|
const imports = createImportsForUsedIdentifiers(
|
149
149
|
{
|
150
150
|
ethers: ['BigNumberish', 'Overrides', 'BytesLike'],
|
151
|
-
'ethers/providers': ['Networkish'],
|
151
|
+
// 'ethers/providers': ['Networkish'],
|
152
152
|
'@sentio/sdk/eth': [
|
153
153
|
'addContractByABI',
|
154
154
|
'getContractByABI',
|
@@ -164,12 +164,14 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
|
|
164
164
|
'ContractContext',
|
165
165
|
'ContractView',
|
166
166
|
'DummyProvider',
|
167
|
+
'EthChainId',
|
167
168
|
'TypedCallTrace',
|
168
|
-
'
|
169
|
+
'getEthChainId',
|
169
170
|
// 'toBlockTag',
|
171
|
+
'EthContext',
|
170
172
|
'EthFetchConfig',
|
171
173
|
],
|
172
|
-
'@sentio/sdk': ['BaseContext'],
|
174
|
+
// '@sentio/sdk/eth': ['BaseContext'],
|
173
175
|
// '@sentio/protos': ['EthFetchConfig'],
|
174
176
|
'./common.js': ['PromiseOrValue'],
|
175
177
|
'./index.js': [`${contract.name}`, `${contract.name}__factory`],
|
@@ -206,6 +208,7 @@ export function codeGenTestUtilsFile(contract: Contract): string {
|
|
206
208
|
|
207
209
|
const possibleImports = {
|
208
210
|
'ethers/providers': ['LogParams'],
|
211
|
+
'@sentio/sdk/eth': ['EthChainId'],
|
209
212
|
} as any
|
210
213
|
possibleImports[`./${contract.name}.js`] = Object.values(contract.events).flatMap((events) => {
|
211
214
|
if (events.length === 1) {
|
@@ -232,7 +235,7 @@ function generateMockEventLogFunction(event: EventDeclaration, contractName: str
|
|
232
235
|
|
233
236
|
return `
|
234
237
|
export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): LogParams {
|
235
|
-
const contract = get${contractName}Contract(
|
238
|
+
const contract = get${contractName}Contract(EthChainId.ETHEREUM, contractAddress)
|
236
239
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
237
240
|
'${getFullSignatureForEvent(event)}',
|
238
241
|
[${eventArgs.join(', ')}]
|