@riaskov/iohtee-abi-wrapper 2.0.7 → 2.0.8
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/README.md +77 -3
- package/dist/abiWrapper.d.ts +4 -1
- package/dist/abiWrapper.js +68 -12
- package/dist/abiWrapper.js.map +1 -1
- package/dist/baseContract.d.ts +33 -0
- package/dist/baseContract.js +102 -0
- package/dist/baseContract.js.map +1 -0
- package/dist/bin/iohtee-abi-wrapper.js +15 -5
- package/dist/bin/iohtee-abi-wrapper.js.map +1 -1
- package/dist/context.js +2 -1
- package/dist/context.js.map +1 -1
- package/dist/contractTemplate.js +45 -16
- package/dist/contractTemplate.js.map +1 -1
- package/dist/helpers.js +7 -2
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/package.json +17 -5
- package/templates/contract.mustache +4 -121
package/README.md
CHANGED
|
@@ -13,15 +13,89 @@ It takes raw json artifact file and render ready-to-use TS-wrapper. Use viem v2
|
|
|
13
13
|
$ npm install @riaskov/iohtee-abi-wrapper --global --no-save
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## Use
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
$ iohtee-abi-wrapper -o ./
|
|
19
|
+
$ iohtee-abi-wrapper -o ./generated ./abi/*
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
Now you can import generated contract's wrapper from `./generated` folder like
|
|
23
|
+
```typescript
|
|
24
|
+
import {
|
|
25
|
+
CtorParams,
|
|
26
|
+
XXXContract,
|
|
27
|
+
} from './generated/XXXContract'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Recipes
|
|
31
|
+
|
|
32
|
+
1. Generate just regular TS wrappers for ABI files located in `./abi/*` and put them into `./generated`
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
$ iohtee-abi-wrapper -o ./generated ./abi/*
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Generate just regular TS wrappers for ABI files located in `./abi/*` AND minified js version of wrapper and put them into `./generated`
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
$ iohtee-abi-wrapper -m -o ./generated ./abi/*
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. Generate just regular TS wrappers for ABI files located in `./abi/*` AND minified js version of wrapper and put them into `./generated` AND create a nice HTML-docs for wrapper
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
$ iohtee-abi-wrapper -m -d ./docs -o ./generated ./abi/*
|
|
48
|
+
```
|
|
49
|
+
**ATTENTION!** All files in specified `docs` dir will be removed each time the command will be invoked!
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Generated TS-wrapper internals
|
|
54
|
+
|
|
55
|
+
After calling global command `iohtee-abi-wrapper`
|
|
56
|
+
```bash
|
|
57
|
+
$ iohtee-abi-wrapper -o ./generated ./abi/*
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
you will get a TS wrapper file.
|
|
61
|
+
|
|
62
|
+
Say you have contract ABI with name `Unidirectional`, in this case TS wrapper classname will be `UnidirectionalContract`
|
|
63
|
+
Importing:
|
|
64
|
+
```typescript
|
|
65
|
+
import {
|
|
66
|
+
CtorParams,
|
|
67
|
+
UnidirectionalContract,
|
|
68
|
+
} from './generated/UnidirectionalContract'
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Constructor:
|
|
72
|
+
```typescript
|
|
73
|
+
constructor(deployedContractAddress: `0x${string}`, params: CtorParams)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- `deployedContractAddress` is the blockchain contract address which will be used for interacting via TS-wrapper.
|
|
77
|
+
|
|
78
|
+
- `CtorParams` object type consists of:
|
|
79
|
+
```typescript
|
|
80
|
+
{
|
|
81
|
+
httpRpcUrl: string // RPC URL (e.g. Alchemy, Infura...) like https://rpc-amoy.polygon.technology
|
|
82
|
+
networkId: number // Network ID or Chain ID like 80002 for Polygon Amoy
|
|
83
|
+
mnemonic: string // 12-word seed mnemonic phrase
|
|
84
|
+
hdPath: `m/44'/60'/${string}` // BIP44 HDPath of account like m/44'/60'/0'/0/0 for the first account for the given seed
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Generated HTML documentation for TS wrapper be like
|
|
89
|
+

|
|
90
|
+
|
|
22
91
|
## TODO
|
|
23
|
-
- add postprocess with prettier
|
|
92
|
+
- add postprocess with prettier and autodetecting of prettierrc
|
|
24
93
|
- TS-wrapper docs autogen
|
|
25
94
|
- add errors and library references handling
|
|
26
95
|
- generate d.ts and min.js wrapper files
|
|
27
96
|
- add solidity comments to wrapper
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
Apache-2.0
|
package/dist/abiWrapper.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
export declare function findNearestTsConfig(startPath: string): string | null;
|
|
1
2
|
export declare class AbiWrapper {
|
|
2
3
|
templatesDir: string;
|
|
3
4
|
outputDir: string;
|
|
4
5
|
pattern: string;
|
|
5
6
|
minify: boolean;
|
|
6
|
-
|
|
7
|
+
docsDir: string | undefined;
|
|
8
|
+
constructor(pattern: string, outputDir: string, minify?: boolean, docsDir?: string);
|
|
9
|
+
generateDocs(filePath: string): Promise<void>;
|
|
7
10
|
run(): Promise<void>;
|
|
8
11
|
}
|
package/dist/abiWrapper.js
CHANGED
|
@@ -1,28 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AbiWrapper = exports.findNearestTsConfig = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const contractTemplate_js_1 = __importDefault(require("./contractTemplate.js"));
|
|
10
|
+
const glob_1 = require("glob");
|
|
11
|
+
const mkdirp_1 = require("mkdirp");
|
|
12
|
+
const typedoc_1 = require("typedoc");
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
function findNearestTsConfig(startPath) {
|
|
15
|
+
let currentDir = startPath;
|
|
16
|
+
while (true) {
|
|
17
|
+
const tsConfigPath = node_path_1.default.join(currentDir, 'tsconfig.json');
|
|
18
|
+
if (node_fs_1.default.existsSync(tsConfigPath)) {
|
|
19
|
+
return tsConfigPath;
|
|
20
|
+
}
|
|
21
|
+
const parentDir = node_path_1.default.dirname(currentDir);
|
|
22
|
+
if (parentDir === currentDir) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
currentDir = parentDir;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.findNearestTsConfig = findNearestTsConfig;
|
|
29
|
+
class AbiWrapper {
|
|
7
30
|
templatesDir;
|
|
8
31
|
outputDir;
|
|
9
32
|
pattern;
|
|
10
33
|
minify;
|
|
11
|
-
|
|
34
|
+
docsDir;
|
|
35
|
+
constructor(pattern, outputDir, minify, docsDir) {
|
|
12
36
|
this.pattern = pattern;
|
|
13
|
-
this.templatesDir =
|
|
37
|
+
this.templatesDir = node_path_1.default.join(__dirname, '../templates');
|
|
14
38
|
this.outputDir = outputDir;
|
|
15
39
|
this.minify = !!minify;
|
|
40
|
+
this.docsDir = docsDir;
|
|
41
|
+
}
|
|
42
|
+
async generateDocs(filePath) {
|
|
43
|
+
const tsConfigPath = findNearestTsConfig(filePath);
|
|
44
|
+
const docsDirFull = node_path_1.default.resolve(this.docsDir);
|
|
45
|
+
fs_extra_1.default.emptyDirSync(docsDirFull);
|
|
46
|
+
const filename = node_path_1.default.parse(filePath).name;
|
|
47
|
+
const outFolder = `${docsDirFull}/${filename}/`;
|
|
48
|
+
const app = await typedoc_1.Application.bootstrap({
|
|
49
|
+
entryPoints: [filePath],
|
|
50
|
+
out: outFolder,
|
|
51
|
+
excludeInternal: true,
|
|
52
|
+
excludePrivate: true,
|
|
53
|
+
tsconfig: tsConfigPath,
|
|
54
|
+
skipErrorChecking: true,
|
|
55
|
+
});
|
|
56
|
+
app.options.addReader(new typedoc_1.TSConfigReader());
|
|
57
|
+
app.options.addReader(new typedoc_1.TypeDocReader());
|
|
58
|
+
const project = await app.convert();
|
|
59
|
+
if (project) {
|
|
60
|
+
await app.generateDocs(project, outFolder);
|
|
61
|
+
console.log('Documentation generated successfully!');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.error('Documentation generation failed!');
|
|
65
|
+
}
|
|
16
66
|
}
|
|
17
67
|
async run() {
|
|
18
|
-
if (!
|
|
19
|
-
mkdirp.sync(this.outputDir);
|
|
68
|
+
if (!node_fs_1.default.existsSync(this.outputDir)) {
|
|
69
|
+
mkdirp_1.mkdirp.sync(this.outputDir);
|
|
20
70
|
}
|
|
21
|
-
const fileNames = globSync(this.pattern);
|
|
71
|
+
const fileNames = (0, glob_1.globSync)(this.pattern);
|
|
22
72
|
if (fileNames.length) {
|
|
23
73
|
fileNames.forEach((fileName) => {
|
|
24
|
-
let transformer = new
|
|
74
|
+
let transformer = new contractTemplate_js_1.default(this.templatesDir, this.outputDir);
|
|
25
75
|
transformer.render(fileName, this.minify);
|
|
76
|
+
if (this.docsDir) {
|
|
77
|
+
const basename = node_path_1.default.basename(fileName, node_path_1.default.extname(fileName));
|
|
78
|
+
const tsFilePath = node_path_1.default.resolve(`${this.outputDir}/${basename}Contract.ts`);
|
|
79
|
+
this.generateDocs(tsFilePath);
|
|
80
|
+
}
|
|
26
81
|
});
|
|
27
82
|
}
|
|
28
83
|
else {
|
|
@@ -30,4 +85,5 @@ export class AbiWrapper {
|
|
|
30
85
|
}
|
|
31
86
|
}
|
|
32
87
|
}
|
|
88
|
+
exports.AbiWrapper = AbiWrapper;
|
|
33
89
|
//# sourceMappingURL=abiWrapper.js.map
|
package/dist/abiWrapper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abiWrapper.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"abiWrapper.js","sourceRoot":"","sources":["../src/abiWrapper.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwB;AACxB,wDAA8B;AAC9B,gFAAoD;AACpD,+BAAqC;AACrC,mCAA+B;AAC/B,qCAAoE;AACpE,0DAA4B;AAE5B,SAAgB,mBAAmB,CAAC,SAAiB;IACnD,IAAI,UAAU,GAAG,SAAS,CAAA;IAE1B,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,YAAY,GAAG,mBAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAA;QAE3D,IAAI,iBAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAChC,OAAO,YAAY,CAAA;QACrB,CAAC;QAED,MAAM,SAAS,GAAG,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAE1C,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAA;QACb,CAAC;QAED,UAAU,GAAG,SAAS,CAAA;IACxB,CAAC;AACH,CAAC;AAlBD,kDAkBC;AAED,MAAa,UAAU;IACrB,YAAY,CAAQ;IACpB,SAAS,CAAQ;IACjB,OAAO,CAAQ;IACf,MAAM,CAAS;IACf,OAAO,CAAoB;IAE3B,YACE,OAAe,EACf,SAAiB,EACjB,MAAgB,EAChB,OAAgB;QAEhB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,YAAY,GAAG,mBAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;QACxD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAA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C,SAAS,CAAC,EAAE,CAAC;YACnC,eAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC7B,CAAC;QACD,MAAM,SAAS,GAAG,IAAA,eAAQ,EAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACxC,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;YACrB,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAC7B,IAAI,WAAW,GAAG,IAAI,6BAAgB,CACpC,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,SAAS,CACf,CAAA;gBACD,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;gBACzC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBACjB,MAAM,QAAQ,GAAG,mBAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;oBAChE,MAAM,UAAU,GAAG,mBAAI,CAAC,OAAO,CAC7B,GAAG,IAAI,CAAC,SAAS,IAAI,QAAQ,aAAa,CAC3C,CAAA;oBACD,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;gBAC/B,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,yCAAyC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QAC1E,CAAC;IACH,CAAC;CACF;AAvED,gCAuEC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Abi, AbiEvent, PublicClient, WalletClient, GetContractReturnType } from 'viem';
|
|
2
|
+
export interface TxOptions {
|
|
3
|
+
value?: bigint;
|
|
4
|
+
}
|
|
5
|
+
export type CtorBaseParams = {
|
|
6
|
+
cachePeriod?: number;
|
|
7
|
+
};
|
|
8
|
+
export type CtorAccountParamPure = CtorBaseParams & {
|
|
9
|
+
httpRpcUrl: string;
|
|
10
|
+
networkId: number;
|
|
11
|
+
mnemonic: string;
|
|
12
|
+
hdPath: `m/44'/60'/${string}`;
|
|
13
|
+
};
|
|
14
|
+
export type CtorAccountParamViem = CtorBaseParams & {
|
|
15
|
+
publicClientViem: PublicClient;
|
|
16
|
+
walletClientViem: WalletClient;
|
|
17
|
+
};
|
|
18
|
+
export declare function isCtorAccountParamPure(params: CtorBaseParams): params is CtorAccountParamPure;
|
|
19
|
+
export type CtorParams = CtorAccountParamPure | CtorAccountParamViem;
|
|
20
|
+
export declare class BaseContract {
|
|
21
|
+
private readonly _publicClient;
|
|
22
|
+
private readonly _walletClient;
|
|
23
|
+
private readonly _address;
|
|
24
|
+
private readonly _contract;
|
|
25
|
+
private readonly _abi;
|
|
26
|
+
constructor(deployedContractAddress: `0x${string}`, params: CtorParams, abi?: any);
|
|
27
|
+
publicClient(): PublicClient;
|
|
28
|
+
walletClient(): WalletClient;
|
|
29
|
+
contract(): GetContractReturnType;
|
|
30
|
+
address(): `0x${string}`;
|
|
31
|
+
abi(): Abi;
|
|
32
|
+
events(): AbiEvent[];
|
|
33
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.BaseContract = exports.isCtorAccountParamPure = void 0;
|
|
27
|
+
const viem_1 = require("viem");
|
|
28
|
+
const accounts_1 = require("viem/accounts");
|
|
29
|
+
const chains = __importStar(require("viem/chains"));
|
|
30
|
+
function isCtorAccountParamPure(params) {
|
|
31
|
+
return (params.httpRpcUrl !== undefined &&
|
|
32
|
+
params.mnemonic !== undefined);
|
|
33
|
+
}
|
|
34
|
+
exports.isCtorAccountParamPure = isCtorAccountParamPure;
|
|
35
|
+
class BaseContract {
|
|
36
|
+
_publicClient;
|
|
37
|
+
_walletClient;
|
|
38
|
+
_address;
|
|
39
|
+
_contract;
|
|
40
|
+
_abi;
|
|
41
|
+
constructor(deployedContractAddress, params, abi) {
|
|
42
|
+
this._address = deployedContractAddress;
|
|
43
|
+
if (isCtorAccountParamPure(params)) {
|
|
44
|
+
let network = (0, viem_1.extractChain)({
|
|
45
|
+
chains: Object.values(chains),
|
|
46
|
+
id: params.networkId,
|
|
47
|
+
});
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
this._publicClient = (0, viem_1.createPublicClient)({
|
|
50
|
+
batch: {
|
|
51
|
+
multicall: true,
|
|
52
|
+
},
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
chain: network,
|
|
55
|
+
transport: (0, viem_1.http)(params.httpRpcUrl, {
|
|
56
|
+
batch: true,
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
this._walletClient = (0, viem_1.createWalletClient)({
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
chain: network,
|
|
62
|
+
transport: (0, viem_1.http)(params.httpRpcUrl, {
|
|
63
|
+
batch: true,
|
|
64
|
+
}),
|
|
65
|
+
account: (0, accounts_1.mnemonicToAccount)(params.mnemonic, { path: params.hdPath }),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this._publicClient = params.publicClientViem;
|
|
70
|
+
this._walletClient = params.walletClientViem;
|
|
71
|
+
}
|
|
72
|
+
this._abi = abi;
|
|
73
|
+
this._contract = (0, viem_1.getContract)({
|
|
74
|
+
address: this._address,
|
|
75
|
+
abi: this._abi,
|
|
76
|
+
client: {
|
|
77
|
+
public: this._publicClient,
|
|
78
|
+
wallet: this._walletClient,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
publicClient() {
|
|
83
|
+
return this._publicClient;
|
|
84
|
+
}
|
|
85
|
+
walletClient() {
|
|
86
|
+
return this._walletClient;
|
|
87
|
+
}
|
|
88
|
+
contract() {
|
|
89
|
+
return this._contract;
|
|
90
|
+
}
|
|
91
|
+
address() {
|
|
92
|
+
return this._address;
|
|
93
|
+
}
|
|
94
|
+
abi() {
|
|
95
|
+
return this._abi;
|
|
96
|
+
}
|
|
97
|
+
events() {
|
|
98
|
+
return this.abi().filter((e) => e.type === 'event');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.BaseContract = BaseContract;
|
|
102
|
+
//# sourceMappingURL=baseContract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseContract.js","sourceRoot":"","sources":["../src/baseContract.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAWa;AACb,4CAAiD;AACjD,oDAAqC;AAsBrC,SAAgB,sBAAsB,CACpC,MAAsB;IAEtB,OAAO,CACJ,MAA+B,CAAC,UAAU,KAAK,SAAS;QACxD,MAA+B,CAAC,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A;QAEhB,IAAI,CAAC,SAAS,GAAG,IAAA,kBAAW,EAAC;YAC3B,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,GAAG,EAAE,IAAI,CAAC,IAAI;YACd,MAAM,EAAE;gBACN,MAAM,EAAE,IAAI,CAAC,aAAsB;gBACnC,MAAM,EAAE,IAAI,CAAC,aAAsB;aACpC;SACF,CAAC,CAAA;IACJ,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAe,CAAA;IACnE,CAAC;CACF;AA9ED,oCA8EC"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
+
const index_js_1 = require("../index.js");
|
|
9
|
+
const helpers_1 = require("yargs/helpers");
|
|
10
|
+
let args = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
6
11
|
.option('output', {
|
|
7
12
|
describe: 'Folder for generated files',
|
|
8
13
|
alias: 'o',
|
|
@@ -10,6 +15,10 @@ let args = yargs(hideBin(process.argv))
|
|
|
10
15
|
.option('minify', {
|
|
11
16
|
describe: 'Also render minified JS-wrapper',
|
|
12
17
|
alias: 'm',
|
|
18
|
+
})
|
|
19
|
+
.option('docs', {
|
|
20
|
+
describe: 'Folder for generated docs',
|
|
21
|
+
alias: 'd',
|
|
13
22
|
}).argv;
|
|
14
23
|
if (args._.length === 0) {
|
|
15
24
|
console.log('No arguments provided. Exiting...');
|
|
@@ -18,7 +27,8 @@ if (args._.length === 0) {
|
|
|
18
27
|
const pattern = args._[0];
|
|
19
28
|
const outputDir = args['output'];
|
|
20
29
|
const minify = args['minify'];
|
|
21
|
-
|
|
30
|
+
const docsDir = args['docs'];
|
|
31
|
+
let abiWrapper = new index_js_1.AbiWrapper(pattern, outputDir, minify, docsDir);
|
|
22
32
|
abiWrapper
|
|
23
33
|
.run()
|
|
24
34
|
.then(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iohtee-abi-wrapper.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"iohtee-abi-wrapper.js","sourceRoot":"","sources":["../../src/bin/iohtee-abi-wrapper.ts"],"names":[],"mappings":";;;;;;AAEA,kDAAyB;AACzB,0CAAwC;AACxC,2CAAuC;AAEvC,IAAI,IAAI,GAAQ,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACzC,MAAM,CAAC,QAAQ,EAAE;IAChB,QAAQ,EAAE,4BAA4B;IACtC,KAAK,EAAE,GAAG;CACX,CAAC;KACD,MAAM,CAAC,QAAQ,EAAE;IAChB,QAAQ,EAAE,iCAAiC;IAC3C,KAAK,EAAE,GAAG;CACX,CAAC;KACD,MAAM,CAAC,MAAM,EAAE;IACd,QAAQ,EAAE,2BAA2B;IACrC,KAAK,EAAE,GAAG;CACX,CAAC,CAAC,IAAI,CAAA;AAET,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAA;IAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACzB,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;AAChC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;AAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,UAAU,GAAG,IAAI,qBAAU,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AACpE,UAAU;KACP,GAAG,EAAE;KACL,IAAI,CAAC,GAAG,EAAE;IACT,aAAa;AACf,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;IACtB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
package/dist/context.js
CHANGED
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":""}
|
package/dist/contractTemplate.js
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
30
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
31
|
+
const esbuild_1 = require("esbuild");
|
|
32
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
33
|
+
const helpers = __importStar(require("./helpers.js"));
|
|
6
34
|
const ABI_TYPE_FUNCTION = 'function';
|
|
7
35
|
const ABI_TYPE_EVENT = 'event';
|
|
8
36
|
function isAbiFunction(abi) {
|
|
@@ -11,13 +39,13 @@ function isAbiFunction(abi) {
|
|
|
11
39
|
function isAbiEvent(abi) {
|
|
12
40
|
return abi.type === ABI_TYPE_EVENT;
|
|
13
41
|
}
|
|
14
|
-
|
|
42
|
+
class ContractTemplate {
|
|
15
43
|
handlebars;
|
|
16
44
|
templatesDir;
|
|
17
45
|
outputDir;
|
|
18
46
|
_template;
|
|
19
47
|
constructor(templatesDir, outputDir) {
|
|
20
|
-
this.handlebars =
|
|
48
|
+
this.handlebars = handlebars_1.default.create();
|
|
21
49
|
this.templatesDir = templatesDir;
|
|
22
50
|
this.outputDir = outputDir;
|
|
23
51
|
this.registerPartials();
|
|
@@ -36,7 +64,7 @@ export default class ContractTemplate {
|
|
|
36
64
|
}
|
|
37
65
|
}
|
|
38
66
|
registerPartials() {
|
|
39
|
-
|
|
67
|
+
node_fs_1.default.readdirSync(this.templatesDir).forEach((file) => {
|
|
40
68
|
let match = file.match(/^_(\w+)\.(handlebars|mustache)/);
|
|
41
69
|
if (match) {
|
|
42
70
|
this.handlebars.registerPartial(match[1], this.readTemplate(file));
|
|
@@ -48,7 +76,7 @@ export default class ContractTemplate {
|
|
|
48
76
|
this.handlebars.registerHelper('outputType', helpers.outputType);
|
|
49
77
|
}
|
|
50
78
|
render(abiFilePath, minified) {
|
|
51
|
-
let artifact = JSON.parse(
|
|
79
|
+
let artifact = JSON.parse(node_fs_1.default.readFileSync(abiFilePath).toString());
|
|
52
80
|
const sourceAbi = JSON.stringify(artifact.abi);
|
|
53
81
|
let abi = artifact.abi;
|
|
54
82
|
if (abi) {
|
|
@@ -77,10 +105,10 @@ export default class ContractTemplate {
|
|
|
77
105
|
let getters = methods.filter((abi) => abi.stateMutability === 'view' || abi.stateMutability === 'pure');
|
|
78
106
|
let functions = methods.filter((abi) => abi.stateMutability !== 'view' && abi.stateMutability !== 'pure');
|
|
79
107
|
let events = abi.filter(isAbiEvent);
|
|
80
|
-
let contractName =
|
|
81
|
-
const basename =
|
|
108
|
+
let contractName = node_path_1.default.parse(abiFilePath).name;
|
|
109
|
+
const basename = node_path_1.default.basename(abiFilePath, node_path_1.default.extname(abiFilePath));
|
|
82
110
|
const filePath = `${this.outputDir}/${basename}Contract.ts`;
|
|
83
|
-
const relativeArtifactPath =
|
|
111
|
+
const relativeArtifactPath = node_path_1.default.relative(this.outputDir, abiFilePath);
|
|
84
112
|
let context = {
|
|
85
113
|
artifact: JSON.stringify(artifact, null, 2),
|
|
86
114
|
abi: JSON.stringify(sourceAbi),
|
|
@@ -91,9 +119,9 @@ export default class ContractTemplate {
|
|
|
91
119
|
events: events,
|
|
92
120
|
};
|
|
93
121
|
let code = this.template(context);
|
|
94
|
-
|
|
122
|
+
node_fs_1.default.writeFileSync(filePath, code);
|
|
95
123
|
if (minified) {
|
|
96
|
-
build({
|
|
124
|
+
(0, esbuild_1.build)({
|
|
97
125
|
entryPoints: [filePath],
|
|
98
126
|
outfile: `${filePath}.min.js`,
|
|
99
127
|
bundle: false,
|
|
@@ -110,8 +138,9 @@ export default class ContractTemplate {
|
|
|
110
138
|
}
|
|
111
139
|
}
|
|
112
140
|
readTemplate(name) {
|
|
113
|
-
let file =
|
|
114
|
-
return
|
|
141
|
+
let file = node_path_1.default.resolve(this.templatesDir, name);
|
|
142
|
+
return node_fs_1.default.readFileSync(file).toString();
|
|
115
143
|
}
|
|
116
144
|
}
|
|
145
|
+
exports.default = ContractTemplate;
|
|
117
146
|
//# sourceMappingURL=contractTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractTemplate.js","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"contractTemplate.js","sourceRoot":"","sources":["../src/contractTemplate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAC5B,sDAAwB;AAExB,qCAA+B;AAC/B,4DAAmC;AAEnC,sDAAuC;AAEvC,MAAM,iBAAiB,GAAG,UAAU,CAAA;AACpC,MAAM,cAAc,GAAG,OAAO,CAAA;AAE9B,SAAS,aAAa,CAAC,GAAgB;IACrC,OAAO,GAAG,CAAC,IAAI,KAAK,iBAAiB,CAAA;AACvC,CAAC;AAED,SAAS,UAAU,CAAC,GAAa;IAC/B,OAAO,GAAG,CAAC,IAAI,KAAK,cAAc,CAAA;AACpC,CAAC;AAED,MAAqB,gBAAgB;IACnC,UAAU,CAAmB;IAC7B,YA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AAO,CAAC,CAAA;YACjC,iBAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;YAChC,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAA,eAAK,EAAC;oBACJ,WAAW,EAAE,CAAC,QAAQ,CAAC;oBACvB,OAAO,EAAE,GAAG,QAAQ,SAAS;oBAC7B,MAAM,EAAE,KAAK;oBACb,MAAM,EAAE,IAAI;oBACZ,MAAM,EAAE,KAAK;oBACb,QAAQ,EAAE,MAAM;oBAChB,SAAS,EAAE,KAAK;oBAChB,MAAM,EAAE,CAAC,QAAQ,CAAC;iBACnB,CAAC,CAAC,IAAI,EAAE,CAAA;YACX,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,mBAAmB,WAAW,GAAG,CAAC,CAAA;QACpD,CAAC;IACH,CAAC;IAES,YAAY,CAAC,IAAY;QACjC,IAAI,IAAI,GAAG,mBAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;QAChD,OAAO,iBAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;IACzC,CAAC;CACF;AAtHD,mCAsHC"}
|
package/dist/helpers.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.outputType = exports.inputType = void 0;
|
|
1
4
|
const TYPE_MAPPING = [
|
|
2
5
|
{ regex: '^string$', tsType: 'string' },
|
|
3
6
|
{ regex: '^address$', tsType: '`0x${string}`' },
|
|
@@ -34,10 +37,12 @@ function typeConversion(types, solidityType, components) {
|
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
|
|
40
|
+
function inputType(solidityType, components) {
|
|
38
41
|
return typeConversion(INPUT_TYPE_MAPPING, solidityType, components);
|
|
39
42
|
}
|
|
40
|
-
|
|
43
|
+
exports.inputType = inputType;
|
|
44
|
+
function outputType(solidityType) {
|
|
41
45
|
return typeConversion(TYPE_MAPPING, solidityType);
|
|
42
46
|
}
|
|
47
|
+
exports.outputType = outputType;
|
|
43
48
|
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"
|
|
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,GAAG,cAAc,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAA;QACpD,OAAO,GAAG,IAAI,IAAI,CAAA;IACpB,CAAC;SAAM,IAAI,OAAO,CAAC,YAAY,CAAC,IAAI,UAAU,EAAE,CAAC;QAC/C,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAA;IACnE,CAAC;SAAM,CAAC;QACN,IAAI,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;QAC1E,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC,MAAM,CAAA;QACvB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,gCAAgC,YAAY,EAAE,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAgB,SAAS,CACvB,YAAoB,EACpB,UAAuB;IAEvB,OAAO,cAAc,CAAC,kBAAkB,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;AACrE,CAAC;AALD,8BAKC;AAED,SAAgB,UAAU,CAAC,YAAoB;IAC7C,OAAO,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;AACnD,CAAC;AAFD,gCAEC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCtorAccountParamPure = exports.BaseContract = exports.AbiWrapper = void 0;
|
|
4
|
+
var abiWrapper_js_1 = require("./abiWrapper.js");
|
|
5
|
+
Object.defineProperty(exports, "AbiWrapper", { enumerable: true, get: function () { return abiWrapper_js_1.AbiWrapper; } });
|
|
6
|
+
var baseContract_js_1 = require("./baseContract.js");
|
|
7
|
+
Object.defineProperty(exports, "BaseContract", { enumerable: true, get: function () { return baseContract_js_1.BaseContract; } });
|
|
8
|
+
Object.defineProperty(exports, "isCtorAccountParamPure", { enumerable: true, get: function () { return baseContract_js_1.isCtorAccountParamPure; } });
|
|
2
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riaskov/iohtee-abi-wrapper",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Generate TypeScript wrapper class for Solidity smart contract ABI",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Machinomy Team <hello@machinomy.com>",
|
|
@@ -10,7 +10,17 @@
|
|
|
10
10
|
"email": "code@riaskov.com"
|
|
11
11
|
}
|
|
12
12
|
],
|
|
13
|
-
"
|
|
13
|
+
"keywords": [
|
|
14
|
+
"solidity",
|
|
15
|
+
"ethereum",
|
|
16
|
+
"evm",
|
|
17
|
+
"polygon",
|
|
18
|
+
"binance",
|
|
19
|
+
"abi",
|
|
20
|
+
"hardhat",
|
|
21
|
+
"wrapper"
|
|
22
|
+
],
|
|
23
|
+
"homepage": "https://github.com/ARyaskov/IohTee/tree/main/packages/abi-wrapper#readme",
|
|
14
24
|
"bugs": {
|
|
15
25
|
"url": "https://github.com/ARyaskov/iohtee/issues"
|
|
16
26
|
},
|
|
@@ -21,7 +31,6 @@
|
|
|
21
31
|
"engines": {
|
|
22
32
|
"node": ">=20"
|
|
23
33
|
},
|
|
24
|
-
"type": "module",
|
|
25
34
|
"main": "dist/index.js",
|
|
26
35
|
"types": "dist/index.d.ts",
|
|
27
36
|
"bin": "dist/bin/iohtee-abi-wrapper.js",
|
|
@@ -30,7 +39,7 @@
|
|
|
30
39
|
"templates/"
|
|
31
40
|
],
|
|
32
41
|
"scripts": {
|
|
33
|
-
"demo": "tsx src/bin/iohtee-abi-wrapper.ts ./abi/* -m -o ../contracts/src/abi-wrapper/",
|
|
42
|
+
"demo": "tsx src/bin/iohtee-abi-wrapper.ts ./abi/* -m -d ./docs -o ../contracts/src/abi-wrapper/",
|
|
34
43
|
"build": "yarn format && yarn clean && tsc --project tsconfig.json",
|
|
35
44
|
"clean": "rimraf dist",
|
|
36
45
|
"test": "exit 0",
|
|
@@ -42,6 +51,7 @@
|
|
|
42
51
|
"chalk": "^5.3.0",
|
|
43
52
|
"console.table": "^0.10.0",
|
|
44
53
|
"esbuild": "^0.21.5",
|
|
54
|
+
"fs-extra": "^11.2.0",
|
|
45
55
|
"glob": "^10.4.2",
|
|
46
56
|
"handlebars": "^4.7.8",
|
|
47
57
|
"mkdirp": "^3.0.1",
|
|
@@ -50,6 +60,8 @@
|
|
|
50
60
|
},
|
|
51
61
|
"devDependencies": {
|
|
52
62
|
"@types/yargs": "^17.0.32",
|
|
53
|
-
"rimraf": "*"
|
|
63
|
+
"rimraf": "*",
|
|
64
|
+
"typedoc": "^0.26.2",
|
|
65
|
+
"typedoc-plugin-markdown": "^4.1.0"
|
|
54
66
|
}
|
|
55
67
|
}
|
|
@@ -1,51 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Abi,
|
|
3
2
|
AbiEvent,
|
|
4
|
-
createPublicClient,
|
|
5
|
-
createWalletClient,
|
|
6
|
-
getContract,
|
|
7
|
-
http,
|
|
8
|
-
PublicClient,
|
|
9
|
-
WalletClient,
|
|
10
|
-
GetContractReturnType,
|
|
11
3
|
TransactionReceipt,
|
|
12
4
|
parseEventLogs,
|
|
13
5
|
ParseEventLogsReturnType,
|
|
14
|
-
extractChain
|
|
15
6
|
} from "viem"
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export interface TxOptions {
|
|
20
|
-
value?: bigint
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type CtorBaseParams = {
|
|
24
|
-
cachePeriod?: number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type CtorAccountParamPure = CtorBaseParams & {
|
|
28
|
-
httpRpcUrl: string
|
|
29
|
-
networkId: number
|
|
30
|
-
mnemonic: string
|
|
31
|
-
hdPath: `m/44'/60'/${string}`
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type CtorAccountParamViem = CtorBaseParams & {
|
|
35
|
-
publicClientViem: PublicClient
|
|
36
|
-
walletClientViem: WalletClient
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function isCtorAccountParamPure(
|
|
40
|
-
params: CtorBaseParams,
|
|
41
|
-
): params is CtorAccountParamPure {
|
|
42
|
-
return (
|
|
43
|
-
(params as CtorAccountParamPure).httpRpcUrl !== undefined &&
|
|
44
|
-
(params as CtorAccountParamPure).mnemonic !== undefined
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type CtorParams = CtorAccountParamPure | CtorAccountParamViem
|
|
7
|
+
import { BaseContract, TxOptions, CtorParams, isCtorAccountParamPure } from "@riaskov/iohtee-abi-wrapper"
|
|
8
|
+
export { isCtorAccountParamPure, CtorParams, TxOptions }
|
|
49
9
|
|
|
50
10
|
export interface {{contractName}}Event {
|
|
51
11
|
eventName: string
|
|
@@ -73,13 +33,7 @@ export enum {{contractName}}EventName {
|
|
|
73
33
|
|
|
74
34
|
const abi = JSON.parse(`{{abi}}`)
|
|
75
35
|
|
|
76
|
-
export class {{contractName}}Contract {
|
|
77
|
-
private readonly _publicClient: PublicClient
|
|
78
|
-
private readonly _walletClient: WalletClient
|
|
79
|
-
private readonly _address: `0x${string}`
|
|
80
|
-
private readonly _contract: GetContractReturnType
|
|
81
|
-
private readonly _abi: any
|
|
82
|
-
|
|
36
|
+
export class {{contractName}}Contract extends BaseContract {
|
|
83
37
|
/// GETTERS
|
|
84
38
|
{{#each getters}}
|
|
85
39
|
{{> getter contractName=../contractName}}
|
|
@@ -133,77 +87,6 @@ export class {{contractName}}Contract {
|
|
|
133
87
|
}
|
|
134
88
|
|
|
135
89
|
constructor(deployedContractAddress: `0x${string}`, params: CtorParams) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (isCtorAccountParamPure(params)) {
|
|
139
|
-
let network = extractChain({
|
|
140
|
-
chains: Object.values(chains) as any,
|
|
141
|
-
id: params.networkId,
|
|
142
|
-
})
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
this._publicClient = createPublicClient({
|
|
145
|
-
batch: {
|
|
146
|
-
multicall: true,
|
|
147
|
-
},
|
|
148
|
-
// @ts-ignore
|
|
149
|
-
chain: network as any,
|
|
150
|
-
transport: http(
|
|
151
|
-
params.httpRpcUrl,
|
|
152
|
-
{
|
|
153
|
-
batch: true,
|
|
154
|
-
}
|
|
155
|
-
),
|
|
156
|
-
})
|
|
157
|
-
this._walletClient = createWalletClient({
|
|
158
|
-
// @ts-ignore
|
|
159
|
-
chain: network as any,
|
|
160
|
-
transport: http(
|
|
161
|
-
params.httpRpcUrl,
|
|
162
|
-
{
|
|
163
|
-
batch: true,
|
|
164
|
-
}
|
|
165
|
-
),
|
|
166
|
-
account: mnemonicToAccount(params.mnemonic, { path: params.hdPath }),
|
|
167
|
-
})
|
|
168
|
-
} else {
|
|
169
|
-
this._publicClient = params.publicClientViem
|
|
170
|
-
this._walletClient = params.walletClientViem
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
this._abi = abi
|
|
174
|
-
|
|
175
|
-
this._contract = getContract({
|
|
176
|
-
address: this._address,
|
|
177
|
-
abi: this._abi,
|
|
178
|
-
client: {
|
|
179
|
-
public: this._publicClient as never,
|
|
180
|
-
wallet: this._walletClient as never,
|
|
181
|
-
},
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
publicClient(): PublicClient {
|
|
187
|
-
return this._publicClient
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
walletClient(): WalletClient {
|
|
191
|
-
return this._walletClient
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
contract(): GetContractReturnType {
|
|
195
|
-
return this._contract
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
address(): `0x${string}` {
|
|
199
|
-
return this._address
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
abi(): Abi {
|
|
203
|
-
return this._abi
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
events(): AbiEvent[] {
|
|
207
|
-
return this.abi().filter((e) => e.type === 'event') as AbiEvent[]
|
|
90
|
+
super(deployedContractAddress, params, abi)
|
|
208
91
|
}
|
|
209
92
|
}
|