@riaskov/iohtee-abi-wrapper 2.0.8 → 3.0.0
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/LICENSE +202 -0
- package/README.md +66 -101
- package/dist/abiWrapper.d.ts +8 -6
- package/dist/abiWrapper.js +40 -32
- package/dist/abiWrapper.js.map +1 -1
- package/dist/baseContract.d.ts +28 -3
- package/dist/baseContract.js +89 -28
- package/dist/baseContract.js.map +1 -1
- package/dist/bin/iohtee-abi-wrapper.js +39 -28
- package/dist/bin/iohtee-abi-wrapper.js.map +1 -1
- package/dist/context.d.ts +16 -3
- package/dist/contractTemplate.d.ts +6 -12
- package/dist/contractTemplate.js +80 -120
- package/dist/contractTemplate.js.map +1 -1
- package/dist/helpers.d.ts +8 -2
- package/dist/helpers.js +65 -25
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +72 -67
- package/templates/contract.ethers.eta +99 -0
- package/templates/contract.viem.eta +124 -0
- package/templates/_event_enum.mustache +0 -1
- package/templates/_event_types.mustache +0 -10
- package/templates/_event_utils.mustache +0 -3
- package/templates/_filter.mustache +0 -3
- package/templates/_function.mustache +0 -21
- package/templates/_getter.mustache +0 -10
- package/templates/_method_input.mustache +0 -4
- package/templates/_method_output.mustache +0 -10
- package/templates/_params.mustache +0 -1
- package/templates/contract.mustache +0 -92
package/dist/helpers.js
CHANGED
|
@@ -1,48 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.inputType = inputType;
|
|
4
|
+
exports.outputType = outputType;
|
|
5
|
+
exports.renderMethodInput = renderMethodInput;
|
|
6
|
+
exports.renderParams = renderParams;
|
|
7
|
+
exports.renderMethodOutput = renderMethodOutput;
|
|
8
|
+
exports.createTemplateHelpers = createTemplateHelpers;
|
|
4
9
|
const TYPE_MAPPING = [
|
|
5
|
-
{ regex:
|
|
6
|
-
{ regex:
|
|
7
|
-
{ regex:
|
|
8
|
-
{ regex:
|
|
9
|
-
{ regex:
|
|
10
|
+
{ regex: /^string$/, tsType: 'string' },
|
|
11
|
+
{ regex: /^address$/, tsType: '`0x${string}`' },
|
|
12
|
+
{ regex: /^bool$/, tsType: 'boolean' },
|
|
13
|
+
{ regex: /^u?int\d*$/, tsType: 'bigint' },
|
|
14
|
+
{ regex: /^bytes\d*$/, tsType: '`0x${string}`' },
|
|
10
15
|
];
|
|
11
16
|
const INPUT_TYPE_MAPPING = [
|
|
12
|
-
{ regex:
|
|
13
|
-
|
|
17
|
+
{ regex: /^u?int(8|16|32|64|128|256)?$/, tsType: 'bigint' },
|
|
18
|
+
...TYPE_MAPPING,
|
|
19
|
+
];
|
|
14
20
|
const ARRAY_BRACES = /\[\d*]$/;
|
|
15
21
|
function isArray(solidityType) {
|
|
16
|
-
return
|
|
22
|
+
return ARRAY_BRACES.test(solidityType);
|
|
17
23
|
}
|
|
18
24
|
function isTuple(solidityType) {
|
|
19
|
-
return
|
|
25
|
+
return solidityType.includes('tuple');
|
|
20
26
|
}
|
|
21
27
|
function typeConversion(types, solidityType, components) {
|
|
22
28
|
if (isArray(solidityType)) {
|
|
23
29
|
const solidityItemType = solidityType.replace(ARRAY_BRACES, '');
|
|
24
|
-
const type = typeConversion(types, solidityItemType);
|
|
30
|
+
const type = typeConversion(types, solidityItemType, components);
|
|
25
31
|
return `${type}[]`;
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
return `[${components
|
|
33
|
+
if (isTuple(solidityType) && components?.length) {
|
|
34
|
+
return `[${components
|
|
35
|
+
.map((component) => typeConversion(types, component.type, getComponents(component)))
|
|
36
|
+
.join(', ')}]`;
|
|
29
37
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return mapping.tsType;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
throw new Error(`Unknown Solidity type found: ${solidityType}`);
|
|
37
|
-
}
|
|
38
|
+
const mapping = types.find((item) => item.regex.test(solidityType));
|
|
39
|
+
if (!mapping) {
|
|
40
|
+
throw new Error(`Unknown Solidity type found: ${solidityType}`);
|
|
38
41
|
}
|
|
42
|
+
return mapping.tsType;
|
|
39
43
|
}
|
|
40
44
|
function inputType(solidityType, components) {
|
|
41
45
|
return typeConversion(INPUT_TYPE_MAPPING, solidityType, components);
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
function outputType(solidityType, components) {
|
|
48
|
+
return typeConversion(TYPE_MAPPING, solidityType, components);
|
|
49
|
+
}
|
|
50
|
+
function methodParamName(input, index) {
|
|
51
|
+
return input.name || `param${index}`;
|
|
52
|
+
}
|
|
53
|
+
function getComponents(parameter) {
|
|
54
|
+
return 'components' in parameter ? parameter.components : undefined;
|
|
55
|
+
}
|
|
56
|
+
function renderMethodInput(inputs, trailingComma = false) {
|
|
57
|
+
if (!inputs.length) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
const rendered = inputs
|
|
61
|
+
.map((input, index) => `${methodParamName(input, index)}: ${inputType(input.type, getComponents(input))}`)
|
|
62
|
+
.join(', ');
|
|
63
|
+
return trailingComma ? `${rendered}, ` : rendered;
|
|
64
|
+
}
|
|
65
|
+
function renderParams(inputs) {
|
|
66
|
+
return inputs.map((input, index) => methodParamName(input, index)).join(', ');
|
|
67
|
+
}
|
|
68
|
+
function renderMethodOutput(method) {
|
|
69
|
+
if (!method.outputs.length) {
|
|
70
|
+
return 'void';
|
|
71
|
+
}
|
|
72
|
+
if (method.singleReturnValue) {
|
|
73
|
+
const single = method.outputs[0];
|
|
74
|
+
return outputType(single.type, getComponents(single));
|
|
75
|
+
}
|
|
76
|
+
return `[${method.outputs
|
|
77
|
+
.map((output) => outputType(output.type, getComponents(output)))
|
|
78
|
+
.join(', ')}]`;
|
|
79
|
+
}
|
|
80
|
+
function createTemplateHelpers() {
|
|
81
|
+
return {
|
|
82
|
+
renderType: outputType,
|
|
83
|
+
renderMethodInput,
|
|
84
|
+
renderMethodOutput,
|
|
85
|
+
renderParams,
|
|
86
|
+
};
|
|
46
87
|
}
|
|
47
|
-
exports.outputType = outputType;
|
|
48
88
|
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;AA0DA,8BAKC;AAED,gCAKC;AAYD,8CAgBC;AAED,oCAEC;AAED,gDAaC;AAED,sDAOC;AAtHD,MAAM,YAAY,GAAc;IAC9B,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE;IACvC,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE;IAC/C,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE;IACtC,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE;IACzC,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE;CACjD,CAAA;AAED,MAAM,kBAAkB,GAAc;IACpC,EAAE,KAAK,EAAE,8BAA8B,EAAE,MAAM,EAAE,QAAQ,EAAE;IAC3D,GAAG,YAAY;CAChB,CAAA;AAED,MAAM,YAAY,GAAG,SAAS,CAAA;AAE9B,SAAS,OAAO,CAAC,YAAoB;IACnC,OAAO,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;AACxC,CAAC;AAED,SAAS,OAAO,CAAC,YAAoB;IACnC,OAAO,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;AACvC,CAAC;AAED,SAAS,cAAc,CACrB,KAAgB,EAChB,YAAoB,EACpB,UAAoC;IAEpC,IAAI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C,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;SAC/D,IAAI,CAAC,IAAI,CAAC,GAAG,CAAA;AAClB,CAAC;AAED,SAAgB,qBAAqB;IACnC,OAAO;QACL,UAAU,EAAE,UAAU;QACtB,iBAAiB;QACjB,kBAAkB;QAClB,YAAY;KACb,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { AbiWrapper } from './abiWrapper.js';
|
|
2
|
-
export { BaseContract, TxOptions, CtorParams, isCtorAccountParamPure, } from './baseContract.js';
|
|
2
|
+
export { BaseContract, BaseContractViem, BaseContractEthers, TxOptions, CtorParams, CtorParamsViem, CtorParamsEthers, isCtorAccountParamPure, isCtorAccountParamViem, isCtorAccountParamEthers, } from './baseContract.js';
|
|
3
|
+
export type { WrapperBackend } from './context.js';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCtorAccountParamPure = exports.BaseContract = exports.AbiWrapper = void 0;
|
|
3
|
+
exports.isCtorAccountParamEthers = exports.isCtorAccountParamViem = exports.isCtorAccountParamPure = exports.BaseContractEthers = exports.BaseContractViem = exports.BaseContract = exports.AbiWrapper = void 0;
|
|
4
4
|
var abiWrapper_js_1 = require("./abiWrapper.js");
|
|
5
5
|
Object.defineProperty(exports, "AbiWrapper", { enumerable: true, get: function () { return abiWrapper_js_1.AbiWrapper; } });
|
|
6
6
|
var baseContract_js_1 = require("./baseContract.js");
|
|
7
7
|
Object.defineProperty(exports, "BaseContract", { enumerable: true, get: function () { return baseContract_js_1.BaseContract; } });
|
|
8
|
+
Object.defineProperty(exports, "BaseContractViem", { enumerable: true, get: function () { return baseContract_js_1.BaseContractViem; } });
|
|
9
|
+
Object.defineProperty(exports, "BaseContractEthers", { enumerable: true, get: function () { return baseContract_js_1.BaseContractEthers; } });
|
|
8
10
|
Object.defineProperty(exports, "isCtorAccountParamPure", { enumerable: true, get: function () { return baseContract_js_1.isCtorAccountParamPure; } });
|
|
11
|
+
Object.defineProperty(exports, "isCtorAccountParamViem", { enumerable: true, get: function () { return baseContract_js_1.isCtorAccountParamViem; } });
|
|
12
|
+
Object.defineProperty(exports, "isCtorAccountParamEthers", { enumerable: true, get: function () { return baseContract_js_1.isCtorAccountParamEthers; } });
|
|
9
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAAnC,2GAAA,UAAU,OAAA;AACnB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAAnC,2GAAA,UAAU,OAAA;AACnB,qDAW0B;AAVxB,+GAAA,YAAY,OAAA;AACZ,mHAAA,gBAAgB,OAAA;AAChB,qHAAA,kBAAkB,OAAA;AAKlB,yHAAA,sBAAsB,OAAA;AACtB,yHAAA,sBAAsB,OAAA;AACtB,2HAAA,wBAAwB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,67 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@riaskov/iohtee-abi-wrapper",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Generate TypeScript wrapper class for Solidity smart contract ABI",
|
|
5
|
-
"license": "Apache-2.0",
|
|
6
|
-
"author": "Machinomy Team <hello@machinomy.com>",
|
|
7
|
-
"contributors": [
|
|
8
|
-
{
|
|
9
|
-
"name": "Andrei Riaskov",
|
|
10
|
-
"email": "code@riaskov.com"
|
|
11
|
-
}
|
|
12
|
-
],
|
|
13
|
-
"keywords": [
|
|
14
|
-
"solidity",
|
|
15
|
-
"ethereum",
|
|
16
|
-
"evm",
|
|
17
|
-
"polygon",
|
|
18
|
-
"binance",
|
|
19
|
-
"abi",
|
|
20
|
-
"hardhat",
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@riaskov/iohtee-abi-wrapper",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Generate TypeScript wrapper class for Solidity smart contract ABI",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Machinomy Team <hello@machinomy.com>",
|
|
7
|
+
"contributors": [
|
|
8
|
+
{
|
|
9
|
+
"name": "Andrei Riaskov",
|
|
10
|
+
"email": "code@riaskov.com"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"solidity",
|
|
15
|
+
"ethereum",
|
|
16
|
+
"evm",
|
|
17
|
+
"polygon",
|
|
18
|
+
"binance",
|
|
19
|
+
"abi",
|
|
20
|
+
"hardhat",
|
|
21
|
+
"viem",
|
|
22
|
+
"ethers",
|
|
23
|
+
"wrapper"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://github.com/ARyaskov/IohTee/tree/main/packages/abi-wrapper#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/ARyaskov/IohTee/issues"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/ARyaskov/iohtee.git"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=22"
|
|
35
|
+
},
|
|
36
|
+
"main": "dist/index.js",
|
|
37
|
+
"types": "dist/index.d.ts",
|
|
38
|
+
"bin": "dist/bin/iohtee-abi-wrapper.js",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist/",
|
|
41
|
+
"templates/"
|
|
42
|
+
],
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"esbuild": "^0.25.9",
|
|
45
|
+
"eta": "^3.5.0",
|
|
46
|
+
"ethers": "^6.15.0",
|
|
47
|
+
"glob": "^11.0.3",
|
|
48
|
+
"typedoc": "^0.28.14",
|
|
49
|
+
"viem": "^2.45.0",
|
|
50
|
+
"yargs": "^17.7.2"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^22.13.4",
|
|
54
|
+
"@types/yargs": "^17.0.33",
|
|
55
|
+
"docsify-cli": "^4.4.4",
|
|
56
|
+
"prettier": "^3.6.2",
|
|
57
|
+
"rimraf": "^6.0.1",
|
|
58
|
+
"tsx": "^4.20.3",
|
|
59
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
60
|
+
"typescript": "6.0.0-beta"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"demo": "tsx src/bin/iohtee-abi-wrapper.ts ./abi/* -m -d ./docs -o ../contracts/src/abi-wrapper/",
|
|
64
|
+
"build": "pnpm run format && pnpm run clean && tsc --project tsconfig.json",
|
|
65
|
+
"clean": "rimraf dist",
|
|
66
|
+
"test": "node --import tsx --test",
|
|
67
|
+
"lint": "tsc --project tsconfig.json --noEmit",
|
|
68
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
69
|
+
"postinstall": "exit 0",
|
|
70
|
+
"docs:serve": "docsify serve docs"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Interface, TransactionReceipt, type InterfaceAbi } from 'ethers'
|
|
2
|
+
import {
|
|
3
|
+
BaseContractEthers,
|
|
4
|
+
TxOptions,
|
|
5
|
+
CtorParamsEthers as CtorParams,
|
|
6
|
+
isCtorAccountParamPure,
|
|
7
|
+
} from '@riaskov/iohtee-abi-wrapper'
|
|
8
|
+
export { isCtorAccountParamPure, CtorParams, TxOptions }
|
|
9
|
+
|
|
10
|
+
export interface <%= it.contractName %>Event {
|
|
11
|
+
eventName: string
|
|
12
|
+
args: unknown
|
|
13
|
+
log: unknown
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
<% it.events.forEach((event) => { %>
|
|
17
|
+
export interface <%= event.name %> {
|
|
18
|
+
<% if (event.inputs.length) { %>
|
|
19
|
+
args: {
|
|
20
|
+
<% event.inputs.forEach((input, index) => { %>
|
|
21
|
+
<%= input.name || `arg${index}` %>: <%= it.helpers.renderType(input.type, input.components) %>
|
|
22
|
+
<% }) %>
|
|
23
|
+
}
|
|
24
|
+
<% } %>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
<% }) %>
|
|
28
|
+
export enum <%= it.contractName %>EventName {
|
|
29
|
+
<% it.events.forEach((event, index) => { %>
|
|
30
|
+
<%= event.name %> = "<%= event.name %>"<%= index < it.events.length - 1 ? ',' : '' %>
|
|
31
|
+
<% }) %>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const abi = JSON.parse(`<%= it.abi %>`) as InterfaceAbi
|
|
35
|
+
|
|
36
|
+
export class <%= it.contractName %>Contract extends BaseContractEthers {
|
|
37
|
+
/// GETTERS
|
|
38
|
+
<% it.getters.forEach((method) => { %>
|
|
39
|
+
async <%= method.name %><%= method.namePostfix ?? '' %>(<%= it.helpers.renderMethodInput(method.inputs) %>): Promise<<%= it.helpers.renderMethodOutput(method) %>> {
|
|
40
|
+
return (await this.contract().getFunction("<%= method.name %>")(
|
|
41
|
+
<%= it.helpers.renderParams(method.inputs) %>
|
|
42
|
+
)) as <%= it.helpers.renderMethodOutput(method) %>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
<% }) %>
|
|
46
|
+
/// SETTERS
|
|
47
|
+
<% it.functions.forEach((method) => { %>
|
|
48
|
+
async <%= method.name %><%= method.namePostfix ?? '' %>(<%= it.helpers.renderMethodInput(method.inputs, true) %>options?: TxOptions): Promise<TransactionReceipt> {
|
|
49
|
+
const fn = this.contract().getFunction("<%= method.name %>")
|
|
50
|
+
const args = [<%= it.helpers.renderParams(method.inputs) %>] as const
|
|
51
|
+
|
|
52
|
+
const tx = await (options?.value !== undefined
|
|
53
|
+
? fn(...args, { value: options.value })
|
|
54
|
+
: fn(...args))
|
|
55
|
+
|
|
56
|
+
return (await tx.wait(3)) as TransactionReceipt
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
<% }) %>
|
|
60
|
+
/// EVENTS
|
|
61
|
+
<% it.events.forEach((event) => { %>
|
|
62
|
+
is<%= event.name %>Event(eventName: string): boolean {
|
|
63
|
+
return eventName === "<%= event.name %>"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
<% }) %>
|
|
67
|
+
static parseEvents(receipt: TransactionReceipt): <%= it.contractName %>Event[] {
|
|
68
|
+
const iface = new Interface(abi)
|
|
69
|
+
const result: <%= it.contractName %>Event[] = []
|
|
70
|
+
|
|
71
|
+
for (const log of receipt.logs) {
|
|
72
|
+
try {
|
|
73
|
+
const parsed = iface.parseLog(log)
|
|
74
|
+
if (!parsed) continue
|
|
75
|
+
result.push({
|
|
76
|
+
eventName: parsed.name,
|
|
77
|
+
args: parsed.args,
|
|
78
|
+
log,
|
|
79
|
+
})
|
|
80
|
+
} catch {
|
|
81
|
+
// Ignore unrelated logs.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return result
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static hasEvent(receipt: TransactionReceipt, eventName: <%= it.contractName %>EventName): boolean {
|
|
89
|
+
return this.parseEvents(receipt).some((event) => event.eventName === eventName)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static extractEventFromReceipt<T>(receipt: TransactionReceipt, eventName: <%= it.contractName %>EventName): T {
|
|
93
|
+
return this.parseEvents(receipt).find((event) => event.eventName === eventName) as T
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
constructor(deployedContractAddress: `0x${string}`, params: CtorParams) {
|
|
97
|
+
super(deployedContractAddress, params, abi)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TransactionReceipt,
|
|
3
|
+
parseEventLogs,
|
|
4
|
+
ParseEventLogsReturnType,
|
|
5
|
+
} from 'viem'
|
|
6
|
+
import {
|
|
7
|
+
BaseContractViem,
|
|
8
|
+
TxOptions,
|
|
9
|
+
CtorParamsViem as CtorParams,
|
|
10
|
+
isCtorAccountParamPure,
|
|
11
|
+
} from '@riaskov/iohtee-abi-wrapper'
|
|
12
|
+
export { isCtorAccountParamPure, CtorParams, TxOptions }
|
|
13
|
+
|
|
14
|
+
export interface <%= it.contractName %>Event {
|
|
15
|
+
eventName: string
|
|
16
|
+
args: any
|
|
17
|
+
address: `0x${string}`
|
|
18
|
+
blockHash: `0x${string}`
|
|
19
|
+
blockNumber: bigint
|
|
20
|
+
data: `0x${string}`
|
|
21
|
+
logIndex: number
|
|
22
|
+
removed: boolean
|
|
23
|
+
topics: [] | [`0x${string}`, ...`0x${string}`[]]
|
|
24
|
+
transactionHash: `0x${string}`
|
|
25
|
+
transactionIndex: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
<% it.events.forEach((event) => { %>
|
|
29
|
+
export interface <%= event.name %> {
|
|
30
|
+
<% if (event.inputs.length) { %>
|
|
31
|
+
args: {
|
|
32
|
+
<% event.inputs.forEach((input, index) => { %>
|
|
33
|
+
<%= input.name || `arg${index}` %>: <%= it.helpers.renderType(input.type, input.components) %>
|
|
34
|
+
<% }) %>
|
|
35
|
+
}
|
|
36
|
+
<% } %>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
<% }) %>
|
|
40
|
+
export enum <%= it.contractName %>EventName {
|
|
41
|
+
<% it.events.forEach((event, index) => { %>
|
|
42
|
+
<%= event.name %> = "<%= event.name %>"<%= index < it.events.length - 1 ? ',' : '' %>
|
|
43
|
+
<% }) %>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const abi = JSON.parse(`<%= it.abi %>`)
|
|
47
|
+
|
|
48
|
+
export class <%= it.contractName %>Contract extends BaseContractViem {
|
|
49
|
+
/// GETTERS
|
|
50
|
+
<% it.getters.forEach((method) => { %>
|
|
51
|
+
async <%= method.name %><%= method.namePostfix ?? '' %>(<%= it.helpers.renderMethodInput(method.inputs) %>): Promise<<%= it.helpers.renderMethodOutput(method) %>> {
|
|
52
|
+
return (await this.publicClient().readContract({
|
|
53
|
+
address: this.address(),
|
|
54
|
+
abi: this.abi(),
|
|
55
|
+
functionName: "<%= method.name %>",
|
|
56
|
+
args: [<%= it.helpers.renderParams(method.inputs) %>],
|
|
57
|
+
})) as never as <%= it.helpers.renderMethodOutput(method) %>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
<% }) %>
|
|
61
|
+
/// SETTERS
|
|
62
|
+
<% it.functions.forEach((method) => { %>
|
|
63
|
+
async <%= method.name %><%= method.namePostfix ?? '' %>(<%= it.helpers.renderMethodInput(method.inputs, true) %>options?: TxOptions): Promise<TransactionReceipt>{
|
|
64
|
+
const { request } = await this.publicClient().simulateContract({
|
|
65
|
+
chain: this.walletClient().chain,
|
|
66
|
+
address: this.address(),
|
|
67
|
+
abi: this.abi(),
|
|
68
|
+
functionName: "<%= method.name %>",
|
|
69
|
+
args: [<%= it.helpers.renderParams(method.inputs) %>],
|
|
70
|
+
account: this.walletClient().account,
|
|
71
|
+
value: options?.value,
|
|
72
|
+
})
|
|
73
|
+
const txId = await this.walletClient().writeContract(request)
|
|
74
|
+
|
|
75
|
+
return await this.publicClient().waitForTransactionReceipt({
|
|
76
|
+
hash: txId,
|
|
77
|
+
confirmations: 3,
|
|
78
|
+
timeout: 45_000,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
<% }) %>
|
|
83
|
+
/// EVENTS
|
|
84
|
+
<% it.events.forEach((event) => { %>
|
|
85
|
+
is<%= event.name %>Event(eventName: string): boolean {
|
|
86
|
+
return eventName === "<%= event.name %>"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
<% }) %>
|
|
90
|
+
static parseLogs(receipt: TransactionReceipt): ParseEventLogsReturnType {
|
|
91
|
+
return parseEventLogs({
|
|
92
|
+
abi: abi as any,
|
|
93
|
+
logs: receipt.logs,
|
|
94
|
+
}) as any
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static hasEvent(receipt: TransactionReceipt, eventName: <%= it.contractName %>EventName): boolean {
|
|
98
|
+
return parseEventLogs({ abi: abi, logs: receipt.logs }).some((log: any) => log.eventName === eventName)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static extractEventFromReceipt<T>(receipt: TransactionReceipt, eventName: <%= it.contractName %>EventName): T {
|
|
102
|
+
return parseEventLogs({ abi: abi, logs: receipt.logs }).find((log: any) => log.eventName === eventName) as T
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static parseEvents(receipt: TransactionReceipt): <%= it.contractName %>Event[] {
|
|
106
|
+
return parseEventLogs({ abi: abi, logs: receipt.logs }).map((log: any) => ({
|
|
107
|
+
eventName: log.eventName,
|
|
108
|
+
args: log.args,
|
|
109
|
+
address: log.address,
|
|
110
|
+
blockHash: log.blockHash,
|
|
111
|
+
blockNumber: log.blockNumber,
|
|
112
|
+
data: log.data,
|
|
113
|
+
logIndex: log.logIndex,
|
|
114
|
+
removed: log.removed,
|
|
115
|
+
topics: log.topics,
|
|
116
|
+
transactionHash: log.transactionHash,
|
|
117
|
+
transactionIndex: log.transactionIndex,
|
|
118
|
+
}))
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
constructor(deployedContractAddress: `0x${string}`, params: CtorParams) {
|
|
122
|
+
super(deployedContractAddress, params, abi)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{{this.name}} = "{{this.name}}"{{#unless @last}}, {{/unless}}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
async {{this.name}}{{this.namePostfix}}({{> method_input inputs=inputs trailingComma=true}}options?: TxOptions): Promise<TransactionReceipt>{
|
|
2
|
-
const { request } = await this.publicClient().simulateContract({
|
|
3
|
-
chain: this.walletClient().chain,
|
|
4
|
-
address: this.address(),
|
|
5
|
-
abi: this.abi(),
|
|
6
|
-
functionName: "{{this.name}}",
|
|
7
|
-
args: [
|
|
8
|
-
{{> params inputs=inputs}}
|
|
9
|
-
],
|
|
10
|
-
account: this.walletClient().account,
|
|
11
|
-
value: options?.value,
|
|
12
|
-
})
|
|
13
|
-
const txId = await this.walletClient().writeContract(request)
|
|
14
|
-
|
|
15
|
-
return await this.publicClient().waitForTransactionReceipt({
|
|
16
|
-
hash: txId,
|
|
17
|
-
confirmations: 3,
|
|
18
|
-
timeout: 45_000,
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
async {{this.name}}{{this.namePostfix}}({{> method_input inputs=inputs}}): Promise<{{> method_output outputs=outputs}}> {
|
|
2
|
-
return (await this.publicClient().readContract({
|
|
3
|
-
address: this.address(),
|
|
4
|
-
abi: this.abi(),
|
|
5
|
-
functionName: "{{this.name}}",
|
|
6
|
-
args: [
|
|
7
|
-
{{> params inputs=inputs}}
|
|
8
|
-
],
|
|
9
|
-
})) as never as {{> method_output outputs=outputs}}
|
|
10
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{{~#if outputs~}}
|
|
2
|
-
{{~#singleReturnValue~}}
|
|
3
|
-
{{#outputType outputs.0.type}}{{/outputType}}
|
|
4
|
-
{{~/singleReturnValue~}}
|
|
5
|
-
{{~^singleReturnValue~}}
|
|
6
|
-
[{{#each outputs}}{{#outputType type}}{{/outputType}}{{#unless @last}}, {{/unless}}{{/each}}]
|
|
7
|
-
{{~/singleReturnValue~}}
|
|
8
|
-
{{~else~}}
|
|
9
|
-
void
|
|
10
|
-
{{~/if~}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{{#each inputs}}{{name}}{{#unless @last}}, {{/unless}}{{/each}}
|