@riaskov/iohtee-abi-wrapper 2.0.9 → 3.0.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/dist/helpers.js CHANGED
@@ -1,48 +1,88 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.outputType = exports.inputType = void 0;
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: '^string$', tsType: 'string' },
6
- { regex: '^address$', tsType: '`0x${string}`' },
7
- { regex: '^bool$', tsType: 'boolean' },
8
- { regex: '^u?int\\d*$', tsType: 'bigint' },
9
- { regex: '^bytes\\d*$', tsType: '`0x${string}`' },
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: '^u?int(8|16|32|64|128|256)?$', tsType: 'bigint' },
13
- ].concat(TYPE_MAPPING);
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 !!solidityType.match(ARRAY_BRACES);
22
+ return ARRAY_BRACES.test(solidityType);
17
23
  }
18
24
  function isTuple(solidityType) {
19
- return !!solidityType.match('tuple');
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
- else if (isTuple(solidityType) && components) {
28
- return `[${components.map((e) => inputType(e.type)).join(' ,')}]`;
33
+ if (isTuple(solidityType) && components?.length) {
34
+ return `[${components
35
+ .map((component) => typeConversion(types, component.type, getComponents(component)))
36
+ .join(', ')}]`;
29
37
  }
30
- else {
31
- let mapping = types.find((mapping) => !!solidityType.match(mapping.regex));
32
- if (mapping) {
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
- exports.inputType = inputType;
44
- function outputType(solidityType) {
45
- return typeConversion(TYPE_MAPPING, solidityType);
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
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAKA,MAAM,YAAY,GAAG;IACnB,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,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE;IAC1C,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE;CAClD,CAAA;AAED,MAAM,kBAAkB,GAAG;IACzB,EAAE,KAAK,EAAE,8BAA8B,EAAE,MAAM,EAAE,QAAQ,EAAE;CAC5D,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;AAEtB,MAAM,YAAY,GAAG,SAAS,CAAA;AAE9B,SAAS,OAAO,CAAC,YAAoB;IACnC,OAAO,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;AAC3C,CAAC;AAED,SAAS,OAAO,CAAC,YAAoB;IACnC,OAAO,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;AACtC,CAAC;AAED,SAAS,cAAc,CACrB,KAAqB,EACrB,YAAoB,EACpB,UAAuB;IAEvB,IAAI,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QAC1B,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;QAC/D,MAAM,IAAI,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OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC/E,CAAC;AAED,SAAgB,kBAAkB,CAAC,MAAiB;IAClD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAA;IACf,CAAC;IAED,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAE,CAAA;QACjC,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;IACvD,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,OAAO;SACtB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,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,qDAK0B;AAJxB,+GAAA,YAAY,OAAA;AAGZ,yHAAA,sBAAsB,OAAA"}
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,70 +1,71 @@
1
- {
2
- "name": "@riaskov/iohtee-abi-wrapper",
3
- "version": "2.0.9",
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
- "wrapper"
23
- ],
24
- "homepage": "https://github.com/ARyaskov/IohTee/tree/main/packages/abi-wrapper#readme",
25
- "bugs": {
26
- "url": "https://github.com/ARyaskov/iohtee/issues"
27
- },
28
- "repository": {
29
- "type": "git",
30
- "url": "https://github.com/ARyaskov/iohtee.git"
31
- },
32
- "engines": {
33
- "node": ">=20"
34
- },
35
- "main": "dist/index.js",
36
- "types": "dist/index.d.ts",
37
- "bin": "dist/bin/iohtee-abi-wrapper.js",
38
- "files": [
39
- "dist/",
40
- "templates/"
41
- ],
42
- "scripts": {
43
- "demo": "tsx src/bin/iohtee-abi-wrapper.ts ./abi/* -m -d ./docs -o ../contracts/src/abi-wrapper/",
44
- "build": "yarn format && yarn clean && tsc --project tsconfig.json",
45
- "clean": "rimraf dist",
46
- "test": "exit 0",
47
- "coverage": "exit 0",
48
- "format": "npx prettier --write \"src/**/*.ts\"",
49
- "postinstall": "exit 0"
50
- },
51
- "dependencies": {
52
- "chalk": "^5.3.0",
53
- "console.table": "^0.10.0",
54
- "esbuild": "^0.21.5",
55
- "fs-extra": "^11.2.0",
56
- "glob": "^10.4.2",
57
- "handlebars": "^4.7.8",
58
- "mkdirp": "^3.0.1",
59
- "viem": "*",
60
- "yargs": "^17.7.2"
61
- },
62
- "devDependencies": {
63
- "@types/yargs": "^17.0.32",
64
- "rimraf": "*",
65
- "ts-node": "^10.9.2",
66
- "typedoc": "^0.26.2",
67
- "typedoc-plugin-markdown": "^4.1.0",
68
- "typescript": "*"
69
- }
70
- }
1
+ {
2
+ "name": "@riaskov/iohtee-abi-wrapper",
3
+ "version": "3.0.1",
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
+ "prettier": "^3.6.2",
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
+ "rimraf": "^6.0.1",
57
+ "tsx": "^4.20.3",
58
+ "typedoc-plugin-markdown": "^4.9.0",
59
+ "typescript": "6.0.0-beta"
60
+ },
61
+ "scripts": {
62
+ "demo": "tsx src/bin/iohtee-abi-wrapper.ts ./abi/* -m -d ./docs -o ../contracts/src/abi-wrapper/",
63
+ "build": "pnpm run format && pnpm run clean && tsc --project tsconfig.json",
64
+ "clean": "rimraf dist",
65
+ "test": "node --import tsx --test",
66
+ "lint": "tsc --project tsconfig.json --noEmit",
67
+ "format": "prettier --write \"src/**/*.ts\"",
68
+ "postinstall": "exit 0",
69
+ "docs:serve": "docsify serve docs"
70
+ }
71
+ }
@@ -0,0 +1,107 @@
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, eventIndex) => { -%>
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
+ <% if (eventIndex < it.events.length - 1) { -%>
27
+
28
+ <% } -%>
29
+ <% }) -%>
30
+ export enum <%= it.contractName %>EventName {
31
+ <% it.events.forEach((event, index) => { -%>
32
+ <%= event.name %> = '<%= event.name %>'<%= index < it.events.length - 1 ? ',' : '' %>
33
+ <% }) -%>
34
+ }
35
+
36
+ const abi = JSON.parse(
37
+ `<%= it.abi %>`,
38
+ ) as InterfaceAbi
39
+
40
+ export class <%= it.contractName %>Contract extends BaseContractEthers {
41
+ /// GETTERS
42
+ <% it.getters.forEach((method) => { %>
43
+ async <%= method.name %><%= method.namePostfix ?? '' %>(<%= it.helpers.renderMethodInput(method.inputs) %>): Promise<<%= it.helpers.renderMethodOutput(method) %>> {
44
+ <% if (method.inputs.length) { %>
45
+ return (await this.contract().getFunction('<%= method.name %>')(
46
+ <%= it.helpers.renderParams(method.inputs) %>
47
+ )) as <%= it.helpers.renderMethodOutput(method) %>
48
+ <% } else { %>
49
+ return (await this.contract().getFunction('<%= method.name %>')()) as <%= it.helpers.renderMethodOutput(method) %>
50
+ <% } %>
51
+ }
52
+
53
+ <% }) %>
54
+ /// SETTERS
55
+ <% it.functions.forEach((method) => { %>
56
+ async <%= method.name %><%= method.namePostfix ?? '' %>(<%= it.helpers.renderMethodInput(method.inputs, true) %>options?: TxOptions): Promise<TransactionReceipt> {
57
+ const fn = this.contract().getFunction('<%= method.name %>')
58
+ const args = [<%= it.helpers.renderParams(method.inputs) %>] as const
59
+
60
+ const tx = await (options?.value !== undefined
61
+ ? fn(...args, { value: options.value })
62
+ : fn(...args))
63
+
64
+ return (await tx.wait(3)) as TransactionReceipt
65
+ }
66
+
67
+ <% }) %>
68
+ /// EVENTS
69
+ <% it.events.forEach((event) => { %>
70
+ is<%= event.name %>Event(eventName: string): boolean {
71
+ return eventName === '<%= event.name %>'
72
+ }
73
+
74
+ <% }) %>
75
+ static parseEvents(receipt: TransactionReceipt): <%= it.contractName %>Event[] {
76
+ const iface = new Interface(abi)
77
+ const result: <%= it.contractName %>Event[] = []
78
+
79
+ for (const log of receipt.logs) {
80
+ try {
81
+ const parsed = iface.parseLog(log)
82
+ if (!parsed) continue
83
+ result.push({
84
+ eventName: parsed.name,
85
+ args: parsed.args,
86
+ log,
87
+ })
88
+ } catch {
89
+ // Ignore unrelated logs.
90
+ }
91
+ }
92
+
93
+ return result
94
+ }
95
+
96
+ static hasEvent(receipt: TransactionReceipt, eventName: <%= it.contractName %>EventName): boolean {
97
+ return this.parseEvents(receipt).some((event) => event.eventName === eventName)
98
+ }
99
+
100
+ static extractEventFromReceipt<T>(receipt: TransactionReceipt, eventName: <%= it.contractName %>EventName): T {
101
+ return this.parseEvents(receipt).find((event) => event.eventName === eventName) as T
102
+ }
103
+
104
+ constructor(deployedContractAddress: `0x${string}`, params: CtorParams) {
105
+ super(deployedContractAddress, params, abi)
106
+ }
107
+ }
@@ -0,0 +1,128 @@
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: unknown
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, eventIndex) => { -%>
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
+ <% if (eventIndex < it.events.length - 1) { -%>
39
+
40
+ <% } -%>
41
+ <% }) -%>
42
+ export enum <%= it.contractName %>EventName {
43
+ <% it.events.forEach((event, index) => { -%>
44
+ <%= event.name %> = '<%= event.name %>'<%= index < it.events.length - 1 ? ',' : '' %>
45
+ <% }) -%>
46
+ }
47
+
48
+ const abi = JSON.parse(
49
+ `<%= it.abi %>`,
50
+ )
51
+
52
+ export class <%= it.contractName %>Contract extends BaseContractViem {
53
+ /// GETTERS
54
+ <% it.getters.forEach((method) => { %>
55
+ async <%= method.name %><%= method.namePostfix ?? '' %>(<%= it.helpers.renderMethodInput(method.inputs) %>): Promise<<%= it.helpers.renderMethodOutput(method) %>> {
56
+ return (await this.publicClient().readContract({
57
+ address: this.address(),
58
+ abi: this.abi(),
59
+ functionName: '<%= method.name %>',
60
+ args: [<%= it.helpers.renderParams(method.inputs) %>],
61
+ })) as never as <%= it.helpers.renderMethodOutput(method) %>
62
+ }
63
+
64
+ <% }) %>
65
+ /// SETTERS
66
+ <% it.functions.forEach((method) => { %>
67
+ async <%= method.name %><%= method.namePostfix ?? '' %>(<%= it.helpers.renderMethodInput(method.inputs, true) %>options?: TxOptions): Promise<TransactionReceipt> {
68
+ const { request } = await this.publicClient().simulateContract({
69
+ chain: this.walletClient().chain,
70
+ address: this.address(),
71
+ abi: this.abi(),
72
+ functionName: '<%= method.name %>',
73
+ args: [<%= it.helpers.renderParams(method.inputs) %>],
74
+ account: this.walletClient().account,
75
+ value: options?.value,
76
+ })
77
+ const txId = await this.walletClient().writeContract(request)
78
+
79
+ return await this.publicClient().waitForTransactionReceipt({
80
+ hash: txId,
81
+ confirmations: 3,
82
+ timeout: 45_000,
83
+ })
84
+ }
85
+
86
+ <% }) %>
87
+ /// EVENTS
88
+ <% it.events.forEach((event) => { %>
89
+ is<%= event.name %>Event(eventName: string): boolean {
90
+ return eventName === '<%= event.name %>'
91
+ }
92
+
93
+ <% }) %>
94
+ static parseLogs(receipt: TransactionReceipt): ParseEventLogsReturnType {
95
+ return parseEventLogs({
96
+ abi: abi as any,
97
+ logs: receipt.logs,
98
+ }) as ParseEventLogsReturnType
99
+ }
100
+
101
+ static hasEvent(receipt: TransactionReceipt, eventName: <%= it.contractName %>EventName): boolean {
102
+ return this.parseLogs(receipt).some((log: any) => log.eventName === eventName)
103
+ }
104
+
105
+ static extractEventFromReceipt<T>(receipt: TransactionReceipt, eventName: <%= it.contractName %>EventName): T {
106
+ return this.parseLogs(receipt).find((log: any) => log.eventName === eventName) as T
107
+ }
108
+
109
+ static parseEvents(receipt: TransactionReceipt): <%= it.contractName %>Event[] {
110
+ return this.parseLogs(receipt).map((log: any) => ({
111
+ eventName: log.eventName,
112
+ args: log.args,
113
+ address: log.address,
114
+ blockHash: log.blockHash,
115
+ blockNumber: log.blockNumber,
116
+ data: log.data,
117
+ logIndex: log.logIndex,
118
+ removed: log.removed,
119
+ topics: log.topics,
120
+ transactionHash: log.transactionHash,
121
+ transactionIndex: log.transactionIndex,
122
+ }))
123
+ }
124
+
125
+ constructor(deployedContractAddress: `0x${string}`, params: CtorParams) {
126
+ super(deployedContractAddress, params, abi)
127
+ }
128
+ }
@@ -1 +0,0 @@
1
- {{this.name}} = "{{this.name}}"{{#unless @last}}, {{/unless}}
@@ -1,10 +0,0 @@
1
- export interface {{this.name}} {
2
- {{#if inputs}}
3
- args: {
4
- {{#each inputs}}
5
- {{name}}: {{#inputType type}}{{/inputType}}
6
- {{/each}}
7
- }
8
- {{/if}}
9
- }
10
-
@@ -1,3 +0,0 @@
1
- is{{this.name}}Event (something: AbiEvent): boolean {
2
- return something.name === "{{this.name}}"
3
- }
@@ -1,3 +0,0 @@
1
- {{this.name}}: {
2
- ({{#if inputs}}filter: { {{#each inputs}}{{name}}?: {{#inputType type}}{{/inputType}}{{#unless @last}}, {{/unless}}{{/each}} }, {{/if}}options?: any): any
3
- }
@@ -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,4 +0,0 @@
1
- {{~#if inputs~}}
2
- {{~#each inputs~}}{{name}}: {{#inputType type components}} {{/inputType}}{{#unless @last}}, {{/unless}}{{~/each~}}
3
- {{~#if trailingComma~}}, {{/if}}
4
- {{~/if~}}
@@ -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}}