@sentio/sdk 2.17.1-rc.1 → 2.18.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +17 -0
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +88 -0
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.d.ts +13 -0
- package/lib/eth/builtin/internal/erc1155-processor.js +56 -0
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.d.ts +28 -1
- package/lib/eth/builtin/internal/erc20-processor.js +168 -0
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +14 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.js +56 -0
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.d.ts +17 -0
- package/lib/eth/builtin/internal/erc721-processor.js +88 -0
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.d.ts +18 -1
- package/lib/eth/builtin/internal/weth9-processor.js +88 -0
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/codegen/file.js +22 -4
- package/lib/eth/codegen/file.js.map +1 -1
- package/lib/eth/codegen/function-calls.d.ts +5 -0
- package/lib/eth/codegen/function-calls.js +64 -0
- package/lib/eth/codegen/function-calls.js.map +1 -0
- package/lib/eth/context.d.ts +4 -0
- package/lib/eth/context.js +4 -0
- package/lib/eth/context.js.map +1 -1
- package/package.json +3 -3
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +105 -0
- package/src/eth/builtin/internal/erc1155-processor.ts +111 -0
- package/src/eth/builtin/internal/erc20-processor.ts +228 -1
- package/src/eth/builtin/internal/erc20bytes-processor.ts +84 -1
- package/src/eth/builtin/internal/erc721-processor.ts +146 -0
- package/src/eth/builtin/internal/weth9-processor.ts +114 -1
- package/src/eth/codegen/file.ts +22 -4
- package/src/eth/codegen/function-calls.ts +78 -0
- package/src/eth/context.ts +7 -0
- package/lib/eth/codegen/view-function.d.ts +0 -5
- package/lib/eth/codegen/view-function.js +0 -60
- package/lib/eth/codegen/view-function.js.map +0 -1
- package/src/eth/codegen/view-function.ts +0 -71
package/src/eth/codegen/file.ts
CHANGED
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
import { reservedKeywords } from '@sentio/ethers-v6/dist/codegen/reserved-keywords.js'
|
10
10
|
import { codegenCallTraceTypes, generateCallHandlers } from './functions-handler.js'
|
11
11
|
import { generateEventFilters, generateEventHandlers } from './event-handler.js'
|
12
|
-
import { generateBoundViewFunctions, generateViewFunctions } from './
|
12
|
+
import { generateBoundViewFunctions, generateViewFunctions } from './function-calls.js'
|
13
13
|
|
14
14
|
export function codeGenIndex(contract: Contract): string {
|
15
15
|
return `
|
@@ -29,23 +29,41 @@ export function codeGenSentioFile(contract: Contract): string {
|
|
29
29
|
export class ${contract.name}ContractView extends ContractView<${contract.name}> {
|
30
30
|
constructor (contract: ${contract.name}) {
|
31
31
|
super(contract);
|
32
|
+
this.callStatic.contract = contract;
|
32
33
|
}
|
33
34
|
|
34
35
|
${Object.values(contract.functions)
|
35
36
|
.filter((f) => !reservedKeywords.has(f[0].name))
|
36
|
-
.
|
37
|
+
.flatMap((fs) => generateViewFunctions(true, fs))
|
37
38
|
.join('\n')}
|
39
|
+
|
40
|
+
callStatic = {
|
41
|
+
contract: this.contract,
|
42
|
+
${Object.values(contract.functions)
|
43
|
+
.filter((f) => !reservedKeywords.has(f[0].name))
|
44
|
+
.flatMap((fs) => generateViewFunctions(false, fs))
|
45
|
+
.join(',\n')}
|
46
|
+
}
|
38
47
|
}
|
39
48
|
|
40
49
|
export class ${contract.name}BoundContractView extends BoundContractView<${contract.name},
|
41
50
|
${contract.name}ContractView> {
|
42
51
|
${Object.values(contract.functions)
|
43
52
|
.filter((f) => !reservedKeywords.has(f[0].name))
|
44
|
-
.
|
53
|
+
.flatMap((fs) => generateBoundViewFunctions(true, fs))
|
45
54
|
.join('\n')}
|
55
|
+
|
56
|
+
callStatic = {
|
57
|
+
view: this.view,
|
58
|
+
context: this.context,
|
59
|
+
${Object.values(contract.functions)
|
60
|
+
.filter((f) => !reservedKeywords.has(f[0].name))
|
61
|
+
.flatMap((fs) => generateBoundViewFunctions(false, fs))
|
62
|
+
.join(',\n')}
|
63
|
+
}
|
46
64
|
}
|
47
65
|
|
48
|
-
|
66
|
+
export type ${contract.name}Context = ContractContext<${contract.name}, ${contract.name}BoundContractView>
|
49
67
|
|
50
68
|
export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {
|
51
69
|
${Object.values(contract.events)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
// https://github.com/dethcrypto/TypeChain/blob/015abb28bd22826611051f27e0ec96a00f9a0b61/packages/target-ethers-v5/src/codegen/functions.ts#L54
|
2
|
+
import { FunctionDeclaration } from 'typechain'
|
3
|
+
import { generateInputTypes, generateOutputTypes } from '@sentio/ethers-v6/dist/codegen/types.js'
|
4
|
+
import { getFullSignatureAsSymbolForFunction, getFullSignatureForFunction } from './types.js'
|
5
|
+
|
6
|
+
function generateReturnTypes(fn: FunctionDeclaration) {
|
7
|
+
// sounds like returnResultObject should be true but we need to set false to make it work
|
8
|
+
return `Promise<${generateOutputTypes({ returnResultObject: false, useStructs: true }, fn.outputs)}>`
|
9
|
+
}
|
10
|
+
|
11
|
+
export function generateViewFunctions(view: boolean, functions: FunctionDeclaration[]): string[] {
|
12
|
+
const includeArgTypes = functions.length !== 1
|
13
|
+
return functions.flatMap((fn) => generateViewFunction(view, fn, includeArgTypes))
|
14
|
+
}
|
15
|
+
|
16
|
+
export function generateViewFunction(view: boolean, fn: FunctionDeclaration, includeArgTypes: boolean): string[] {
|
17
|
+
const isView = fn.stateMutability === 'view' || fn.stateMutability === 'pure'
|
18
|
+
if (view !== isView) {
|
19
|
+
return []
|
20
|
+
}
|
21
|
+
const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name
|
22
|
+
|
23
|
+
const call = view ? '' : '.staticCall'
|
24
|
+
|
25
|
+
const func = `this.contract.getFunction("` + getFullSignatureForFunction(fn) + '")'
|
26
|
+
// if (overrides) {
|
27
|
+
// return await ${call}(${
|
28
|
+
// fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
29
|
+
// } overrides)
|
30
|
+
// } else {
|
31
|
+
// return await ${call}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})
|
32
|
+
// }
|
33
|
+
return [
|
34
|
+
`
|
35
|
+
async ${declName}(${generateInputTypes(fn.inputs, {
|
36
|
+
useStructs: true,
|
37
|
+
})}overrides?: Overrides): ${generateReturnTypes(fn)} {
|
38
|
+
try {
|
39
|
+
return await ${func}${call}(${
|
40
|
+
fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
41
|
+
} overrides || {})
|
42
|
+
} catch (e) {
|
43
|
+
throw transformEtherError(e, undefined)
|
44
|
+
}
|
45
|
+
}
|
46
|
+
`,
|
47
|
+
]
|
48
|
+
}
|
49
|
+
|
50
|
+
export function generateBoundViewFunctions(view: boolean, functions: FunctionDeclaration[]): string[] {
|
51
|
+
const includeArgTypes = functions.length !== 1
|
52
|
+
return functions.flatMap((fn) => generateBoundViewFunction(view, fn, includeArgTypes))
|
53
|
+
}
|
54
|
+
|
55
|
+
export function generateBoundViewFunction(view: boolean, fn: FunctionDeclaration, includeArgTypes: boolean): string[] {
|
56
|
+
const isView = fn.stateMutability === 'view' || fn.stateMutability === 'pure'
|
57
|
+
if (view !== isView) {
|
58
|
+
return []
|
59
|
+
}
|
60
|
+
const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name
|
61
|
+
|
62
|
+
const qualifier = view ? 'view' : 'view.callStatic'
|
63
|
+
|
64
|
+
return [
|
65
|
+
`
|
66
|
+
async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
|
67
|
+
useStructs: true,
|
68
|
+
})}overrides?: Overrides): ${generateReturnTypes(fn)} {
|
69
|
+
return await this.${qualifier}.${declName}(${
|
70
|
+
fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
71
|
+
} {
|
72
|
+
blockTag: this.context.blockNumber,
|
73
|
+
...overrides
|
74
|
+
})
|
75
|
+
}
|
76
|
+
`,
|
77
|
+
]
|
78
|
+
}
|
package/src/eth/context.ts
CHANGED
@@ -147,6 +147,9 @@ export class ContractContext<
|
|
147
147
|
) {
|
148
148
|
super(chainId, view.address, timestamp, block, log, trace, transaction, transactionReceipt, baseLabels)
|
149
149
|
view.context = this
|
150
|
+
if (view.callStatic) {
|
151
|
+
view.callStatic.context = this
|
152
|
+
}
|
150
153
|
this.contractName = contractName
|
151
154
|
this.contract = view
|
152
155
|
}
|
@@ -181,6 +184,10 @@ export class BoundContractView<TContract extends BaseContract, TContractView ext
|
|
181
184
|
// context will be set right after context creation (in context's constructor)
|
182
185
|
// context: ContractContext<TContract, BoundContractView<TContract, TContractView>>
|
183
186
|
context: EthContext
|
187
|
+
callStatic: {
|
188
|
+
context: EthContext
|
189
|
+
view: TContractView
|
190
|
+
}
|
184
191
|
|
185
192
|
constructor(address: string, view: TContractView) {
|
186
193
|
this.address = address
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { FunctionDeclaration } from 'typechain';
|
2
|
-
export declare function generateViewFunctions(functions: FunctionDeclaration[]): string;
|
3
|
-
export declare function generateViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string;
|
4
|
-
export declare function generateBoundViewFunctions(functions: FunctionDeclaration[]): string;
|
5
|
-
export declare function generateBoundViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string;
|
@@ -1,60 +0,0 @@
|
|
1
|
-
import { generateInputTypes, generateOutputTypes } from '@sentio/ethers-v6/dist/codegen/types.js';
|
2
|
-
import { getFullSignatureAsSymbolForFunction, getFullSignatureForFunction } from './types.js';
|
3
|
-
function generateReturnTypes(fn) {
|
4
|
-
// sounds like returnResultObject should be true but we need to set false to make it work
|
5
|
-
return `Promise<${generateOutputTypes({ returnResultObject: false, useStructs: true }, fn.outputs)}>`;
|
6
|
-
}
|
7
|
-
export function generateViewFunctions(functions) {
|
8
|
-
if (functions.length === 1) {
|
9
|
-
return generateViewFunction(functions[0], false);
|
10
|
-
}
|
11
|
-
return functions.map((fn) => generateViewFunction(fn, true)).join('\n');
|
12
|
-
}
|
13
|
-
export function generateViewFunction(fn, includeArgTypes) {
|
14
|
-
if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {
|
15
|
-
return '';
|
16
|
-
}
|
17
|
-
const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name;
|
18
|
-
const call = 'this.contract.getFunction("' + getFullSignatureForFunction(fn) + '")';
|
19
|
-
// if (overrides) {
|
20
|
-
// return await ${call}(${
|
21
|
-
// fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
22
|
-
// } overrides)
|
23
|
-
// } else {
|
24
|
-
// return await ${call}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})
|
25
|
-
// }
|
26
|
-
return `
|
27
|
-
async ${declName}(${generateInputTypes(fn.inputs, {
|
28
|
-
useStructs: true,
|
29
|
-
})}overrides?: Overrides): ${generateReturnTypes(fn)} {
|
30
|
-
try {
|
31
|
-
return await ${call}(${fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''} overrides || {})
|
32
|
-
} catch (e) {
|
33
|
-
throw transformEtherError(e, undefined)
|
34
|
-
}
|
35
|
-
}
|
36
|
-
`;
|
37
|
-
}
|
38
|
-
export function generateBoundViewFunctions(functions) {
|
39
|
-
if (functions.length === 1) {
|
40
|
-
return generateBoundViewFunction(functions[0], false);
|
41
|
-
}
|
42
|
-
return functions.map((fn) => generateBoundViewFunction(fn, true)).join('\n');
|
43
|
-
}
|
44
|
-
export function generateBoundViewFunction(fn, includeArgTypes) {
|
45
|
-
if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {
|
46
|
-
return '';
|
47
|
-
}
|
48
|
-
const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name;
|
49
|
-
return `
|
50
|
-
async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
|
51
|
-
useStructs: true,
|
52
|
-
})}overrides?: Overrides): ${generateReturnTypes(fn)} {
|
53
|
-
return await this.view.${declName}(${fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''} {
|
54
|
-
blockTag: this.context.blockNumber,
|
55
|
-
...overrides
|
56
|
-
})
|
57
|
-
}
|
58
|
-
`;
|
59
|
-
}
|
60
|
-
//# sourceMappingURL=view-function.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"view-function.js","sourceRoot":"","sources":["../../../src/eth/codegen/view-function.ts"],"names":[],"mappings":"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","sourcesContent":["// https://github.com/dethcrypto/TypeChain/blob/015abb28bd22826611051f27e0ec96a00f9a0b61/packages/target-ethers-v5/src/codegen/functions.ts#L54\nimport { FunctionDeclaration } from 'typechain'\nimport { generateInputTypes, generateOutputTypes } from '@sentio/ethers-v6/dist/codegen/types.js'\nimport { getFullSignatureAsSymbolForFunction, getFullSignatureForFunction } from './types.js'\n\nfunction generateReturnTypes(fn: FunctionDeclaration) {\n // sounds like returnResultObject should be true but we need to set false to make it work\n return `Promise<${generateOutputTypes({ returnResultObject: false, useStructs: true }, fn.outputs)}>`\n}\n\nexport function generateViewFunctions(functions: FunctionDeclaration[]): string {\n if (functions.length === 1) {\n return generateViewFunction(functions[0], false)\n }\n return functions.map((fn) => generateViewFunction(fn, true)).join('\\n')\n}\n\nexport function generateViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string {\n if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {\n return ''\n }\n const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name\n const call = 'this.contract.getFunction(\"' + getFullSignatureForFunction(fn) + '\")'\n // if (overrides) {\n // return await ${call}(${\n // fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n // } overrides)\n // } else {\n // return await ${call}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})\n // }\n return `\n async ${declName}(${generateInputTypes(fn.inputs, {\n useStructs: true,\n })}overrides?: Overrides): ${generateReturnTypes(fn)} {\n try { \n return await ${call}(${\n fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n } overrides || {})\n } catch (e) {\n throw transformEtherError(e, undefined)\n }\n }\n `\n}\n\nexport function generateBoundViewFunctions(functions: FunctionDeclaration[]): string {\n if (functions.length === 1) {\n return generateBoundViewFunction(functions[0], false)\n }\n return functions.map((fn) => generateBoundViewFunction(fn, true)).join('\\n')\n}\n\nexport function generateBoundViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string {\n if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {\n return ''\n }\n const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name\n\n return `\n async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {\n useStructs: true,\n })}overrides?: Overrides): ${generateReturnTypes(fn)} {\n return await this.view.${declName}(${\n fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n } {\n blockTag: this.context.blockNumber,\n ...overrides\n })\n }\n `\n}\n"]}
|
@@ -1,71 +0,0 @@
|
|
1
|
-
// https://github.com/dethcrypto/TypeChain/blob/015abb28bd22826611051f27e0ec96a00f9a0b61/packages/target-ethers-v5/src/codegen/functions.ts#L54
|
2
|
-
import { FunctionDeclaration } from 'typechain'
|
3
|
-
import { generateInputTypes, generateOutputTypes } from '@sentio/ethers-v6/dist/codegen/types.js'
|
4
|
-
import { getFullSignatureAsSymbolForFunction, getFullSignatureForFunction } from './types.js'
|
5
|
-
|
6
|
-
function generateReturnTypes(fn: FunctionDeclaration) {
|
7
|
-
// sounds like returnResultObject should be true but we need to set false to make it work
|
8
|
-
return `Promise<${generateOutputTypes({ returnResultObject: false, useStructs: true }, fn.outputs)}>`
|
9
|
-
}
|
10
|
-
|
11
|
-
export function generateViewFunctions(functions: FunctionDeclaration[]): string {
|
12
|
-
if (functions.length === 1) {
|
13
|
-
return generateViewFunction(functions[0], false)
|
14
|
-
}
|
15
|
-
return functions.map((fn) => generateViewFunction(fn, true)).join('\n')
|
16
|
-
}
|
17
|
-
|
18
|
-
export function generateViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string {
|
19
|
-
if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {
|
20
|
-
return ''
|
21
|
-
}
|
22
|
-
const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name
|
23
|
-
const call = 'this.contract.getFunction("' + getFullSignatureForFunction(fn) + '")'
|
24
|
-
// if (overrides) {
|
25
|
-
// return await ${call}(${
|
26
|
-
// fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
27
|
-
// } overrides)
|
28
|
-
// } else {
|
29
|
-
// return await ${call}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})
|
30
|
-
// }
|
31
|
-
return `
|
32
|
-
async ${declName}(${generateInputTypes(fn.inputs, {
|
33
|
-
useStructs: true,
|
34
|
-
})}overrides?: Overrides): ${generateReturnTypes(fn)} {
|
35
|
-
try {
|
36
|
-
return await ${call}(${
|
37
|
-
fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
38
|
-
} overrides || {})
|
39
|
-
} catch (e) {
|
40
|
-
throw transformEtherError(e, undefined)
|
41
|
-
}
|
42
|
-
}
|
43
|
-
`
|
44
|
-
}
|
45
|
-
|
46
|
-
export function generateBoundViewFunctions(functions: FunctionDeclaration[]): string {
|
47
|
-
if (functions.length === 1) {
|
48
|
-
return generateBoundViewFunction(functions[0], false)
|
49
|
-
}
|
50
|
-
return functions.map((fn) => generateBoundViewFunction(fn, true)).join('\n')
|
51
|
-
}
|
52
|
-
|
53
|
-
export function generateBoundViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string {
|
54
|
-
if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {
|
55
|
-
return ''
|
56
|
-
}
|
57
|
-
const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name
|
58
|
-
|
59
|
-
return `
|
60
|
-
async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
|
61
|
-
useStructs: true,
|
62
|
-
})}overrides?: Overrides): ${generateReturnTypes(fn)} {
|
63
|
-
return await this.view.${declName}(${
|
64
|
-
fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
|
65
|
-
} {
|
66
|
-
blockTag: this.context.blockNumber,
|
67
|
-
...overrides
|
68
|
-
})
|
69
|
-
}
|
70
|
-
`
|
71
|
-
}
|