@sentio/sdk 1.7.14 → 1.7.15
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/{base-processor-template.d.ts → lib/base-processor-template.d.ts} +0 -0
- package/{base-processor-template.js → lib/base-processor-template.js} +0 -0
- package/{base-processor-template.js.map → lib/base-processor-template.js.map} +0 -0
- package/{base-processor.d.ts → lib/base-processor.d.ts} +0 -0
- package/{base-processor.js → lib/base-processor.js} +0 -0
- package/{base-processor.js.map → lib/base-processor.js.map} +0 -0
- package/{bind-options.d.ts → lib/bind-options.d.ts} +0 -0
- package/{bind-options.js → lib/bind-options.js} +0 -0
- package/{bind-options.js.map → lib/bind-options.js.map} +0 -0
- package/{binds.d.ts → lib/binds.d.ts} +0 -0
- package/{binds.js → lib/binds.js} +0 -0
- package/{binds.js.map → lib/binds.js.map} +0 -0
- package/{builtin → lib/builtin}/erc20/index.d.ts +0 -0
- package/{builtin → lib/builtin}/erc20/index.js +0 -0
- package/{builtin → lib/builtin}/erc20/index.js.map +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.d.ts +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.js +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.js.map +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.js +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.js.map +0 -0
- package/{builtin → lib/builtin}/internal/common.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/common.js +0 -0
- package/{builtin → lib/builtin}/internal/common.js.map +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.js +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.js.map +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js.map +0 -0
- package/{builtin → lib/builtin}/internal/factories/index.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/factories/index.js +0 -0
- package/{builtin → lib/builtin}/internal/factories/index.js.map +0 -0
- package/{builtin → lib/builtin}/internal/index.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/index.js +0 -0
- package/{builtin → lib/builtin}/internal/index.js.map +0 -0
- package/{chain-config.d.ts → lib/chain-config.d.ts} +0 -0
- package/{chain-config.js → lib/chain-config.js} +0 -0
- package/{chain-config.js.map → lib/chain-config.js.map} +0 -0
- package/{cli → lib/cli}/build.d.ts +0 -0
- package/{cli → lib/cli}/build.js +0 -0
- package/{cli → lib/cli}/build.js.map +0 -0
- package/{cli → lib/cli}/cli.d.ts +0 -0
- package/{cli → lib/cli}/cli.js +0 -0
- package/{cli → lib/cli}/cli.js.map +0 -0
- package/{cli → lib/cli}/config.d.ts +0 -0
- package/{cli → lib/cli}/config.js +0 -0
- package/{cli → lib/cli}/config.js.map +0 -0
- package/{cli → lib/cli}/key.d.ts +0 -0
- package/{cli → lib/cli}/key.js +0 -0
- package/{cli → lib/cli}/key.js.map +0 -0
- package/{cli → lib/cli}/solana-code-gen.d.ts +0 -0
- package/{cli → lib/cli}/solana-code-gen.js +0 -0
- package/{cli → lib/cli}/solana-code-gen.js.map +0 -0
- package/{cli → lib/cli}/upload.d.ts +0 -0
- package/{cli → lib/cli}/upload.js +0 -0
- package/{cli → lib/cli}/upload.js.map +0 -0
- package/{cli → lib/cli}/webpack.config.js +0 -0
- package/{context.d.ts → lib/context.d.ts} +0 -0
- package/{context.js → lib/context.js} +0 -0
- package/{context.js.map → lib/context.js.map} +0 -0
- package/{contract-namer.d.ts → lib/contract-namer.d.ts} +0 -0
- package/{contract-namer.js → lib/contract-namer.js} +0 -0
- package/{contract-namer.js.map → lib/contract-namer.js.map} +0 -0
- package/{error.d.ts → lib/error.d.ts} +0 -0
- package/{error.js → lib/error.js} +0 -0
- package/{error.js.map → lib/error.js.map} +0 -0
- package/{gen → lib/gen}/builtin.d.ts +0 -0
- package/{gen → lib/gen}/builtin.js +0 -0
- package/{gen → lib/gen}/builtin.js.map +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.d.ts +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.js +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.js.map +0 -0
- package/{gen → lib/gen}/processor/protos/processor.d.ts +0 -0
- package/{gen → lib/gen}/processor/protos/processor.js +0 -0
- package/{gen → lib/gen}/processor/protos/processor.js.map +0 -0
- package/{generic-processor.d.ts → lib/generic-processor.d.ts} +0 -0
- package/{generic-processor.js → lib/generic-processor.js} +0 -0
- package/{generic-processor.js.map → lib/generic-processor.js.map} +0 -0
- package/{index.d.ts → lib/index.d.ts} +0 -0
- package/{index.js → lib/index.js} +0 -0
- package/{index.js.map → lib/index.js.map} +0 -0
- package/{meter.d.ts → lib/meter.d.ts} +0 -0
- package/{meter.js → lib/meter.js} +0 -0
- package/{meter.js.map → lib/meter.js.map} +0 -0
- package/{numberish.d.ts → lib/numberish.d.ts} +0 -0
- package/{numberish.js → lib/numberish.js} +0 -0
- package/{numberish.js.map → lib/numberish.js.map} +0 -0
- package/{numberish.test.d.ts → lib/numberish.test.d.ts} +0 -0
- package/{numberish.test.js → lib/numberish.test.js} +0 -0
- package/{numberish.test.js.map → lib/numberish.test.js.map} +0 -0
- package/{processor-runner.d.ts → lib/processor-runner.d.ts} +0 -0
- package/{processor-runner.js → lib/processor-runner.js} +0 -0
- package/{processor-runner.js.map → lib/processor-runner.js.map} +0 -0
- package/{processor-state.d.ts → lib/processor-state.d.ts} +0 -0
- package/{processor-state.js → lib/processor-state.js} +0 -0
- package/{processor-state.js.map → lib/processor-state.js.map} +0 -0
- package/{promise-or-void.d.ts → lib/promise-or-void.d.ts} +0 -0
- package/{promise-or-void.js → lib/promise-or-void.js} +0 -0
- package/{promise-or-void.js.map → lib/promise-or-void.js.map} +0 -0
- package/{provider.d.ts → lib/provider.d.ts} +0 -0
- package/{provider.js → lib/provider.js} +0 -0
- package/{provider.js.map → lib/provider.js.map} +0 -0
- package/{release.config.js → lib/release.config.js} +0 -0
- package/{service.d.ts → lib/service.d.ts} +0 -0
- package/{service.js → lib/service.js} +0 -0
- package/{service.js.map → lib/service.js.map} +0 -0
- package/{solana → lib/solana}/builtin/index.d.ts +0 -0
- package/{solana → lib/solana}/builtin/index.js +0 -0
- package/{solana → lib/solana}/builtin/index.js.map +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.d.ts +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.js +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.js.map +0 -0
- package/{solana → lib/solana}/builtin/types.d.ts +0 -0
- package/{solana → lib/solana}/builtin/types.js +0 -0
- package/{solana → lib/solana}/builtin/types.js.map +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.d.ts +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.js +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.js.map +0 -0
- package/{solana-processor.d.ts → lib/solana-processor.d.ts} +0 -0
- package/{solana-processor.js → lib/solana-processor.js} +0 -0
- package/{solana-processor.js.map → lib/solana-processor.js.map} +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.d.ts +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js +0 -0
- package/lib/target-ethers-sentio/codegen.js.map +1 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/index.d.ts +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js +0 -0
- package/lib/target-ethers-sentio/index.js.map +1 -0
- package/{test → lib/test}/codegen.test.d.ts +0 -0
- package/{test → lib/test}/codegen.test.js +1 -1
- package/{test → lib/test}/codegen.test.js.map +1 -1
- package/{test → lib/test}/erc20-template.d.ts +0 -0
- package/{test → lib/test}/erc20-template.js +0 -0
- package/{test → lib/test}/erc20-template.js.map +0 -0
- package/{test → lib/test}/erc20-template.test.d.ts +0 -0
- package/{test → lib/test}/erc20-template.test.js +0 -0
- package/{test → lib/test}/erc20-template.test.js.map +0 -0
- package/{test → lib/test}/erc20.d.ts +0 -0
- package/{test → lib/test}/erc20.js +0 -0
- package/{test → lib/test}/erc20.js.map +0 -0
- package/{test → lib/test}/erc20.test.d.ts +0 -0
- package/{test → lib/test}/erc20.test.js +0 -0
- package/{test → lib/test}/erc20.test.js.map +0 -0
- package/{test → lib/test}/generic-processor.test.d.ts +0 -0
- package/{test → lib/test}/generic-processor.test.js +0 -0
- package/{test → lib/test}/generic-processor.test.js.map +0 -0
- package/{test → lib/test}/index.d.ts +0 -0
- package/{test → lib/test}/index.js +0 -0
- package/{test → lib/test}/index.js.map +0 -0
- package/{test → lib/test}/metric-utils.d.ts +0 -0
- package/{test → lib/test}/metric-utils.js +0 -0
- package/{test → lib/test}/metric-utils.js.map +0 -0
- package/{test → lib/test}/mirrorworld.d.ts +0 -0
- package/{test → lib/test}/mirrorworld.js +0 -0
- package/{test → lib/test}/mirrorworld.js.map +0 -0
- package/{test → lib/test}/solana.test.d.ts +0 -0
- package/{test → lib/test}/solana.test.js +0 -0
- package/{test → lib/test}/solana.test.js.map +0 -0
- package/{test → lib/test}/test-processor-server.d.ts +0 -0
- package/{test → lib/test}/test-processor-server.js +0 -0
- package/{test → lib/test}/test-processor-server.js.map +0 -0
- package/{test → lib/test}/types/game_wallet.d.ts +0 -0
- package/{test → lib/test}/types/game_wallet.js +0 -0
- package/{test → lib/test}/types/game_wallet.js.map +0 -0
- package/{test → lib/test}/types/game_wallet_processor.d.ts +0 -0
- package/{test → lib/test}/types/game_wallet_processor.js +0 -0
- package/{test → lib/test}/types/game_wallet_processor.js.map +0 -0
- package/{test → lib/test}/wormhole-token-bridge.d.ts +0 -0
- package/{test → lib/test}/wormhole-token-bridge.js +0 -0
- package/{test → lib/test}/wormhole-token-bridge.js.map +0 -0
- package/{utils → lib/utils}/chainmap.d.ts +0 -0
- package/{utils → lib/utils}/chainmap.js +0 -0
- package/{utils → lib/utils}/chainmap.js.map +0 -0
- package/{utils → lib/utils}/convert.d.ts +0 -0
- package/{utils → lib/utils}/convert.js +0 -0
- package/{utils → lib/utils}/convert.js.map +0 -0
- package/{utils → lib/utils}/index.d.ts +0 -0
- package/{utils → lib/utils}/index.js +0 -0
- package/{utils → lib/utils}/index.js.map +0 -0
- package/package.json +47 -6
- package/src/abis/erc20.json +198 -0
- package/src/base-processor-template.ts +92 -0
- package/src/base-processor.ts +128 -0
- package/src/bind-options.ts +41 -0
- package/src/binds.ts +73 -0
- package/src/builtin/erc20/index.ts +6 -0
- package/src/builtin/erc20/test-utils.ts +49 -0
- package/src/builtin/internal/Erc20.ts +356 -0
- package/src/builtin/internal/common.ts +46 -0
- package/src/builtin/internal/erc20_processor.ts +295 -0
- package/src/builtin/internal/factories/Erc20__factory.ts +216 -0
- package/src/builtin/internal/factories/index.ts +4 -0
- package/src/builtin/internal/index.ts +6 -0
- package/src/chain-config.ts +6 -0
- package/src/cli/build.ts +180 -0
- package/src/cli/cli.ts +217 -0
- package/src/cli/config.ts +43 -0
- package/src/cli/key.ts +43 -0
- package/src/cli/solana-code-gen.ts +16 -0
- package/src/cli/upload.ts +86 -0
- package/src/cli/webpack.config.js +42 -0
- package/src/context.ts +93 -0
- package/src/contract-namer.ts +17 -0
- package/src/error.ts +43 -0
- package/src/gen/builtin.ts +22 -0
- package/src/gen/google/protobuf/empty.ts +70 -0
- package/src/gen/processor/protos/processor.ts +3071 -0
- package/src/generic-processor.ts +38 -0
- package/src/index.ts +19 -0
- package/src/meter.ts +122 -0
- package/src/numberish.test.ts +82 -0
- package/src/numberish.ts +99 -0
- package/src/processor-runner.ts +75 -0
- package/src/processor-state.ts +24 -0
- package/src/promise-or-void.ts +1 -0
- package/src/provider.ts +74 -0
- package/src/service.ts +434 -0
- package/src/solana/builtin/index.ts +2 -0
- package/src/solana/builtin/spl-token-processor.ts +164 -0
- package/src/solana/builtin/types.ts +268 -0
- package/src/solana/builtin/wormhole-processor.ts +178 -0
- package/src/solana-processor.ts +105 -0
- package/src/target-ethers-sentio/codegen.ts +289 -0
- package/src/target-ethers-sentio/index.ts +50 -0
- package/src/target-ethers-sentio/tsconfig.json +9 -0
- package/src/test/abis/evm/anyswapRouter.json +490 -0
- package/src/test/abis/solana/mirrorworld.json +1392 -0
- package/src/test/codegen.test.ts +26 -0
- package/src/test/erc20-template.test.ts +39 -0
- package/src/test/erc20-template.ts +25 -0
- package/src/test/erc20.test.ts +92 -0
- package/src/test/erc20.ts +48 -0
- package/src/test/generic-processor.test.ts +72 -0
- package/src/test/index.ts +1 -0
- package/src/test/metric-utils.ts +49 -0
- package/src/test/mirrorworld.ts +40 -0
- package/src/test/sentio.yaml +4 -0
- package/src/test/solana.test.ts +93 -0
- package/src/test/test-processor-server.ts +210 -0
- package/src/test/types/game_wallet.ts +1392 -0
- package/src/test/types/game_wallet_processor.ts +113 -0
- package/src/test/wormhole-token-bridge.ts +21 -0
- package/src/types/global.d.ts +17 -0
- package/src/utils/chainmap.ts +95 -0
- package/src/utils/convert.ts +6 -0
- package/src/utils/index.ts +2 -0
- package/target-ethers-sentio/codegen.js.map +0 -1
- package/target-ethers-sentio/index.js.map +0 -1
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Contract,
|
|
3
|
+
createImportsForUsedIdentifiers,
|
|
4
|
+
EventDeclaration,
|
|
5
|
+
FunctionDeclaration,
|
|
6
|
+
getFullSignatureAsSymbolForEvent,
|
|
7
|
+
} from 'typechain'
|
|
8
|
+
|
|
9
|
+
import { reservedKeywords } from '@typechain/ethers-v5/dist/codegen/reserved-keywords'
|
|
10
|
+
import { generateInputTypes } from '@typechain/ethers-v5/dist/codegen/types'
|
|
11
|
+
import { getFullSignatureForEvent } from 'typechain/dist/utils/signatures'
|
|
12
|
+
|
|
13
|
+
export function codeGenIndex(contract: Contract): string {
|
|
14
|
+
return `
|
|
15
|
+
export * from '../internal/${contract.name.toLowerCase()}_processor'
|
|
16
|
+
export * from '../internal/${contract.name}'
|
|
17
|
+
`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function codeGenSentioFile(contract: Contract): string {
|
|
21
|
+
const source = `
|
|
22
|
+
const templateContract = ${contract.name}__factory.connect("", DummyProvider)
|
|
23
|
+
|
|
24
|
+
export class ${contract.name}ContractView extends ContractView<${contract.name}> {
|
|
25
|
+
constructor (contract: ${contract.name}) {
|
|
26
|
+
super(contract);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
${Object.values(contract.functions)
|
|
30
|
+
.filter((f) => !reservedKeywords.has(f[0].name))
|
|
31
|
+
.flatMap((v) => v.filter((f) => f.stateMutability == 'view').map(generateViewFunction))
|
|
32
|
+
.join('\n')}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class ${contract.name}BoundContractView extends BoundContractView<${contract.name}, ${
|
|
36
|
+
contract.name
|
|
37
|
+
}ContractView> {
|
|
38
|
+
// constructor (contract: ${contract.name}) {
|
|
39
|
+
// super(contract);
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
${Object.values(contract.functions)
|
|
43
|
+
.filter((f) => !reservedKeywords.has(f[0].name))
|
|
44
|
+
.flatMap((v) => v.filter((f) => f.stateMutability == 'view').map(generateBoundViewFunction))
|
|
45
|
+
.join('\n')}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type ${contract.name}Context = Context<${contract.name}, ${contract.name}BoundContractView>
|
|
49
|
+
|
|
50
|
+
export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${contract.name}, ${
|
|
51
|
+
contract.name
|
|
52
|
+
}BoundContractView> {
|
|
53
|
+
bindInternal(options: BindOptions) {
|
|
54
|
+
let processor = getProcessor("${contract.name}", options) as ${contract.name}Processor
|
|
55
|
+
if (!processor) {
|
|
56
|
+
const finalOptions = Object.assign({}, options)
|
|
57
|
+
finalOptions.name = getContractName("${contract.name}", options.name, options.address, options.network)
|
|
58
|
+
processor = new ${contract.name}Processor(finalOptions)
|
|
59
|
+
addProcessor("${contract.name}", options, processor)
|
|
60
|
+
}
|
|
61
|
+
return processor
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
${Object.values(contract.events)
|
|
65
|
+
.map((events) => {
|
|
66
|
+
if (events.length === 1) {
|
|
67
|
+
return generateOnEventFunction(events[0], contract.name, false)
|
|
68
|
+
} else {
|
|
69
|
+
return events.map((e) => generateOnEventFunction(e, contract.name, true)).join('\n')
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
.join('\n')}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {
|
|
76
|
+
${Object.values(contract.events)
|
|
77
|
+
.map((events) => {
|
|
78
|
+
if (events.length === 1) {
|
|
79
|
+
return generateOnEventFunction(events[0], contract.name, false)
|
|
80
|
+
} else {
|
|
81
|
+
return events.map((e) => generateOnEventFunction(e, contract.name, true)).join('\n')
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
.join('\n')}
|
|
85
|
+
|
|
86
|
+
public static filters = templateContract.filters
|
|
87
|
+
|
|
88
|
+
protected CreateBoundContractView(): ${contract.name}BoundContractView {
|
|
89
|
+
const view = get${contract.name}Contract(this.config.address, this.config.network)
|
|
90
|
+
return new ${contract.name}BoundContractView(view)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public static bind(options: BindOptions): ${contract.name}Processor {
|
|
94
|
+
let processor = getProcessor("${contract.name}", options) as ${contract.name}Processor
|
|
95
|
+
if (!processor) {
|
|
96
|
+
// const wrapper = get${contract.name}Contract(options.address, options.network)
|
|
97
|
+
|
|
98
|
+
const finalOptions = Object.assign({}, options)
|
|
99
|
+
finalOptions.name = getContractName("${contract.name}", options.name, options.address, options.network)
|
|
100
|
+
processor = new ${contract.name}Processor(finalOptions)
|
|
101
|
+
addProcessor("${contract.name}", options, processor)
|
|
102
|
+
}
|
|
103
|
+
return processor
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function get${contract.name}Contract(address: string, network: Networkish = 1): ${contract.name}ContractView {
|
|
108
|
+
let contract = getContractByABI("${contract.name}", address, network) as ${contract.name}ContractView
|
|
109
|
+
if (!contract) {
|
|
110
|
+
const rawContract = ${contract.name}__factory.connect(address, getProvider(network))
|
|
111
|
+
contract = new ${contract.name}ContractView(rawContract)
|
|
112
|
+
addContractByABI("${contract.name}", address, network, contract)
|
|
113
|
+
}
|
|
114
|
+
return contract
|
|
115
|
+
}
|
|
116
|
+
`
|
|
117
|
+
|
|
118
|
+
const imports = createImportsForUsedIdentifiers(
|
|
119
|
+
{
|
|
120
|
+
ethers: ['BigNumber', 'BigNumberish', 'CallOverrides', 'BytesLike'],
|
|
121
|
+
'@ethersproject/providers': ['Networkish'],
|
|
122
|
+
'@sentio/sdk': [
|
|
123
|
+
'addContractByABI',
|
|
124
|
+
'getContractByABI',
|
|
125
|
+
'addProcessor',
|
|
126
|
+
'getProcessor',
|
|
127
|
+
'getProvider',
|
|
128
|
+
'transformEtherError',
|
|
129
|
+
'BindOptions',
|
|
130
|
+
'BaseProcessor',
|
|
131
|
+
'BaseProcessorTemplate',
|
|
132
|
+
'BoundContractView',
|
|
133
|
+
'Context',
|
|
134
|
+
'ContractView',
|
|
135
|
+
'DummyProvider',
|
|
136
|
+
'getContractName',
|
|
137
|
+
],
|
|
138
|
+
'./common': ['PromiseOrValue'],
|
|
139
|
+
'./index': [`${contract.name}`, `${contract.name}__factory`],
|
|
140
|
+
[`./${contract.name}`]: (<string[]>[]).concat(
|
|
141
|
+
...Object.values(contract.events).map((events) => {
|
|
142
|
+
if (events.length === 1) {
|
|
143
|
+
return [`${events[0].name}Event`, `${events[0].name}EventFilter`]
|
|
144
|
+
} else {
|
|
145
|
+
return events.flatMap((e) => [
|
|
146
|
+
`${getFullSignatureAsSymbolForEvent(e)}_Event`,
|
|
147
|
+
`${getFullSignatureAsSymbolForEvent(e)}_EventFilter`,
|
|
148
|
+
])
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
),
|
|
152
|
+
},
|
|
153
|
+
source
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
return imports + source
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function codeGenTestUtilsFile(contract: Contract): string {
|
|
160
|
+
const source = `
|
|
161
|
+
const mockField = {
|
|
162
|
+
blockHash:
|
|
163
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
164
|
+
blockNumber: 0,
|
|
165
|
+
logIndex: 0,
|
|
166
|
+
removed: false,
|
|
167
|
+
transactionHash:
|
|
168
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
169
|
+
transactionIndex: 0,
|
|
170
|
+
}
|
|
171
|
+
${Object.values(contract.events)
|
|
172
|
+
.map((events) => {
|
|
173
|
+
if (events.length === 1) {
|
|
174
|
+
return generateMockEventLogFunction(events[0], contract.name, false)
|
|
175
|
+
} else {
|
|
176
|
+
return events.map((e) => generateMockEventLogFunction(e, contract.name, true)).join('\n')
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
.join('\n')}
|
|
180
|
+
`
|
|
181
|
+
|
|
182
|
+
const imports = createImportsForUsedIdentifiers(
|
|
183
|
+
{
|
|
184
|
+
'@ethersproject/providers': ['Log'],
|
|
185
|
+
'.': [
|
|
186
|
+
`get${contract.name}Contract`,
|
|
187
|
+
...Object.values(contract.events).flatMap((events) => {
|
|
188
|
+
if (events.length === 1) {
|
|
189
|
+
return `${events[0].name}EventObject`
|
|
190
|
+
} else {
|
|
191
|
+
return events.flatMap((e) => `${getFullSignatureAsSymbolForEvent(e)}_EventObject`)
|
|
192
|
+
}
|
|
193
|
+
}),
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
source
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
return imports + source
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function generateOnEventFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {
|
|
203
|
+
let eventName = event.name
|
|
204
|
+
if (includeArgTypes) {
|
|
205
|
+
eventName = getFullSignatureAsSymbolForEvent(event) + '_'
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const filterName = getFullSignatureForEvent(event)
|
|
209
|
+
|
|
210
|
+
return `
|
|
211
|
+
on${eventName}(
|
|
212
|
+
handler: (event: ${eventName}Event, ctx: ${contractName}Context) => void,
|
|
213
|
+
filter?: ${eventName}EventFilter | ${eventName}EventFilter[]
|
|
214
|
+
) {
|
|
215
|
+
if (!filter) {
|
|
216
|
+
filter = ${contractName}Processor.filters['${filterName}'](${event.inputs.map(() => 'null').join(',')})
|
|
217
|
+
}
|
|
218
|
+
return super.onEvent(handler, filter)
|
|
219
|
+
}
|
|
220
|
+
`
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function generateViewFunction(func: FunctionDeclaration): string {
|
|
224
|
+
return `
|
|
225
|
+
async ${func.name}(${generateInputTypes(func.inputs, { useStructs: true })}overrides?: CallOverrides) {
|
|
226
|
+
try {
|
|
227
|
+
if (overrides) {
|
|
228
|
+
return await this.contract.${func.name}(${
|
|
229
|
+
func.inputs.length > 0 ? func.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
|
230
|
+
} overrides)
|
|
231
|
+
} else {
|
|
232
|
+
return await this.contract.${func.name}(${func.inputs
|
|
233
|
+
.map((input, index) => input.name || `arg${index}`)
|
|
234
|
+
.join(',')})
|
|
235
|
+
}
|
|
236
|
+
} catch (e) {
|
|
237
|
+
throw transformEtherError(e, undefined)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
`
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function generateBoundViewFunction(func: FunctionDeclaration): string {
|
|
244
|
+
return `
|
|
245
|
+
async ${func.name}(${generateInputTypes(func.inputs, { useStructs: true })}overrides?: CallOverrides) {
|
|
246
|
+
try {
|
|
247
|
+
if (!overrides && this.context) {
|
|
248
|
+
overrides = {
|
|
249
|
+
blockTag: this.context.blockNumber.toNumber(),
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (overrides) {
|
|
253
|
+
return await this.view.${func.name}(${
|
|
254
|
+
func.inputs.length > 0 ? func.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
|
255
|
+
} overrides)
|
|
256
|
+
} else {
|
|
257
|
+
return await this.view.${func.name}(${func.inputs.map((input, index) => input.name || `arg${index}`).join(',')})
|
|
258
|
+
}
|
|
259
|
+
} catch (e) {
|
|
260
|
+
throw transformEtherError(e, this.context)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
`
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function generateMockEventLogFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {
|
|
267
|
+
let eventName = event.name
|
|
268
|
+
let eventNameWithSignature = event.name
|
|
269
|
+
if (includeArgTypes) {
|
|
270
|
+
eventName = getFullSignatureAsSymbolForEvent(event) + '_'
|
|
271
|
+
eventNameWithSignature = getFullSignatureForEvent(event)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return `
|
|
275
|
+
export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): Log {
|
|
276
|
+
const contract = get${contractName}Contract(contractAddress)
|
|
277
|
+
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
|
278
|
+
contract.rawContract.interface.getEvent('${eventNameWithSignature}'),
|
|
279
|
+
Object.values(event)
|
|
280
|
+
)
|
|
281
|
+
return {
|
|
282
|
+
...mockField,
|
|
283
|
+
address: contractAddress,
|
|
284
|
+
data: encodedLog.data,
|
|
285
|
+
topics: encodedLog.topics,
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
`
|
|
289
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Ethers from '@typechain/ethers-v5'
|
|
2
|
+
import { Config, extractAbi, extractDocumentation, FileDescription, parse, shortenFullJsonFilePath } from 'typechain'
|
|
3
|
+
import { dirname, join, relative } from 'path'
|
|
4
|
+
import { codeGenIndex, codeGenSentioFile, codeGenTestUtilsFile } from './codegen'
|
|
5
|
+
|
|
6
|
+
export default class EthersSentio extends Ethers {
|
|
7
|
+
constructor(config: Config) {
|
|
8
|
+
if (!config.outDir) {
|
|
9
|
+
throw new Error('Out put path not specificed')
|
|
10
|
+
}
|
|
11
|
+
super(config)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// TODO(pc): also have to override transformBinFile, transformFile
|
|
15
|
+
override transformAbiOrFullJsonFile(file: FileDescription): FileDescription[] | void {
|
|
16
|
+
const abi = extractAbi(file.contents)
|
|
17
|
+
if (abi.length === 0) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const documentation = extractDocumentation(file.contents)
|
|
22
|
+
|
|
23
|
+
const jsonPath = relative(this.cfg.inputDir, shortenFullJsonFilePath(file.path, this.cfg.allFiles))
|
|
24
|
+
const contract = parse(abi, jsonPath, documentation)
|
|
25
|
+
const files = super.transformAbiOrFullJsonFile(file)
|
|
26
|
+
|
|
27
|
+
if (files !== undefined) {
|
|
28
|
+
// files.forEach(this.transformFilePath)
|
|
29
|
+
// for (const file of files) {
|
|
30
|
+
// this.transformFilePath(file)
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
return [
|
|
34
|
+
...files,
|
|
35
|
+
{
|
|
36
|
+
path: join(dirname(files[0].path), `${contract.name.toLowerCase()}_processor.ts`),
|
|
37
|
+
contents: codeGenSentioFile(contract),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
path: join(dirname(files[0].path), '..', contract.name.toLowerCase(), 'index.ts'),
|
|
41
|
+
contents: codeGenIndex(contract),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
path: join(dirname(files[0].path), '..', contract.name.toLowerCase(), 'test-utils.ts'),
|
|
45
|
+
contents: codeGenTestUtilsFile(contract),
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|