@sentio/sdk 1.9.0 → 1.10.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/base-processor-template.d.ts +6 -0
- package/lib/base-processor-template.js +5 -0
- package/lib/base-processor-template.js.map +1 -1
- package/lib/base-processor.d.ts +1 -1
- package/lib/base-processor.js +9 -2
- package/lib/base-processor.js.map +1 -1
- package/lib/builtin/internal/erc20_processor.d.ts +148 -99
- package/lib/builtin/internal/erc20_processor.js +96 -42
- package/lib/builtin/internal/erc20_processor.js.map +1 -1
- package/lib/builtin/internal/erc20bytes_processor.d.ts +80 -52
- package/lib/builtin/internal/erc20bytes_processor.js +49 -22
- package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.d.ts +92 -64
- package/lib/builtin/internal/weth9_processor.js +63 -30
- package/lib/builtin/internal/weth9_processor.js.map +1 -1
- package/lib/context.js +1 -0
- package/lib/context.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/lib/target-ethers-sentio/codegen.js +35 -15
- package/lib/target-ethers-sentio/codegen.js.map +1 -1
- package/lib/target-ethers-sentio/functions.js +13 -6
- package/lib/target-ethers-sentio/functions.js.map +1 -1
- package/lib/test/codegen.test.js +9 -7
- package/lib/test/codegen.test.js.map +1 -1
- package/lib/test/erc20-template.js +2 -2
- package/lib/test/erc20-template.js.map +1 -1
- package/lib/test/erc20.js +6 -4
- package/lib/test/erc20.js.map +1 -1
- package/lib/test/erc20.test.js +25 -0
- package/lib/test/erc20.test.js.map +1 -1
- package/lib/test/test-processor-server.d.ts +5 -1
- package/lib/test/test-processor-server.js +41 -0
- package/lib/test/test-processor-server.js.map +1 -1
- package/lib/trace.d.ts +5 -5
- package/lib/trace.js +21 -0
- package/lib/trace.js.map +1 -1
- package/package.json +1 -1
- package/src/base-processor-template.ts +13 -0
- package/src/base-processor.ts +10 -3
- package/src/builtin/internal/erc20_processor.ts +264 -123
- package/src/builtin/internal/erc20bytes_processor.ts +139 -63
- package/src/builtin/internal/weth9_processor.ts +155 -76
- package/src/context.ts +1 -0
- package/src/index.ts +1 -1
- package/src/target-ethers-sentio/codegen.ts +34 -16
- package/src/target-ethers-sentio/functions.ts +20 -7
- package/src/test/abis/evm/CommitmentPool.json +1034 -0
- package/src/test/codegen.test.ts +10 -7
- package/src/test/erc20-template.ts +2 -2
- package/src/test/erc20.test.ts +29 -0
- package/src/test/erc20.ts +6 -4
- package/src/test/test-processor-server.ts +47 -0
- package/src/trace.ts +27 -5
|
@@ -20,6 +20,8 @@ export function codeGenIndex(contract: Contract): string {
|
|
|
20
20
|
|
|
21
21
|
export function codeGenSentioFile(contract: Contract): string {
|
|
22
22
|
const source = `
|
|
23
|
+
${Object.values(contract.functions).map(codegenCallTraceTypes).join('\n')}
|
|
24
|
+
|
|
23
25
|
const templateContract = ${contract.name}__factory.connect("", DummyProvider)
|
|
24
26
|
|
|
25
27
|
export class ${contract.name}ContractView extends ContractView<${contract.name}> {
|
|
@@ -71,10 +73,12 @@ export function codeGenSentioFile(contract: Contract): string {
|
|
|
71
73
|
}
|
|
72
74
|
})
|
|
73
75
|
.join('\n')}
|
|
76
|
+
|
|
77
|
+
${Object.values(contract.functions)
|
|
78
|
+
.map((f) => codegenFunctions(f, contract.name))
|
|
79
|
+
.join('\n')}
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
${Object.values(contract.functions).map(codegenCallTraceTypes).join('\n')}
|
|
77
|
-
|
|
78
82
|
export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {
|
|
79
83
|
${Object.values(contract.events)
|
|
80
84
|
.map((events) => {
|
|
@@ -121,6 +125,31 @@ export function codeGenSentioFile(contract: Contract): string {
|
|
|
121
125
|
return contract
|
|
122
126
|
}
|
|
123
127
|
`
|
|
128
|
+
const eventsImports = Object.values(contract.events).flatMap((events) => {
|
|
129
|
+
if (events.length === 1) {
|
|
130
|
+
return [`${events[0].name}Event`, `${events[0].name}EventFilter`]
|
|
131
|
+
} else {
|
|
132
|
+
return events.flatMap((e) => [
|
|
133
|
+
`${getFullSignatureAsSymbolForEvent(e)}_Event`,
|
|
134
|
+
`${getFullSignatureAsSymbolForEvent(e)}_EventFilter`,
|
|
135
|
+
])
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const structImports = Object.values(contract.structs).flatMap((structs) => {
|
|
140
|
+
return structs.flatMap((s) => {
|
|
141
|
+
if (!s.structName) {
|
|
142
|
+
return []
|
|
143
|
+
}
|
|
144
|
+
if (s.structName.namespace) {
|
|
145
|
+
return [s.structName.namespace]
|
|
146
|
+
} else {
|
|
147
|
+
return [s.structName.identifier]
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
// dedup namespace
|
|
152
|
+
const uniqueStructImports = [...new Set(structImports)]
|
|
124
153
|
|
|
125
154
|
const imports = createImportsForUsedIdentifiers(
|
|
126
155
|
{
|
|
@@ -141,22 +170,11 @@ export function codeGenSentioFile(contract: Contract): string {
|
|
|
141
170
|
'ContractView',
|
|
142
171
|
'DummyProvider',
|
|
143
172
|
'getContractName',
|
|
144
|
-
'
|
|
173
|
+
'TypedCallTrace',
|
|
145
174
|
],
|
|
146
175
|
'./common': ['PromiseOrValue'],
|
|
147
176
|
'./index': [`${contract.name}`, `${contract.name}__factory`],
|
|
148
|
-
[`./${contract.name}`]:
|
|
149
|
-
...Object.values(contract.events).map((events) => {
|
|
150
|
-
if (events.length === 1) {
|
|
151
|
-
return [`${events[0].name}Event`, `${events[0].name}EventFilter`]
|
|
152
|
-
} else {
|
|
153
|
-
return events.flatMap((e) => [
|
|
154
|
-
`${getFullSignatureAsSymbolForEvent(e)}_Event`,
|
|
155
|
-
`${getFullSignatureAsSymbolForEvent(e)}_EventFilter`,
|
|
156
|
-
])
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
),
|
|
177
|
+
[`./${contract.name}`]: eventsImports.concat(uniqueStructImports),
|
|
160
178
|
},
|
|
161
179
|
source
|
|
162
180
|
)
|
|
@@ -216,7 +234,7 @@ function generateOnEventFunction(event: EventDeclaration, contractName: string,
|
|
|
216
234
|
const filterName = getFullSignatureForEvent(event)
|
|
217
235
|
|
|
218
236
|
return `
|
|
219
|
-
|
|
237
|
+
onEvent${eventName}(
|
|
220
238
|
handler: (event: ${eventName}Event, ctx: ${contractName}Context) => void,
|
|
221
239
|
filter?: ${eventName}EventFilter | ${eventName}EventFilter[]
|
|
222
240
|
) {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
generateOutputComplexTypeAsArray,
|
|
3
|
+
generateOutputComplexTypesAsObject,
|
|
4
|
+
} from '@typechain/ethers-v5/dist/codegen/types'
|
|
2
5
|
import { FunctionDeclaration, getSignatureForFn } from 'typechain'
|
|
6
|
+
import { utils } from 'ethers'
|
|
3
7
|
|
|
4
8
|
export function codegenFunctions(fns: FunctionDeclaration[], contractName: string): string {
|
|
5
9
|
if (fns.length === 1) {
|
|
@@ -18,19 +22,28 @@ export function codegenCallTraceTypes(fns: FunctionDeclaration[]): string {
|
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
function codegenCallTraceType(fn: FunctionDeclaration, overloadedName?: string): string {
|
|
25
|
+
const identifier = capitalizeFirstChar(overloadedName ?? fn.name)
|
|
26
|
+
|
|
27
|
+
const components = fn.inputs.map((input, i) => ({ name: input.name ?? `arg${i.toString()}`, type: input.type }))
|
|
28
|
+
const arrayOutput = generateOutputComplexTypeAsArray(components, { useStructs: true })
|
|
29
|
+
const objectOutput = generateOutputComplexTypesAsObject(components, { useStructs: true }) || '{}'
|
|
30
|
+
|
|
21
31
|
return `
|
|
22
|
-
export interface ${
|
|
23
|
-
|
|
24
|
-
}
|
|
32
|
+
export interface ${identifier}CallObject ${objectOutput}
|
|
33
|
+
|
|
34
|
+
export type ${identifier}CallTrace = TypedCallTrace<${arrayOutput}, ${identifier}CallObject>
|
|
25
35
|
`
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
function generateFunction(fn: FunctionDeclaration, contractName: string, overloadedName?: string): string {
|
|
39
|
+
const signature = getSignatureForFn(fn)
|
|
40
|
+
const sighash = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10)
|
|
41
|
+
|
|
29
42
|
return `
|
|
30
|
-
|
|
31
|
-
handler: (
|
|
43
|
+
onCall${capitalizeFirstChar(overloadedName ?? fn.name)}(
|
|
44
|
+
handler: (call: ${capitalizeFirstChar(overloadedName ?? fn.name)}CallTrace, ctx: ${contractName}Context) => void
|
|
32
45
|
) {
|
|
33
|
-
return super.onTrace("${
|
|
46
|
+
return super.onTrace("${sighash}", handler);
|
|
34
47
|
}
|
|
35
48
|
`
|
|
36
49
|
}
|