@parity/product-sdk-contracts 0.1.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 +201 -0
- package/dist/chunk-E7AP65D4.js +244 -0
- package/dist/chunk-E7AP65D4.js.map +1 -0
- package/dist/codegen-Apg73XJX.d.ts +148 -0
- package/dist/codegen.d.ts +4 -0
- package/dist/codegen.js +7 -0
- package/dist/codegen.js.map +1 -0
- package/dist/index.d.ts +136 -0
- package/dist/index.js +412 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// src/codegen.ts
|
|
2
|
+
function mapSolidityType(param) {
|
|
3
|
+
const t = param.type;
|
|
4
|
+
if (t.endsWith("[]")) {
|
|
5
|
+
const inner = { ...param, type: t.slice(0, -2) };
|
|
6
|
+
return `${mapSolidityType(inner)}[]`;
|
|
7
|
+
}
|
|
8
|
+
const fixedArrayMatch = t.match(/^(.+)\[(\d+)\]$/);
|
|
9
|
+
if (fixedArrayMatch) {
|
|
10
|
+
const inner = { ...param, type: fixedArrayMatch[1] };
|
|
11
|
+
return `${mapSolidityType(inner)}[]`;
|
|
12
|
+
}
|
|
13
|
+
if (t === "tuple" && param.components) {
|
|
14
|
+
const fields = param.components.map((c) => `${c.name}: ${mapSolidityType(c)}`);
|
|
15
|
+
return `{ ${fields.join("; ")} }`;
|
|
16
|
+
}
|
|
17
|
+
if (/^uint(8|16|32)$/.test(t)) return "number";
|
|
18
|
+
if (/^uint\d*$/.test(t)) return "bigint";
|
|
19
|
+
if (/^int(8|16|32)$/.test(t)) return "number";
|
|
20
|
+
if (/^int\d*$/.test(t)) return "bigint";
|
|
21
|
+
if (t === "address") return "HexString";
|
|
22
|
+
if (t === "bytes") return "Binary";
|
|
23
|
+
const bytesMatch = t.match(/^bytes(\d+)$/);
|
|
24
|
+
if (bytesMatch) return `FixedSizeBinary<${bytesMatch[1]}>`;
|
|
25
|
+
if (t === "bool") return "boolean";
|
|
26
|
+
if (t === "string") return "string";
|
|
27
|
+
return "unknown";
|
|
28
|
+
}
|
|
29
|
+
function generateMethodArgsType(inputs) {
|
|
30
|
+
if (inputs.length === 0) return "[]";
|
|
31
|
+
const parts = inputs.map((p) => `${p.name}: ${mapSolidityType(p)}`);
|
|
32
|
+
return `[${parts.join(", ")}]`;
|
|
33
|
+
}
|
|
34
|
+
function generateMethodResponseType(outputs) {
|
|
35
|
+
if (!outputs || outputs.length === 0) return "undefined";
|
|
36
|
+
if (outputs.length === 1) return mapSolidityType(outputs[0]);
|
|
37
|
+
const fields = outputs.map((o, i) => {
|
|
38
|
+
const name = o.name || `_${i}`;
|
|
39
|
+
return `${name}: ${mapSolidityType(o)}`;
|
|
40
|
+
});
|
|
41
|
+
return `{ ${fields.join("; ")} }`;
|
|
42
|
+
}
|
|
43
|
+
function generateContractTypes(contracts) {
|
|
44
|
+
const lines = [
|
|
45
|
+
"// Auto-generated by cdm install \u2014 do not edit",
|
|
46
|
+
'import type { HexString, Binary, FixedSizeBinary } from "polkadot-api";',
|
|
47
|
+
"",
|
|
48
|
+
'declare module "@parity/product-sdk-contracts" {',
|
|
49
|
+
" interface Contracts {"
|
|
50
|
+
];
|
|
51
|
+
for (const contract of contracts) {
|
|
52
|
+
const methods = contract.abi.filter((e) => e.type === "function" && e.name);
|
|
53
|
+
lines.push(` "${contract.library}": {`);
|
|
54
|
+
lines.push(" methods: {");
|
|
55
|
+
for (const method of methods) {
|
|
56
|
+
const args = generateMethodArgsType(method.inputs);
|
|
57
|
+
const response = generateMethodResponseType(method.outputs);
|
|
58
|
+
lines.push(
|
|
59
|
+
` ${method.name}: { args: ${args}; response: ${response} };`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
lines.push(" };");
|
|
63
|
+
lines.push(" };");
|
|
64
|
+
}
|
|
65
|
+
lines.push(" }");
|
|
66
|
+
lines.push("}");
|
|
67
|
+
lines.push("");
|
|
68
|
+
return lines.join("\n");
|
|
69
|
+
}
|
|
70
|
+
if (void 0) {
|
|
71
|
+
const { test, expect, describe } = void 0;
|
|
72
|
+
describe("mapSolidityType", () => {
|
|
73
|
+
const cases = [
|
|
74
|
+
[{ name: "x", type: "uint8" }, "number"],
|
|
75
|
+
[{ name: "x", type: "uint16" }, "number"],
|
|
76
|
+
[{ name: "x", type: "uint32" }, "number"],
|
|
77
|
+
[{ name: "x", type: "uint64" }, "bigint"],
|
|
78
|
+
[{ name: "x", type: "uint128" }, "bigint"],
|
|
79
|
+
[{ name: "x", type: "uint256" }, "bigint"],
|
|
80
|
+
[{ name: "x", type: "int8" }, "number"],
|
|
81
|
+
[{ name: "x", type: "int32" }, "number"],
|
|
82
|
+
[{ name: "x", type: "int64" }, "bigint"],
|
|
83
|
+
[{ name: "x", type: "int256" }, "bigint"],
|
|
84
|
+
[{ name: "x", type: "address" }, "HexString"],
|
|
85
|
+
[{ name: "x", type: "bool" }, "boolean"],
|
|
86
|
+
[{ name: "x", type: "string" }, "string"],
|
|
87
|
+
[{ name: "x", type: "bytes" }, "Binary"],
|
|
88
|
+
[{ name: "x", type: "bytes32" }, "FixedSizeBinary<32>"],
|
|
89
|
+
[{ name: "x", type: "bytes4" }, "FixedSizeBinary<4>"],
|
|
90
|
+
[{ name: "x", type: "uint256[]" }, "bigint[]"],
|
|
91
|
+
[{ name: "x", type: "address[]" }, "HexString[]"],
|
|
92
|
+
[{ name: "x", type: "uint256[3]" }, "bigint[]"],
|
|
93
|
+
[{ name: "x", type: "somethingWeird" }, "unknown"]
|
|
94
|
+
];
|
|
95
|
+
for (const [param, expected] of cases) {
|
|
96
|
+
test(`${param.type} \u2192 ${expected}`, () => {
|
|
97
|
+
expect(mapSolidityType(param)).toBe(expected);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
test("tuple with components", () => {
|
|
101
|
+
const param = {
|
|
102
|
+
name: "info",
|
|
103
|
+
type: "tuple",
|
|
104
|
+
components: [
|
|
105
|
+
{ name: "addr", type: "address" },
|
|
106
|
+
{ name: "amount", type: "uint256" }
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
expect(mapSolidityType(param)).toBe("{ addr: HexString; amount: bigint }");
|
|
110
|
+
});
|
|
111
|
+
test("nested array of tuples", () => {
|
|
112
|
+
const param = {
|
|
113
|
+
name: "items",
|
|
114
|
+
type: "tuple[]",
|
|
115
|
+
components: [
|
|
116
|
+
{ name: "id", type: "uint32" },
|
|
117
|
+
{ name: "name", type: "string" }
|
|
118
|
+
]
|
|
119
|
+
};
|
|
120
|
+
expect(mapSolidityType(param)).toBe("{ id: number; name: string }[]");
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe("generateMethodArgsType", () => {
|
|
124
|
+
test("empty inputs", () => {
|
|
125
|
+
expect(generateMethodArgsType([])).toBe("[]");
|
|
126
|
+
});
|
|
127
|
+
test("single input", () => {
|
|
128
|
+
expect(generateMethodArgsType([{ name: "to", type: "address" }])).toBe(
|
|
129
|
+
"[to: HexString]"
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
test("multiple inputs", () => {
|
|
133
|
+
const result = generateMethodArgsType([
|
|
134
|
+
{ name: "to", type: "address" },
|
|
135
|
+
{ name: "amount", type: "uint256" }
|
|
136
|
+
]);
|
|
137
|
+
expect(result).toBe("[to: HexString, amount: bigint]");
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe("generateMethodResponseType", () => {
|
|
141
|
+
test("no outputs", () => {
|
|
142
|
+
expect(generateMethodResponseType(void 0)).toBe("undefined");
|
|
143
|
+
expect(generateMethodResponseType([])).toBe("undefined");
|
|
144
|
+
});
|
|
145
|
+
test("single output", () => {
|
|
146
|
+
expect(generateMethodResponseType([{ name: "", type: "uint32" }])).toBe("number");
|
|
147
|
+
});
|
|
148
|
+
test("multiple outputs", () => {
|
|
149
|
+
const result = generateMethodResponseType([
|
|
150
|
+
{ name: "balance", type: "uint256" },
|
|
151
|
+
{ name: "nonce", type: "uint32" }
|
|
152
|
+
]);
|
|
153
|
+
expect(result).toBe("{ balance: bigint; nonce: number }");
|
|
154
|
+
});
|
|
155
|
+
test("unnamed outputs get positional names", () => {
|
|
156
|
+
const result = generateMethodResponseType([
|
|
157
|
+
{ name: "", type: "bool" },
|
|
158
|
+
{ name: "", type: "uint256" }
|
|
159
|
+
]);
|
|
160
|
+
expect(result).toBe("{ _0: boolean; _1: bigint }");
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
describe("generateContractTypes", () => {
|
|
164
|
+
test("generates valid module augmentation", () => {
|
|
165
|
+
const result = generateContractTypes([
|
|
166
|
+
{
|
|
167
|
+
library: "@example/counter",
|
|
168
|
+
abi: [
|
|
169
|
+
{
|
|
170
|
+
type: "constructor",
|
|
171
|
+
inputs: [],
|
|
172
|
+
stateMutability: "nonpayable"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
type: "function",
|
|
176
|
+
name: "getCount",
|
|
177
|
+
inputs: [],
|
|
178
|
+
outputs: [{ name: "", type: "uint32" }],
|
|
179
|
+
stateMutability: "view"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
type: "function",
|
|
183
|
+
name: "increment",
|
|
184
|
+
inputs: [],
|
|
185
|
+
outputs: [],
|
|
186
|
+
stateMutability: "nonpayable"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
]);
|
|
191
|
+
expect(result).toContain('declare module "@parity/product-sdk-contracts"');
|
|
192
|
+
expect(result).toContain("interface Contracts");
|
|
193
|
+
expect(result).toContain('"@example/counter"');
|
|
194
|
+
expect(result).toContain("getCount: { args: []; response: number };");
|
|
195
|
+
expect(result).toContain("increment: { args: []; response: undefined };");
|
|
196
|
+
expect(result).not.toContain("constructor");
|
|
197
|
+
});
|
|
198
|
+
test("handles multiple contracts", () => {
|
|
199
|
+
const result = generateContractTypes([
|
|
200
|
+
{
|
|
201
|
+
library: "@a/one",
|
|
202
|
+
abi: [
|
|
203
|
+
{
|
|
204
|
+
type: "function",
|
|
205
|
+
name: "foo",
|
|
206
|
+
inputs: [{ name: "x", type: "uint256" }],
|
|
207
|
+
outputs: [{ name: "", type: "bool" }]
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
library: "@b/two",
|
|
213
|
+
abi: [
|
|
214
|
+
{
|
|
215
|
+
type: "function",
|
|
216
|
+
name: "bar",
|
|
217
|
+
inputs: [],
|
|
218
|
+
outputs: [{ name: "", type: "address" }]
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
]);
|
|
223
|
+
expect(result).toContain('"@a/one"');
|
|
224
|
+
expect(result).toContain('"@b/two"');
|
|
225
|
+
expect(result).toContain("foo: { args: [x: bigint]; response: boolean };");
|
|
226
|
+
expect(result).toContain("bar: { args: []; response: HexString };");
|
|
227
|
+
});
|
|
228
|
+
test("empty contracts list", () => {
|
|
229
|
+
const result = generateContractTypes([]);
|
|
230
|
+
expect(result).toContain("interface Contracts {");
|
|
231
|
+
expect(result).toContain("}");
|
|
232
|
+
});
|
|
233
|
+
test("includes polkadot-api type imports", () => {
|
|
234
|
+
const result = generateContractTypes([]);
|
|
235
|
+
expect(result).toContain("import type { HexString, Binary, FixedSizeBinary }");
|
|
236
|
+
expect(result).toContain('from "polkadot-api"');
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
generateContractTypes
|
|
243
|
+
};
|
|
244
|
+
//# sourceMappingURL=chunk-E7AP65D4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/codegen.ts"],"sourcesContent":["import type { AbiEntry, AbiParam } from \"./types.js\";\n\n/** Map a Solidity ABI type to its TypeScript equivalent. */\nfunction mapSolidityType(param: AbiParam): string {\n const t = param.type;\n\n // Dynamic arrays — e.g. uint256[]\n if (t.endsWith(\"[]\")) {\n const inner = { ...param, type: t.slice(0, -2) };\n return `${mapSolidityType(inner)}[]`;\n }\n\n // Fixed-size arrays — e.g. uint256[3]\n const fixedArrayMatch = t.match(/^(.+)\\[(\\d+)\\]$/);\n if (fixedArrayMatch) {\n const inner = { ...param, type: fixedArrayMatch[1] };\n return `${mapSolidityType(inner)}[]`;\n }\n\n // Tuple\n if (t === \"tuple\" && param.components) {\n const fields = param.components.map((c) => `${c.name}: ${mapSolidityType(c)}`);\n return `{ ${fields.join(\"; \")} }`;\n }\n\n // Unsigned integers — uint8/16/32 fit in JS number\n if (/^uint(8|16|32)$/.test(t)) return \"number\";\n if (/^uint\\d*$/.test(t)) return \"bigint\";\n\n // Signed integers\n if (/^int(8|16|32)$/.test(t)) return \"number\";\n if (/^int\\d*$/.test(t)) return \"bigint\";\n\n // Address\n if (t === \"address\") return \"HexString\";\n\n // Bytes\n if (t === \"bytes\") return \"Binary\";\n const bytesMatch = t.match(/^bytes(\\d+)$/);\n if (bytesMatch) return `FixedSizeBinary<${bytesMatch[1]}>`;\n\n // Primitives\n if (t === \"bool\") return \"boolean\";\n if (t === \"string\") return \"string\";\n\n return \"unknown\";\n}\n\nfunction generateMethodArgsType(inputs: AbiParam[]): string {\n if (inputs.length === 0) return \"[]\";\n const parts = inputs.map((p) => `${p.name}: ${mapSolidityType(p)}`);\n return `[${parts.join(\", \")}]`;\n}\n\nfunction generateMethodResponseType(outputs: AbiParam[] | undefined): string {\n if (!outputs || outputs.length === 0) return \"undefined\";\n if (outputs.length === 1) return mapSolidityType(outputs[0]);\n const fields = outputs.map((o, i) => {\n const name = o.name || `_${i}`;\n return `${name}: ${mapSolidityType(o)}`;\n });\n return `{ ${fields.join(\"; \")} }`;\n}\n\n/**\n * Generate a TypeScript module augmentation that extends the\n * {@link Contracts} interface with typed method signatures for each\n * installed contract.\n *\n * The output is written to `.cdm/contracts.d.ts` (or equivalent) and\n * augments `\"@parity/product-sdk-contracts\"` so that\n * `ContractManager.getContract()` returns fully-typed handles.\n *\n * @example\n * ```ts\n * const src = generateContractTypes([\n * { library: \"@example/counter\", abi },\n * ]);\n * writeFileSync(\".cdm/contracts.d.ts\", src);\n * ```\n */\nexport function generateContractTypes(contracts: { library: string; abi: AbiEntry[] }[]): string {\n const lines: string[] = [\n \"// Auto-generated by cdm install — do not edit\",\n 'import type { HexString, Binary, FixedSizeBinary } from \"polkadot-api\";',\n \"\",\n 'declare module \"@parity/product-sdk-contracts\" {',\n \" interface Contracts {\",\n ];\n\n for (const contract of contracts) {\n const methods = contract.abi.filter((e) => e.type === \"function\" && e.name);\n lines.push(` \"${contract.library}\": {`);\n lines.push(\" methods: {\");\n for (const method of methods) {\n const args = generateMethodArgsType(method.inputs);\n const response = generateMethodResponseType(method.outputs);\n lines.push(\n ` ${method.name!}: { args: ${args}; response: ${response} };`,\n );\n }\n lines.push(\" };\");\n lines.push(\" };\");\n }\n\n lines.push(\" }\");\n lines.push(\"}\");\n lines.push(\"\");\n\n return lines.join(\"\\n\");\n}\n\nif (import.meta.vitest) {\n const { test, expect, describe } = import.meta.vitest;\n\n describe(\"mapSolidityType\", () => {\n const cases: [AbiParam, string][] = [\n [{ name: \"x\", type: \"uint8\" }, \"number\"],\n [{ name: \"x\", type: \"uint16\" }, \"number\"],\n [{ name: \"x\", type: \"uint32\" }, \"number\"],\n [{ name: \"x\", type: \"uint64\" }, \"bigint\"],\n [{ name: \"x\", type: \"uint128\" }, \"bigint\"],\n [{ name: \"x\", type: \"uint256\" }, \"bigint\"],\n [{ name: \"x\", type: \"int8\" }, \"number\"],\n [{ name: \"x\", type: \"int32\" }, \"number\"],\n [{ name: \"x\", type: \"int64\" }, \"bigint\"],\n [{ name: \"x\", type: \"int256\" }, \"bigint\"],\n [{ name: \"x\", type: \"address\" }, \"HexString\"],\n [{ name: \"x\", type: \"bool\" }, \"boolean\"],\n [{ name: \"x\", type: \"string\" }, \"string\"],\n [{ name: \"x\", type: \"bytes\" }, \"Binary\"],\n [{ name: \"x\", type: \"bytes32\" }, \"FixedSizeBinary<32>\"],\n [{ name: \"x\", type: \"bytes4\" }, \"FixedSizeBinary<4>\"],\n [{ name: \"x\", type: \"uint256[]\" }, \"bigint[]\"],\n [{ name: \"x\", type: \"address[]\" }, \"HexString[]\"],\n [{ name: \"x\", type: \"uint256[3]\" }, \"bigint[]\"],\n [{ name: \"x\", type: \"somethingWeird\" }, \"unknown\"],\n ];\n\n for (const [param, expected] of cases) {\n test(`${param.type} → ${expected}`, () => {\n expect(mapSolidityType(param)).toBe(expected);\n });\n }\n\n test(\"tuple with components\", () => {\n const param: AbiParam = {\n name: \"info\",\n type: \"tuple\",\n components: [\n { name: \"addr\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n };\n expect(mapSolidityType(param)).toBe(\"{ addr: HexString; amount: bigint }\");\n });\n\n test(\"nested array of tuples\", () => {\n const param: AbiParam = {\n name: \"items\",\n type: \"tuple[]\",\n components: [\n { name: \"id\", type: \"uint32\" },\n { name: \"name\", type: \"string\" },\n ],\n };\n expect(mapSolidityType(param)).toBe(\"{ id: number; name: string }[]\");\n });\n });\n\n describe(\"generateMethodArgsType\", () => {\n test(\"empty inputs\", () => {\n expect(generateMethodArgsType([])).toBe(\"[]\");\n });\n\n test(\"single input\", () => {\n expect(generateMethodArgsType([{ name: \"to\", type: \"address\" }])).toBe(\n \"[to: HexString]\",\n );\n });\n\n test(\"multiple inputs\", () => {\n const result = generateMethodArgsType([\n { name: \"to\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ]);\n expect(result).toBe(\"[to: HexString, amount: bigint]\");\n });\n });\n\n describe(\"generateMethodResponseType\", () => {\n test(\"no outputs\", () => {\n expect(generateMethodResponseType(undefined)).toBe(\"undefined\");\n expect(generateMethodResponseType([])).toBe(\"undefined\");\n });\n\n test(\"single output\", () => {\n expect(generateMethodResponseType([{ name: \"\", type: \"uint32\" }])).toBe(\"number\");\n });\n\n test(\"multiple outputs\", () => {\n const result = generateMethodResponseType([\n { name: \"balance\", type: \"uint256\" },\n { name: \"nonce\", type: \"uint32\" },\n ]);\n expect(result).toBe(\"{ balance: bigint; nonce: number }\");\n });\n\n test(\"unnamed outputs get positional names\", () => {\n const result = generateMethodResponseType([\n { name: \"\", type: \"bool\" },\n { name: \"\", type: \"uint256\" },\n ]);\n expect(result).toBe(\"{ _0: boolean; _1: bigint }\");\n });\n });\n\n describe(\"generateContractTypes\", () => {\n test(\"generates valid module augmentation\", () => {\n const result = generateContractTypes([\n {\n library: \"@example/counter\",\n abi: [\n {\n type: \"constructor\",\n inputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"getCount\",\n inputs: [],\n outputs: [{ name: \"\", type: \"uint32\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"increment\",\n inputs: [],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n ],\n },\n ]);\n\n expect(result).toContain('declare module \"@parity/product-sdk-contracts\"');\n expect(result).toContain(\"interface Contracts\");\n expect(result).toContain('\"@example/counter\"');\n expect(result).toContain(\"getCount: { args: []; response: number };\");\n expect(result).toContain(\"increment: { args: []; response: undefined };\");\n // Should not include constructor\n expect(result).not.toContain(\"constructor\");\n });\n\n test(\"handles multiple contracts\", () => {\n const result = generateContractTypes([\n {\n library: \"@a/one\",\n abi: [\n {\n type: \"function\",\n name: \"foo\",\n inputs: [{ name: \"x\", type: \"uint256\" }],\n outputs: [{ name: \"\", type: \"bool\" }],\n },\n ],\n },\n {\n library: \"@b/two\",\n abi: [\n {\n type: \"function\",\n name: \"bar\",\n inputs: [],\n outputs: [{ name: \"\", type: \"address\" }],\n },\n ],\n },\n ]);\n\n expect(result).toContain('\"@a/one\"');\n expect(result).toContain('\"@b/two\"');\n expect(result).toContain(\"foo: { args: [x: bigint]; response: boolean };\");\n expect(result).toContain(\"bar: { args: []; response: HexString };\");\n });\n\n test(\"empty contracts list\", () => {\n const result = generateContractTypes([]);\n expect(result).toContain(\"interface Contracts {\");\n expect(result).toContain(\"}\");\n });\n\n test(\"includes polkadot-api type imports\", () => {\n const result = generateContractTypes([]);\n expect(result).toContain(\"import type { HexString, Binary, FixedSizeBinary }\");\n expect(result).toContain('from \"polkadot-api\"');\n });\n });\n}\n"],"mappings":";AAGA,SAAS,gBAAgB,OAAyB;AAC9C,QAAM,IAAI,MAAM;AAGhB,MAAI,EAAE,SAAS,IAAI,GAAG;AAClB,UAAM,QAAQ,EAAE,GAAG,OAAO,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE;AAC/C,WAAO,GAAG,gBAAgB,KAAK,CAAC;AAAA,EACpC;AAGA,QAAM,kBAAkB,EAAE,MAAM,iBAAiB;AACjD,MAAI,iBAAiB;AACjB,UAAM,QAAQ,EAAE,GAAG,OAAO,MAAM,gBAAgB,CAAC,EAAE;AACnD,WAAO,GAAG,gBAAgB,KAAK,CAAC;AAAA,EACpC;AAGA,MAAI,MAAM,WAAW,MAAM,YAAY;AACnC,UAAM,SAAS,MAAM,WAAW,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,KAAK,gBAAgB,CAAC,CAAC,EAAE;AAC7E,WAAO,KAAK,OAAO,KAAK,IAAI,CAAC;AAAA,EACjC;AAGA,MAAI,kBAAkB,KAAK,CAAC,EAAG,QAAO;AACtC,MAAI,YAAY,KAAK,CAAC,EAAG,QAAO;AAGhC,MAAI,iBAAiB,KAAK,CAAC,EAAG,QAAO;AACrC,MAAI,WAAW,KAAK,CAAC,EAAG,QAAO;AAG/B,MAAI,MAAM,UAAW,QAAO;AAG5B,MAAI,MAAM,Q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AAM,EAAE,UAAU,gDAAgD;AACzE,aAAO,MAAM,EAAE,UAAU,yCAAyC;AAAA,IACtE,CAAC;AAED,SAAK,wBAAwB,MAAM;AAC/B,YAAM,SAAS,sBAAsB,CAAC,CAAC;AACvC,aAAO,MAAM,EAAE,UAAU,uBAAuB;AAChD,aAAO,MAAM,EAAE,UAAU,GAAG;AAAA,IAChC,CAAC;AAED,SAAK,sCAAsC,MAAM;AAC7C,YAAM,SAAS,sBAAsB,CAAC,CAAC;AACvC,aAAO,MAAM,EAAE,UAAU,oDAAoD;AAC7E,aAAO,MAAM,EAAE,UAAU,qBAAqB;AAAA,IAClD,CAAC;AAAA,EACL,CAAC;AACL;","names":[]}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { HexString, SS58String, PolkadotSigner } from 'polkadot-api';
|
|
2
|
+
import { SubmitOptions, Weight, TxResult } from '@parity/product-sdk-tx';
|
|
3
|
+
import { SignerManager } from '@parity/product-sdk-signer';
|
|
4
|
+
|
|
5
|
+
interface CdmJsonTarget {
|
|
6
|
+
"asset-hub": string;
|
|
7
|
+
bulletin: string;
|
|
8
|
+
}
|
|
9
|
+
interface CdmJsonContract {
|
|
10
|
+
version: number;
|
|
11
|
+
address: HexString;
|
|
12
|
+
abi: AbiEntry[];
|
|
13
|
+
metadataCid: string;
|
|
14
|
+
}
|
|
15
|
+
interface CdmJson {
|
|
16
|
+
targets: Record<string, CdmJsonTarget>;
|
|
17
|
+
dependencies: Record<string, Record<string, number | string>>;
|
|
18
|
+
contracts?: Record<string, Record<string, CdmJsonContract>>;
|
|
19
|
+
}
|
|
20
|
+
interface AbiParam {
|
|
21
|
+
name: string;
|
|
22
|
+
type: string;
|
|
23
|
+
components?: AbiParam[];
|
|
24
|
+
}
|
|
25
|
+
interface AbiEntry {
|
|
26
|
+
type: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
inputs: AbiParam[];
|
|
29
|
+
outputs?: AbiParam[];
|
|
30
|
+
stateMutability?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Per-contract definition shape — generated into `.cdm/contracts.d.ts` via module augmentation. */
|
|
33
|
+
interface ContractDef {
|
|
34
|
+
methods: Record<string, {
|
|
35
|
+
args: any[];
|
|
36
|
+
response: any;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Augmentable interface extended by codegen with per-contract method types.
|
|
41
|
+
*
|
|
42
|
+
* After running `cdm install`, a generated `.d.ts` file augments this
|
|
43
|
+
* interface so that `ContractManager.getContract()` returns fully-typed
|
|
44
|
+
* contract handles.
|
|
45
|
+
*/
|
|
46
|
+
interface Contracts {
|
|
47
|
+
}
|
|
48
|
+
/** Result from a read-only contract query. */
|
|
49
|
+
interface QueryResult<T> {
|
|
50
|
+
success: boolean;
|
|
51
|
+
value: T;
|
|
52
|
+
gasRequired?: bigint;
|
|
53
|
+
}
|
|
54
|
+
/** Options for query calls — passed as the last argument after positional args. */
|
|
55
|
+
interface QueryOptions {
|
|
56
|
+
origin?: SS58String;
|
|
57
|
+
value?: bigint;
|
|
58
|
+
}
|
|
59
|
+
/** Options for transaction calls — passed as the last argument after positional args. */
|
|
60
|
+
interface TxOptions extends SubmitOptions {
|
|
61
|
+
signer?: PolkadotSigner;
|
|
62
|
+
origin?: SS58String;
|
|
63
|
+
value?: bigint;
|
|
64
|
+
gasLimit?: Weight;
|
|
65
|
+
storageDepositLimit?: bigint;
|
|
66
|
+
}
|
|
67
|
+
/** Mutable defaults shared across all contract handles from a manager. */
|
|
68
|
+
interface ContractDefaults {
|
|
69
|
+
origin?: SS58String;
|
|
70
|
+
signer?: PolkadotSigner;
|
|
71
|
+
signerManager?: SignerManager;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Options for {@link createContract} and base for {@link ContractManagerOptions}.
|
|
75
|
+
*
|
|
76
|
+
* Signer resolution order (highest wins):
|
|
77
|
+
* 1. Explicit override in call options
|
|
78
|
+
* 2. `signerManager` (current logged-in account)
|
|
79
|
+
* 3. Static `defaultSigner` / `defaultOrigin`
|
|
80
|
+
*/
|
|
81
|
+
interface ContractOptions {
|
|
82
|
+
/**
|
|
83
|
+
* Signer manager from `@parity/product-sdk-signer`. When provided, the
|
|
84
|
+
* currently selected account is used as the default signer and origin
|
|
85
|
+
* for all contract interactions. Resolved at call time so account
|
|
86
|
+
* switches are reflected immediately.
|
|
87
|
+
*/
|
|
88
|
+
signerManager?: SignerManager;
|
|
89
|
+
/** Static fallback caller address for queries. */
|
|
90
|
+
defaultOrigin?: SS58String;
|
|
91
|
+
/** Static fallback signer for transactions. */
|
|
92
|
+
defaultSigner?: PolkadotSigner;
|
|
93
|
+
}
|
|
94
|
+
/** Options for {@link ContractManager} construction. */
|
|
95
|
+
interface ContractManagerOptions extends ContractOptions {
|
|
96
|
+
/** Explicit target hash to select from cdm.json. Defaults to the first target. */
|
|
97
|
+
targetHash?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A typed contract handle where each ABI method exposes `.query()` and `.tx()`.
|
|
101
|
+
*
|
|
102
|
+
* Both accept the method's positional arguments followed by an optional
|
|
103
|
+
* options object as the last argument.
|
|
104
|
+
*/
|
|
105
|
+
type Contract<C extends ContractDef> = {
|
|
106
|
+
[K in keyof C["methods"]]: {
|
|
107
|
+
/**
|
|
108
|
+
* Dry-run the method (read-only). Does not submit a transaction or
|
|
109
|
+
* cost gas. Returns the decoded response and estimated gas required.
|
|
110
|
+
*
|
|
111
|
+
* Origin is resolved from: explicit `{ origin }` option → signerManager →
|
|
112
|
+
* defaultOrigin → dev fallback (Alice).
|
|
113
|
+
*/
|
|
114
|
+
query: (...args: [...C["methods"][K]["args"], opts?: QueryOptions]) => Promise<QueryResult<C["methods"][K]["response"]>>;
|
|
115
|
+
/**
|
|
116
|
+
* Sign, submit, and watch the method as an on-chain transaction.
|
|
117
|
+
* Resolves at best-block by default (configurable via `waitFor`).
|
|
118
|
+
*
|
|
119
|
+
* Signer is resolved from: explicit `{ signer }` option → signerManager →
|
|
120
|
+
* defaultSigner. Throws {@link ContractSignerMissingError} if none available.
|
|
121
|
+
*/
|
|
122
|
+
tx: (...args: [...C["methods"][K]["args"], opts?: TxOptions]) => Promise<TxResult>;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Generate a TypeScript module augmentation that extends the
|
|
128
|
+
* {@link Contracts} interface with typed method signatures for each
|
|
129
|
+
* installed contract.
|
|
130
|
+
*
|
|
131
|
+
* The output is written to `.cdm/contracts.d.ts` (or equivalent) and
|
|
132
|
+
* augments `"@parity/product-sdk-contracts"` so that
|
|
133
|
+
* `ContractManager.getContract()` returns fully-typed handles.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const src = generateContractTypes([
|
|
138
|
+
* { library: "@example/counter", abi },
|
|
139
|
+
* ]);
|
|
140
|
+
* writeFileSync(".cdm/contracts.d.ts", src);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function generateContractTypes(contracts: {
|
|
144
|
+
library: string;
|
|
145
|
+
abi: AbiEntry[];
|
|
146
|
+
}[]): string;
|
|
147
|
+
|
|
148
|
+
export { type AbiEntry as A, type CdmJson as C, type QueryOptions as Q, type TxOptions as T, type ContractManagerOptions as a, type ContractDefaults as b, type Contracts as c, type Contract as d, type ContractDef as e, type ContractOptions as f, type AbiParam as g, type CdmJsonContract as h, type CdmJsonTarget as i, type QueryResult as j, generateContractTypes as k };
|
package/dist/codegen.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { PolkadotClient, HexString } from 'polkadot-api';
|
|
2
|
+
import { InkSdk } from '@polkadot-api/sdk-ink';
|
|
3
|
+
import { C as CdmJson, a as ContractManagerOptions, b as ContractDefaults, c as Contracts, d as Contract, e as ContractDef, A as AbiEntry, f as ContractOptions } from './codegen-Apg73XJX.js';
|
|
4
|
+
export { g as AbiParam, h as CdmJsonContract, i as CdmJsonTarget, Q as QueryOptions, j as QueryResult, T as TxOptions, k as generateContractTypes } from './codegen-Apg73XJX.js';
|
|
5
|
+
export { TxResult } from '@parity/product-sdk-tx';
|
|
6
|
+
import '@parity/product-sdk-signer';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Manages typed contract interactions backed by a `cdm.json` manifest.
|
|
10
|
+
*
|
|
11
|
+
* Pass a `signerManager` (e.g. a `SignerManager` from `@parity/product-sdk-signer`)
|
|
12
|
+
* so the currently logged-in account is used automatically — no manual
|
|
13
|
+
* signer/origin wiring needed.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { createChainClient } from "@parity/product-sdk-chain-client";
|
|
18
|
+
* import { createInkSdk } from "@polkadot-api/sdk-ink";
|
|
19
|
+
* import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
|
|
20
|
+
* import { ContractManager } from "@parity/product-sdk-contracts";
|
|
21
|
+
* import cdmJson from "./cdm.json";
|
|
22
|
+
*
|
|
23
|
+
* const client = await createChainClient({
|
|
24
|
+
* chains: { assetHub: paseo_asset_hub },
|
|
25
|
+
* rpcs: { assetHub: ["wss://sys.ibp.network/asset-hub-paseo"] },
|
|
26
|
+
* });
|
|
27
|
+
* const inkSdk = createInkSdk(client.raw.assetHub, { atBest: true });
|
|
28
|
+
* const manager = new ContractManager(cdmJson, inkSdk, {
|
|
29
|
+
* signerManager: signerManager, // from @parity/product-sdk-signer
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Uses the host's logged-in account automatically
|
|
33
|
+
* const counter = manager.getContract("@example/counter");
|
|
34
|
+
* const { value } = await counter.getCount.query();
|
|
35
|
+
* await counter.increment.tx();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare class ContractManager {
|
|
39
|
+
private cdmJson;
|
|
40
|
+
private targetHash;
|
|
41
|
+
private inkSdk;
|
|
42
|
+
private defaults;
|
|
43
|
+
constructor(cdmJson: CdmJson, inkSdk: InkSdk, options?: ContractManagerOptions);
|
|
44
|
+
/** Update the default origin, signer, or signerManager used by all contract handles. */
|
|
45
|
+
setDefaults(defaults: ContractDefaults): void;
|
|
46
|
+
/**
|
|
47
|
+
* Create a ContractManager from a raw `PolkadotClient`.
|
|
48
|
+
*
|
|
49
|
+
* Convenience factory that creates the InkSdk internally via dynamic import
|
|
50
|
+
* of `@polkadot-api/sdk-ink`. The ~4 MB sdk-ink metadata is loaded lazily
|
|
51
|
+
* only when this method is called.
|
|
52
|
+
*
|
|
53
|
+
* For size-sensitive apps, prefer the constructor with a pre-created `InkSdk`
|
|
54
|
+
* to control exactly when `@polkadot-api/sdk-ink` is loaded.
|
|
55
|
+
*
|
|
56
|
+
* @param cdmJson - The CDM manifest.
|
|
57
|
+
* @param client - A `PolkadotClient` for the chain where contracts are deployed (e.g., `client.raw.assetHub`).
|
|
58
|
+
* @param options - Optional configuration (signerManager, defaults).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { createChainClient } from "@parity/product-sdk-chain-client";
|
|
63
|
+
* import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
|
|
64
|
+
* import { ContractManager } from "@parity/product-sdk-contracts";
|
|
65
|
+
*
|
|
66
|
+
* const client = await createChainClient({
|
|
67
|
+
* chains: { assetHub: paseo_asset_hub },
|
|
68
|
+
* rpcs: { assetHub: ["wss://sys.ibp.network/asset-hub-paseo"] },
|
|
69
|
+
* });
|
|
70
|
+
* const manager = await ContractManager.fromClient(cdmJson, client.raw.assetHub, {
|
|
71
|
+
* signerManager,
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
static fromClient(cdmJson: CdmJson, client: PolkadotClient, options?: ContractManagerOptions): Promise<ContractManager>;
|
|
76
|
+
private getContractData;
|
|
77
|
+
/**
|
|
78
|
+
* Get a typed contract handle.
|
|
79
|
+
*
|
|
80
|
+
* Each method on the returned object has `.query()` for read-only calls
|
|
81
|
+
* and `.tx()` for signed transactions. When codegen augments
|
|
82
|
+
* {@link Contracts}, passing a known library name returns a fully-typed
|
|
83
|
+
* handle. Without codegen the generic overload still works — methods are
|
|
84
|
+
* accessible but untyped.
|
|
85
|
+
*/
|
|
86
|
+
getContract<K extends string & keyof Contracts>(library: K): Contract<Contracts[K]>;
|
|
87
|
+
getContract(library: string): Contract<ContractDef>;
|
|
88
|
+
/** Get the on-chain address of an installed contract. */
|
|
89
|
+
getAddress(library: string): HexString;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a contract handle from a raw address and ABI — no `cdm.json` needed.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { createInkSdk } from "@polkadot-api/sdk-ink";
|
|
97
|
+
*
|
|
98
|
+
* const inkSdk = createInkSdk(client.raw.assetHub, { atBest: true });
|
|
99
|
+
* const counter = createContract(inkSdk, "0xC472...", abi, {
|
|
100
|
+
* signerManager: signerManager,
|
|
101
|
+
* });
|
|
102
|
+
* await counter.getCount.query();
|
|
103
|
+
* await counter.increment.tx();
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function createContract(inkSdk: InkSdk, address: HexString, abi: AbiEntry[], options?: ContractOptions): Contract<ContractDef>;
|
|
107
|
+
/**
|
|
108
|
+
* Create a contract handle from a raw `PolkadotClient`, address, and ABI.
|
|
109
|
+
*
|
|
110
|
+
* Convenience wrapper that creates the InkSdk internally via dynamic import.
|
|
111
|
+
* For size-sensitive apps, use {@link createContract} with a pre-created `InkSdk`.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const counter = await createContractFromClient(client.raw.assetHub, "0xC472...", abi);
|
|
116
|
+
* const { value } = await counter.getCount.query();
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function createContractFromClient(client: PolkadotClient, address: HexString, abi: AbiEntry[], options?: ContractOptions): Promise<Contract<ContractDef>>;
|
|
120
|
+
|
|
121
|
+
/** Base class for all contract errors. Use `instanceof ContractError` to catch any contract-related error. */
|
|
122
|
+
declare class ContractError extends Error {
|
|
123
|
+
constructor(message: string, options?: ErrorOptions);
|
|
124
|
+
}
|
|
125
|
+
/** No signer was available for a transaction call. */
|
|
126
|
+
declare class ContractSignerMissingError extends ContractError {
|
|
127
|
+
constructor();
|
|
128
|
+
}
|
|
129
|
+
/** A contract was not found in the cdm.json manifest. */
|
|
130
|
+
declare class ContractNotFoundError extends ContractError {
|
|
131
|
+
readonly library: string;
|
|
132
|
+
readonly targetHash: string;
|
|
133
|
+
constructor(library: string, targetHash: string);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { AbiEntry, CdmJson, Contract, ContractDef, ContractDefaults, ContractError, ContractManager, ContractManagerOptions, ContractNotFoundError, ContractOptions, ContractSignerMissingError, Contracts, createContract, createContractFromClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateContractTypes
|
|
3
|
+
} from "./chunk-E7AP65D4.js";
|
|
4
|
+
|
|
5
|
+
// src/wrap.ts
|
|
6
|
+
import { submitAndWatch } from "@parity/product-sdk-tx";
|
|
7
|
+
import { seedToAccount } from "@parity/product-sdk-keys";
|
|
8
|
+
import { createLogger } from "@parity/product-sdk-logger";
|
|
9
|
+
import { DEV_PHRASE, ss58Address } from "@polkadot-labs/hdkd-helpers";
|
|
10
|
+
|
|
11
|
+
// src/errors.ts
|
|
12
|
+
var ContractError = class extends Error {
|
|
13
|
+
constructor(message, options) {
|
|
14
|
+
super(message, options);
|
|
15
|
+
this.name = "ContractError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var ContractSignerMissingError = class extends ContractError {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(
|
|
21
|
+
"No signer available. Pass { signer } in call options, set defaultSigner, or provide a signerManager."
|
|
22
|
+
);
|
|
23
|
+
this.name = "ContractSignerMissingError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var ContractNotFoundError = class extends ContractError {
|
|
27
|
+
library;
|
|
28
|
+
targetHash;
|
|
29
|
+
constructor(library, targetHash) {
|
|
30
|
+
super(`Contract "${library}" not found in cdm.json for target ${targetHash}`);
|
|
31
|
+
this.name = "ContractNotFoundError";
|
|
32
|
+
this.library = library;
|
|
33
|
+
this.targetHash = targetHash;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
if (void 0) {
|
|
37
|
+
const { test, expect, describe } = void 0;
|
|
38
|
+
describe("ContractError", () => {
|
|
39
|
+
test("base error has correct name", () => {
|
|
40
|
+
const err = new ContractError("test");
|
|
41
|
+
expect(err.name).toBe("ContractError");
|
|
42
|
+
expect(err).toBeInstanceOf(Error);
|
|
43
|
+
});
|
|
44
|
+
test("instanceof catches all contract errors", () => {
|
|
45
|
+
expect(new ContractSignerMissingError()).toBeInstanceOf(ContractError);
|
|
46
|
+
expect(new ContractNotFoundError("@a/b", "abc")).toBeInstanceOf(ContractError);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("ContractSignerMissingError", () => {
|
|
50
|
+
test("message mentions signer options", () => {
|
|
51
|
+
const err = new ContractSignerMissingError();
|
|
52
|
+
expect(err.message).toContain("signer");
|
|
53
|
+
expect(err.message).toContain("signerManager");
|
|
54
|
+
expect(err.name).toBe("ContractSignerMissingError");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe("ContractNotFoundError", () => {
|
|
58
|
+
test("includes library and target", () => {
|
|
59
|
+
const err = new ContractNotFoundError("@test/foo", "abc123");
|
|
60
|
+
expect(err.library).toBe("@test/foo");
|
|
61
|
+
expect(err.targetHash).toBe("abc123");
|
|
62
|
+
expect(err.message).toContain("@test/foo");
|
|
63
|
+
expect(err.message).toContain("abc123");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/wrap.ts
|
|
69
|
+
var log = createLogger("contracts");
|
|
70
|
+
function buildMethodArgMap(abi) {
|
|
71
|
+
const map = {};
|
|
72
|
+
for (const entry of abi) {
|
|
73
|
+
if (entry.type === "function" && entry.name) {
|
|
74
|
+
map[entry.name] = entry.inputs.map((p) => p.name);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return map;
|
|
78
|
+
}
|
|
79
|
+
function positionalToNamed(argNames, values) {
|
|
80
|
+
const data = {};
|
|
81
|
+
for (let i = 0; i < argNames.length; i++) {
|
|
82
|
+
data[argNames[i]] = values[i];
|
|
83
|
+
}
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
function extractOverrides(argNames, args) {
|
|
87
|
+
if (args.length > argNames.length && args.length > 0) {
|
|
88
|
+
const last = args[args.length - 1];
|
|
89
|
+
if (last && typeof last === "object" && !Array.isArray(last)) {
|
|
90
|
+
return { positionalArgs: args.slice(0, -1), overrides: last };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { positionalArgs: args };
|
|
94
|
+
}
|
|
95
|
+
var QUERY_FALLBACK_ORIGIN = seedToAccount(DEV_PHRASE, "//Alice").ss58Address;
|
|
96
|
+
function resolveOrigin(defaults, override, forQuery) {
|
|
97
|
+
if (override) return override;
|
|
98
|
+
const sourceAddr = defaults.signerManager?.getState().selectedAccount?.address;
|
|
99
|
+
if (sourceAddr) return sourceAddr;
|
|
100
|
+
if (defaults.origin) return defaults.origin;
|
|
101
|
+
if (forQuery) {
|
|
102
|
+
log.warn("No origin configured \u2014 using dev fallback (Alice) for query dry-run");
|
|
103
|
+
return QUERY_FALLBACK_ORIGIN;
|
|
104
|
+
}
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
function resolveSigner(defaults, override) {
|
|
108
|
+
return override ?? defaults.signerManager?.getSigner() ?? defaults.signer;
|
|
109
|
+
}
|
|
110
|
+
function wrapContract(inkContract, abi, defaults) {
|
|
111
|
+
const methodArgs = buildMethodArgMap(abi);
|
|
112
|
+
return new Proxy({}, {
|
|
113
|
+
get(_, methodName) {
|
|
114
|
+
if (typeof methodName !== "string") return void 0;
|
|
115
|
+
const argNames = methodArgs[methodName];
|
|
116
|
+
if (!argNames) return void 0;
|
|
117
|
+
return {
|
|
118
|
+
query: async (...args) => {
|
|
119
|
+
const { positionalArgs, overrides } = extractOverrides(
|
|
120
|
+
argNames,
|
|
121
|
+
args
|
|
122
|
+
);
|
|
123
|
+
const data = positionalToNamed(argNames, positionalArgs);
|
|
124
|
+
const origin = resolveOrigin(defaults, overrides?.origin, true);
|
|
125
|
+
const result = await inkContract.query(methodName, {
|
|
126
|
+
origin,
|
|
127
|
+
data,
|
|
128
|
+
...overrides?.value !== void 0 && { value: overrides.value }
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
success: result.success,
|
|
132
|
+
value: result.success ? result.value.response : void 0,
|
|
133
|
+
gasRequired: result.value?.gasRequired
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
tx: async (...args) => {
|
|
137
|
+
const { positionalArgs, overrides } = extractOverrides(
|
|
138
|
+
argNames,
|
|
139
|
+
args
|
|
140
|
+
);
|
|
141
|
+
const data = positionalToNamed(argNames, positionalArgs);
|
|
142
|
+
const signer = resolveSigner(defaults, overrides?.signer);
|
|
143
|
+
if (!signer) {
|
|
144
|
+
throw new ContractSignerMissingError();
|
|
145
|
+
}
|
|
146
|
+
const origin = resolveOrigin(defaults, overrides?.origin) ?? ss58Address(signer.publicKey);
|
|
147
|
+
const inkTx = inkContract.send(methodName, {
|
|
148
|
+
data,
|
|
149
|
+
origin,
|
|
150
|
+
...overrides?.value !== void 0 && { value: overrides.value },
|
|
151
|
+
...overrides?.gasLimit && { gasLimit: overrides.gasLimit },
|
|
152
|
+
...overrides?.storageDepositLimit !== void 0 && {
|
|
153
|
+
storageDepositLimit: overrides.storageDepositLimit
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return submitAndWatch(inkTx, signer, {
|
|
157
|
+
waitFor: overrides?.waitFor,
|
|
158
|
+
timeoutMs: overrides?.timeoutMs,
|
|
159
|
+
mortalityPeriod: overrides?.mortalityPeriod,
|
|
160
|
+
onStatus: overrides?.onStatus
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (void 0) {
|
|
168
|
+
let mockSigner = function(opts) {
|
|
169
|
+
return {
|
|
170
|
+
getSigner: () => opts.signer ?? null,
|
|
171
|
+
getState: () => ({
|
|
172
|
+
selectedAccount: opts.address ? { address: opts.address } : null
|
|
173
|
+
})
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
mockSigner2 = mockSigner;
|
|
177
|
+
const { test, expect, describe } = void 0;
|
|
178
|
+
describe("buildMethodArgMap", () => {
|
|
179
|
+
test("extracts function parameter names from ABI", () => {
|
|
180
|
+
const abi = [
|
|
181
|
+
{ type: "constructor", inputs: [], stateMutability: "nonpayable" },
|
|
182
|
+
{
|
|
183
|
+
type: "function",
|
|
184
|
+
name: "transfer",
|
|
185
|
+
inputs: [
|
|
186
|
+
{ name: "to", type: "address" },
|
|
187
|
+
{ name: "amount", type: "uint256" }
|
|
188
|
+
],
|
|
189
|
+
outputs: [{ name: "", type: "bool" }]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
type: "function",
|
|
193
|
+
name: "balanceOf",
|
|
194
|
+
inputs: [{ name: "owner", type: "address" }],
|
|
195
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
196
|
+
},
|
|
197
|
+
{ type: "event", name: "Transfer", inputs: [] }
|
|
198
|
+
];
|
|
199
|
+
const map = buildMethodArgMap(abi);
|
|
200
|
+
expect(map).toEqual({
|
|
201
|
+
transfer: ["to", "amount"],
|
|
202
|
+
balanceOf: ["owner"]
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
test("returns empty map for ABI with no functions", () => {
|
|
206
|
+
const abi = [
|
|
207
|
+
{ type: "constructor", inputs: [] },
|
|
208
|
+
{ type: "event", name: "Evt", inputs: [] }
|
|
209
|
+
];
|
|
210
|
+
expect(buildMethodArgMap(abi)).toEqual({});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
describe("positionalToNamed", () => {
|
|
214
|
+
test("maps positional values to named keys", () => {
|
|
215
|
+
expect(positionalToNamed(["a", "b"], [1, 2])).toEqual({ a: 1, b: 2 });
|
|
216
|
+
});
|
|
217
|
+
test("handles empty args", () => {
|
|
218
|
+
expect(positionalToNamed([], [])).toEqual({});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
describe("extractOverrides", () => {
|
|
222
|
+
test("returns overrides when extra object arg is present", () => {
|
|
223
|
+
const result = extractOverrides(["a"], [42, { origin: "0x1" }]);
|
|
224
|
+
expect(result.positionalArgs).toEqual([42]);
|
|
225
|
+
expect(result.overrides).toEqual({ origin: "0x1" });
|
|
226
|
+
});
|
|
227
|
+
test("returns no overrides when arg count matches", () => {
|
|
228
|
+
const result = extractOverrides(["a", "b"], [1, 2]);
|
|
229
|
+
expect(result.positionalArgs).toEqual([1, 2]);
|
|
230
|
+
expect(result.overrides).toBeUndefined();
|
|
231
|
+
});
|
|
232
|
+
test("does not treat array as overrides", () => {
|
|
233
|
+
const result = extractOverrides(["a"], [1, [2, 3]]);
|
|
234
|
+
expect(result.positionalArgs).toEqual([1, [2, 3]]);
|
|
235
|
+
expect(result.overrides).toBeUndefined();
|
|
236
|
+
});
|
|
237
|
+
test("does not treat primitive as overrides", () => {
|
|
238
|
+
const result = extractOverrides(["a"], [1, "extra"]);
|
|
239
|
+
expect(result.positionalArgs).toEqual([1, "extra"]);
|
|
240
|
+
expect(result.overrides).toBeUndefined();
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
describe("resolveOrigin", () => {
|
|
244
|
+
test("explicit override wins", () => {
|
|
245
|
+
const defaults = {
|
|
246
|
+
origin: "5Static",
|
|
247
|
+
signerManager: mockSigner({ address: "5Source" })
|
|
248
|
+
};
|
|
249
|
+
expect(resolveOrigin(defaults, "5Override")).toBe("5Override");
|
|
250
|
+
});
|
|
251
|
+
test("signerManager wins over static default", () => {
|
|
252
|
+
const defaults = {
|
|
253
|
+
origin: "5Static",
|
|
254
|
+
signerManager: mockSigner({ address: "5Source" })
|
|
255
|
+
};
|
|
256
|
+
expect(resolveOrigin(defaults)).toBe("5Source");
|
|
257
|
+
});
|
|
258
|
+
test("falls back to static default", () => {
|
|
259
|
+
const defaults = { origin: "5Static" };
|
|
260
|
+
expect(resolveOrigin(defaults)).toBe("5Static");
|
|
261
|
+
});
|
|
262
|
+
test("returns undefined when nothing available", () => {
|
|
263
|
+
expect(resolveOrigin({})).toBeUndefined();
|
|
264
|
+
});
|
|
265
|
+
test("skips signerManager when no account selected", () => {
|
|
266
|
+
const defaults = {
|
|
267
|
+
origin: "5Static",
|
|
268
|
+
signerManager: mockSigner({ address: null })
|
|
269
|
+
};
|
|
270
|
+
expect(resolveOrigin(defaults)).toBe("5Static");
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
describe("resolveSigner", () => {
|
|
274
|
+
const fakeSigner = { id: "fake" };
|
|
275
|
+
const sourceSigner = { id: "source" };
|
|
276
|
+
test("explicit override wins", () => {
|
|
277
|
+
const defaults = {
|
|
278
|
+
signer: { id: "static" },
|
|
279
|
+
signerManager: mockSigner({ signer: sourceSigner })
|
|
280
|
+
};
|
|
281
|
+
expect(resolveSigner(defaults, fakeSigner)).toBe(fakeSigner);
|
|
282
|
+
});
|
|
283
|
+
test("signerManager wins over static default", () => {
|
|
284
|
+
const defaults = {
|
|
285
|
+
signer: { id: "static" },
|
|
286
|
+
signerManager: mockSigner({ signer: sourceSigner })
|
|
287
|
+
};
|
|
288
|
+
expect(resolveSigner(defaults)).toBe(sourceSigner);
|
|
289
|
+
});
|
|
290
|
+
test("falls back to static default", () => {
|
|
291
|
+
const defaults = { signer: fakeSigner };
|
|
292
|
+
expect(resolveSigner(defaults)).toBe(fakeSigner);
|
|
293
|
+
});
|
|
294
|
+
test("returns undefined when nothing available", () => {
|
|
295
|
+
expect(resolveSigner({})).toBeUndefined();
|
|
296
|
+
});
|
|
297
|
+
test("skips signerManager when getSigner returns null", () => {
|
|
298
|
+
const defaults = {
|
|
299
|
+
signer: fakeSigner,
|
|
300
|
+
signerManager: mockSigner({})
|
|
301
|
+
};
|
|
302
|
+
expect(resolveSigner(defaults)).toBe(fakeSigner);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
var mockSigner2;
|
|
307
|
+
|
|
308
|
+
// src/manager.ts
|
|
309
|
+
var ContractManager = class _ContractManager {
|
|
310
|
+
cdmJson;
|
|
311
|
+
targetHash;
|
|
312
|
+
inkSdk;
|
|
313
|
+
defaults;
|
|
314
|
+
constructor(cdmJson, inkSdk, options) {
|
|
315
|
+
this.cdmJson = cdmJson;
|
|
316
|
+
this.inkSdk = inkSdk;
|
|
317
|
+
if (options?.targetHash) {
|
|
318
|
+
this.targetHash = options.targetHash;
|
|
319
|
+
} else {
|
|
320
|
+
const targets = Object.keys(cdmJson.targets);
|
|
321
|
+
if (targets.length === 0) throw new Error("No targets found in cdm.json");
|
|
322
|
+
this.targetHash = targets[0];
|
|
323
|
+
}
|
|
324
|
+
this.defaults = {
|
|
325
|
+
signerManager: options?.signerManager,
|
|
326
|
+
origin: options?.defaultOrigin,
|
|
327
|
+
signer: options?.defaultSigner
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/** Update the default origin, signer, or signerManager used by all contract handles. */
|
|
331
|
+
setDefaults(defaults) {
|
|
332
|
+
if (defaults.signerManager !== void 0)
|
|
333
|
+
this.defaults.signerManager = defaults.signerManager;
|
|
334
|
+
if (defaults.origin !== void 0) this.defaults.origin = defaults.origin;
|
|
335
|
+
if (defaults.signer !== void 0) this.defaults.signer = defaults.signer;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Create a ContractManager from a raw `PolkadotClient`.
|
|
339
|
+
*
|
|
340
|
+
* Convenience factory that creates the InkSdk internally via dynamic import
|
|
341
|
+
* of `@polkadot-api/sdk-ink`. The ~4 MB sdk-ink metadata is loaded lazily
|
|
342
|
+
* only when this method is called.
|
|
343
|
+
*
|
|
344
|
+
* For size-sensitive apps, prefer the constructor with a pre-created `InkSdk`
|
|
345
|
+
* to control exactly when `@polkadot-api/sdk-ink` is loaded.
|
|
346
|
+
*
|
|
347
|
+
* @param cdmJson - The CDM manifest.
|
|
348
|
+
* @param client - A `PolkadotClient` for the chain where contracts are deployed (e.g., `client.raw.assetHub`).
|
|
349
|
+
* @param options - Optional configuration (signerManager, defaults).
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* import { createChainClient } from "@parity/product-sdk-chain-client";
|
|
354
|
+
* import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
|
|
355
|
+
* import { ContractManager } from "@parity/product-sdk-contracts";
|
|
356
|
+
*
|
|
357
|
+
* const client = await createChainClient({
|
|
358
|
+
* chains: { assetHub: paseo_asset_hub },
|
|
359
|
+
* rpcs: { assetHub: ["wss://sys.ibp.network/asset-hub-paseo"] },
|
|
360
|
+
* });
|
|
361
|
+
* const manager = await ContractManager.fromClient(cdmJson, client.raw.assetHub, {
|
|
362
|
+
* signerManager,
|
|
363
|
+
* });
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
static async fromClient(cdmJson, client, options) {
|
|
367
|
+
const { createInkSdk } = await import("@polkadot-api/sdk-ink");
|
|
368
|
+
const inkSdk = createInkSdk(client, { atBest: true });
|
|
369
|
+
return new _ContractManager(cdmJson, inkSdk, options);
|
|
370
|
+
}
|
|
371
|
+
getContractData(library) {
|
|
372
|
+
const contractsForTarget = this.cdmJson.contracts?.[this.targetHash];
|
|
373
|
+
if (!contractsForTarget || !(library in contractsForTarget)) {
|
|
374
|
+
throw new ContractNotFoundError(library, this.targetHash);
|
|
375
|
+
}
|
|
376
|
+
return contractsForTarget[library];
|
|
377
|
+
}
|
|
378
|
+
getContract(library) {
|
|
379
|
+
const data = this.getContractData(library);
|
|
380
|
+
const descriptor = { abi: data.abi };
|
|
381
|
+
const inkContract = this.inkSdk.getContract(descriptor, data.address);
|
|
382
|
+
return wrapContract(inkContract, data.abi, this.defaults);
|
|
383
|
+
}
|
|
384
|
+
/** Get the on-chain address of an installed contract. */
|
|
385
|
+
getAddress(library) {
|
|
386
|
+
return this.getContractData(library).address;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
function createContract(inkSdk, address, abi, options) {
|
|
390
|
+
const inkContract = inkSdk.getContract({ abi }, address);
|
|
391
|
+
const defaults = {
|
|
392
|
+
signerManager: options?.signerManager,
|
|
393
|
+
origin: options?.defaultOrigin,
|
|
394
|
+
signer: options?.defaultSigner
|
|
395
|
+
};
|
|
396
|
+
return wrapContract(inkContract, abi, defaults);
|
|
397
|
+
}
|
|
398
|
+
async function createContractFromClient(client, address, abi, options) {
|
|
399
|
+
const { createInkSdk } = await import("@polkadot-api/sdk-ink");
|
|
400
|
+
const inkSdk = createInkSdk(client, { atBest: true });
|
|
401
|
+
return createContract(inkSdk, address, abi, options);
|
|
402
|
+
}
|
|
403
|
+
export {
|
|
404
|
+
ContractError,
|
|
405
|
+
ContractManager,
|
|
406
|
+
ContractNotFoundError,
|
|
407
|
+
ContractSignerMissingError,
|
|
408
|
+
createContract,
|
|
409
|
+
createContractFromClient,
|
|
410
|
+
generateContractTypes
|
|
411
|
+
};
|
|
412
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/wrap.ts","../src/errors.ts","../src/manager.ts"],"sourcesContent":["import type { PolkadotSigner, SS58String } from \"polkadot-api\";\nimport { submitAndWatch } from \"@parity/product-sdk-tx\";\nimport { seedToAccount } from \"@parity/product-sdk-keys\";\nimport { createLogger } from \"@parity/product-sdk-logger\";\nimport { DEV_PHRASE, ss58Address } from \"@polkadot-labs/hdkd-helpers\";\nimport { ContractSignerMissingError } from \"./errors.js\";\nimport type {\n AbiEntry,\n Contract,\n ContractDef,\n ContractDefaults,\n QueryOptions,\n TxOptions,\n} from \"./types.js\";\n\nconst log = createLogger(\"contracts\");\n\n/**\n * Ink SDK contract instance returned by `inkSdk.getContract()`.\n *\n * Typed as `any` because we call `.query()` / `.send()` with runtime method\n * names — the SDK's `ContractSdk<D>` requires compile-time descriptor\n * knowledge that runtime ABIs can't provide.\n */\ntype InkContract = any;\n\n/** Extract method name → ordered parameter names from the ABI. */\nfunction buildMethodArgMap(abi: AbiEntry[]): Record<string, string[]> {\n const map: Record<string, string[]> = {};\n for (const entry of abi) {\n if (entry.type === \"function\" && entry.name) {\n map[entry.name] = entry.inputs.map((p) => p.name);\n }\n }\n return map;\n}\n\n/** Convert positional arguments to a named object matching the ABI parameter names. */\nfunction positionalToNamed(argNames: string[], values: unknown[]): Record<string, unknown> {\n const data: Record<string, unknown> = {};\n for (let i = 0; i < argNames.length; i++) {\n data[argNames[i]] = values[i];\n }\n return data;\n}\n\n/**\n * If the caller passed more arguments than the ABI expects and the last\n * argument is a plain object, treat it as an options override.\n */\nfunction extractOverrides<T>(\n argNames: string[],\n args: unknown[],\n): { positionalArgs: unknown[]; overrides?: T } {\n if (args.length > argNames.length && args.length > 0) {\n const last = args[args.length - 1];\n if (last && typeof last === \"object\" && !Array.isArray(last)) {\n return { positionalArgs: args.slice(0, -1), overrides: last as T };\n }\n }\n return { positionalArgs: args };\n}\n\n/**\n * Dev address (Alice) used as fallback origin for read-only queries when no\n * wallet is connected. Queries are dry-run simulations — the origin only\n * affects gas estimation and is safe to stub.\n *\n * This is a development convenience. In production, the origin is resolved\n * from the signerManager (logged-in account) or an explicit defaultOrigin.\n */\nconst QUERY_FALLBACK_ORIGIN = seedToAccount(DEV_PHRASE, \"//Alice\").ss58Address as SS58String;\n\n/**\n * Resolve the origin address: explicit override → signerManager → static default.\n * For queries, pass `forQuery: true` to enable the dev-address fallback.\n */\nfunction resolveOrigin(\n defaults: ContractDefaults,\n override?: SS58String,\n forQuery?: boolean,\n): SS58String | undefined {\n if (override) return override;\n const sourceAddr = defaults.signerManager?.getState().selectedAccount?.address;\n if (sourceAddr) return sourceAddr as SS58String;\n if (defaults.origin) return defaults.origin;\n if (forQuery) {\n log.warn(\"No origin configured — using dev fallback (Alice) for query dry-run\");\n return QUERY_FALLBACK_ORIGIN;\n }\n return undefined;\n}\n\n/**\n * Resolve the signer: explicit override → signerManager → static default.\n */\nfunction resolveSigner(\n defaults: ContractDefaults,\n override?: PolkadotSigner,\n): PolkadotSigner | undefined {\n return override ?? defaults.signerManager?.getSigner() ?? defaults.signer;\n}\n\n/**\n * Wrap an ink SDK contract instance with a proxy that exposes each ABI\n * method as `{ query, tx }` — converting positional arguments to the\n * named-parameter format the SDK expects.\n */\nexport function wrapContract(\n inkContract: InkContract,\n abi: AbiEntry[],\n defaults: ContractDefaults,\n): Contract<ContractDef> {\n const methodArgs = buildMethodArgMap(abi);\n\n return new Proxy({} as any, {\n get(_, methodName: string) {\n if (typeof methodName !== \"string\") return undefined;\n const argNames = methodArgs[methodName];\n if (!argNames) return undefined;\n\n return {\n query: async (...args: unknown[]) => {\n const { positionalArgs, overrides } = extractOverrides<QueryOptions>(\n argNames,\n args,\n );\n const data = positionalToNamed(argNames, positionalArgs);\n const origin = resolveOrigin(defaults, overrides?.origin, true)!;\n\n const result = await inkContract.query(methodName, {\n origin,\n data,\n ...(overrides?.value !== undefined && { value: overrides.value }),\n });\n return {\n success: result.success,\n value: result.success ? result.value.response : undefined,\n gasRequired: result.value?.gasRequired,\n };\n },\n\n tx: async (...args: unknown[]) => {\n const { positionalArgs, overrides } = extractOverrides<TxOptions>(\n argNames,\n args,\n );\n const data = positionalToNamed(argNames, positionalArgs);\n const signer = resolveSigner(defaults, overrides?.signer);\n if (!signer) {\n throw new ContractSignerMissingError();\n }\n\n const origin =\n resolveOrigin(defaults, overrides?.origin) ??\n (ss58Address(signer.publicKey) as SS58String);\n const inkTx = inkContract.send(methodName, {\n data,\n origin,\n ...(overrides?.value !== undefined && { value: overrides.value }),\n ...(overrides?.gasLimit && { gasLimit: overrides.gasLimit }),\n ...(overrides?.storageDepositLimit !== undefined && {\n storageDepositLimit: overrides.storageDepositLimit,\n }),\n });\n return submitAndWatch(inkTx, signer, {\n waitFor: overrides?.waitFor,\n timeoutMs: overrides?.timeoutMs,\n mortalityPeriod: overrides?.mortalityPeriod,\n onStatus: overrides?.onStatus,\n });\n },\n };\n },\n });\n}\n\nif (import.meta.vitest) {\n const { test, expect, describe } = import.meta.vitest;\n\n describe(\"buildMethodArgMap\", () => {\n test(\"extracts function parameter names from ABI\", () => {\n const abi: AbiEntry[] = [\n { type: \"constructor\", inputs: [], stateMutability: \"nonpayable\" },\n {\n type: \"function\",\n name: \"transfer\",\n inputs: [\n { name: \"to\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\" }],\n },\n {\n type: \"function\",\n name: \"balanceOf\",\n inputs: [{ name: \"owner\", type: \"address\" }],\n outputs: [{ name: \"\", type: \"uint256\" }],\n },\n { type: \"event\", name: \"Transfer\", inputs: [] },\n ];\n const map = buildMethodArgMap(abi);\n expect(map).toEqual({\n transfer: [\"to\", \"amount\"],\n balanceOf: [\"owner\"],\n });\n });\n\n test(\"returns empty map for ABI with no functions\", () => {\n const abi: AbiEntry[] = [\n { type: \"constructor\", inputs: [] },\n { type: \"event\", name: \"Evt\", inputs: [] },\n ];\n expect(buildMethodArgMap(abi)).toEqual({});\n });\n });\n\n describe(\"positionalToNamed\", () => {\n test(\"maps positional values to named keys\", () => {\n expect(positionalToNamed([\"a\", \"b\"], [1, 2])).toEqual({ a: 1, b: 2 });\n });\n\n test(\"handles empty args\", () => {\n expect(positionalToNamed([], [])).toEqual({});\n });\n });\n\n describe(\"extractOverrides\", () => {\n test(\"returns overrides when extra object arg is present\", () => {\n const result = extractOverrides<{ origin: string }>([\"a\"], [42, { origin: \"0x1\" }]);\n expect(result.positionalArgs).toEqual([42]);\n expect(result.overrides).toEqual({ origin: \"0x1\" });\n });\n\n test(\"returns no overrides when arg count matches\", () => {\n const result = extractOverrides([\"a\", \"b\"], [1, 2]);\n expect(result.positionalArgs).toEqual([1, 2]);\n expect(result.overrides).toBeUndefined();\n });\n\n test(\"does not treat array as overrides\", () => {\n const result = extractOverrides([\"a\"], [1, [2, 3]]);\n expect(result.positionalArgs).toEqual([1, [2, 3]]);\n expect(result.overrides).toBeUndefined();\n });\n\n test(\"does not treat primitive as overrides\", () => {\n const result = extractOverrides([\"a\"], [1, \"extra\"]);\n expect(result.positionalArgs).toEqual([1, \"extra\"]);\n expect(result.overrides).toBeUndefined();\n });\n });\n\n /** Build a partial SignerManager mock for tests. */\n function mockSigner(opts: {\n address?: string | null;\n signer?: any;\n }): import(\"@parity/product-sdk-signer\").SignerManager {\n return {\n getSigner: () => opts.signer ?? null,\n getState: () => ({\n selectedAccount: opts.address ? ({ address: opts.address } as any) : null,\n }),\n } as any;\n }\n\n describe(\"resolveOrigin\", () => {\n test(\"explicit override wins\", () => {\n const defaults: ContractDefaults = {\n origin: \"5Static\" as SS58String,\n signerManager: mockSigner({ address: \"5Source\" }),\n };\n expect(resolveOrigin(defaults, \"5Override\" as SS58String)).toBe(\"5Override\");\n });\n\n test(\"signerManager wins over static default\", () => {\n const defaults: ContractDefaults = {\n origin: \"5Static\" as SS58String,\n signerManager: mockSigner({ address: \"5Source\" }),\n };\n expect(resolveOrigin(defaults)).toBe(\"5Source\");\n });\n\n test(\"falls back to static default\", () => {\n const defaults: ContractDefaults = { origin: \"5Static\" as SS58String };\n expect(resolveOrigin(defaults)).toBe(\"5Static\");\n });\n\n test(\"returns undefined when nothing available\", () => {\n expect(resolveOrigin({})).toBeUndefined();\n });\n\n test(\"skips signerManager when no account selected\", () => {\n const defaults: ContractDefaults = {\n origin: \"5Static\" as SS58String,\n signerManager: mockSigner({ address: null }),\n };\n expect(resolveOrigin(defaults)).toBe(\"5Static\");\n });\n });\n\n describe(\"resolveSigner\", () => {\n const fakeSigner = { id: \"fake\" } as any;\n const sourceSigner = { id: \"source\" } as any;\n\n test(\"explicit override wins\", () => {\n const defaults: ContractDefaults = {\n signer: { id: \"static\" } as any,\n signerManager: mockSigner({ signer: sourceSigner }),\n };\n expect(resolveSigner(defaults, fakeSigner)).toBe(fakeSigner);\n });\n\n test(\"signerManager wins over static default\", () => {\n const defaults: ContractDefaults = {\n signer: { id: \"static\" } as any,\n signerManager: mockSigner({ signer: sourceSigner }),\n };\n expect(resolveSigner(defaults)).toBe(sourceSigner);\n });\n\n test(\"falls back to static default\", () => {\n const defaults: ContractDefaults = { signer: fakeSigner };\n expect(resolveSigner(defaults)).toBe(fakeSigner);\n });\n\n test(\"returns undefined when nothing available\", () => {\n expect(resolveSigner({})).toBeUndefined();\n });\n\n test(\"skips signerManager when getSigner returns null\", () => {\n const defaults: ContractDefaults = {\n signer: fakeSigner,\n signerManager: mockSigner({}),\n };\n expect(resolveSigner(defaults)).toBe(fakeSigner);\n });\n });\n}\n","/** Base class for all contract errors. Use `instanceof ContractError` to catch any contract-related error. */\nexport class ContractError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"ContractError\";\n }\n}\n\n/** No signer was available for a transaction call. */\nexport class ContractSignerMissingError extends ContractError {\n constructor() {\n super(\n \"No signer available. Pass { signer } in call options, \" +\n \"set defaultSigner, or provide a signerManager.\",\n );\n this.name = \"ContractSignerMissingError\";\n }\n}\n\n/** A contract was not found in the cdm.json manifest. */\nexport class ContractNotFoundError extends ContractError {\n readonly library: string;\n readonly targetHash: string;\n\n constructor(library: string, targetHash: string) {\n super(`Contract \"${library}\" not found in cdm.json for target ${targetHash}`);\n this.name = \"ContractNotFoundError\";\n this.library = library;\n this.targetHash = targetHash;\n }\n}\n\nif (import.meta.vitest) {\n const { test, expect, describe } = import.meta.vitest;\n\n describe(\"ContractError\", () => {\n test(\"base error has correct name\", () => {\n const err = new ContractError(\"test\");\n expect(err.name).toBe(\"ContractError\");\n expect(err).toBeInstanceOf(Error);\n });\n\n test(\"instanceof catches all contract errors\", () => {\n expect(new ContractSignerMissingError()).toBeInstanceOf(ContractError);\n expect(new ContractNotFoundError(\"@a/b\", \"abc\")).toBeInstanceOf(ContractError);\n });\n });\n\n describe(\"ContractSignerMissingError\", () => {\n test(\"message mentions signer options\", () => {\n const err = new ContractSignerMissingError();\n expect(err.message).toContain(\"signer\");\n expect(err.message).toContain(\"signerManager\");\n expect(err.name).toBe(\"ContractSignerMissingError\");\n });\n });\n\n describe(\"ContractNotFoundError\", () => {\n test(\"includes library and target\", () => {\n const err = new ContractNotFoundError(\"@test/foo\", \"abc123\");\n expect(err.library).toBe(\"@test/foo\");\n expect(err.targetHash).toBe(\"abc123\");\n expect(err.message).toContain(\"@test/foo\");\n expect(err.message).toContain(\"abc123\");\n });\n });\n}\n","import type { HexString, PolkadotClient } from \"polkadot-api\";\nimport type { InkSdk } from \"@polkadot-api/sdk-ink\";\nimport { wrapContract } from \"./wrap.js\";\nimport { ContractNotFoundError } from \"./errors.js\";\nimport type {\n AbiEntry,\n CdmJson,\n CdmJsonContract,\n Contract,\n ContractDef,\n ContractDefaults,\n ContractManagerOptions,\n ContractOptions,\n Contracts,\n} from \"./types.js\";\n\n/**\n * Manages typed contract interactions backed by a `cdm.json` manifest.\n *\n * Pass a `signerManager` (e.g. a `SignerManager` from `@parity/product-sdk-signer`)\n * so the currently logged-in account is used automatically — no manual\n * signer/origin wiring needed.\n *\n * @example\n * ```ts\n * import { createChainClient } from \"@parity/product-sdk-chain-client\";\n * import { createInkSdk } from \"@polkadot-api/sdk-ink\";\n * import { paseo_asset_hub } from \"@parity/product-sdk-descriptors/paseo-asset-hub\";\n * import { ContractManager } from \"@parity/product-sdk-contracts\";\n * import cdmJson from \"./cdm.json\";\n *\n * const client = await createChainClient({\n * chains: { assetHub: paseo_asset_hub },\n * rpcs: { assetHub: [\"wss://sys.ibp.network/asset-hub-paseo\"] },\n * });\n * const inkSdk = createInkSdk(client.raw.assetHub, { atBest: true });\n * const manager = new ContractManager(cdmJson, inkSdk, {\n * signerManager: signerManager, // from @parity/product-sdk-signer\n * });\n *\n * // Uses the host's logged-in account automatically\n * const counter = manager.getContract(\"@example/counter\");\n * const { value } = await counter.getCount.query();\n * await counter.increment.tx();\n * ```\n */\nexport class ContractManager {\n private cdmJson: CdmJson;\n private targetHash: string;\n private inkSdk: InkSdk;\n private defaults: ContractDefaults;\n\n constructor(cdmJson: CdmJson, inkSdk: InkSdk, options?: ContractManagerOptions) {\n this.cdmJson = cdmJson;\n this.inkSdk = inkSdk;\n\n if (options?.targetHash) {\n this.targetHash = options.targetHash;\n } else {\n const targets = Object.keys(cdmJson.targets);\n if (targets.length === 0) throw new Error(\"No targets found in cdm.json\");\n this.targetHash = targets[0];\n }\n\n this.defaults = {\n signerManager: options?.signerManager,\n origin: options?.defaultOrigin,\n signer: options?.defaultSigner,\n };\n }\n\n /** Update the default origin, signer, or signerManager used by all contract handles. */\n setDefaults(defaults: ContractDefaults): void {\n if (defaults.signerManager !== undefined)\n this.defaults.signerManager = defaults.signerManager;\n if (defaults.origin !== undefined) this.defaults.origin = defaults.origin;\n if (defaults.signer !== undefined) this.defaults.signer = defaults.signer;\n }\n\n /**\n * Create a ContractManager from a raw `PolkadotClient`.\n *\n * Convenience factory that creates the InkSdk internally via dynamic import\n * of `@polkadot-api/sdk-ink`. The ~4 MB sdk-ink metadata is loaded lazily\n * only when this method is called.\n *\n * For size-sensitive apps, prefer the constructor with a pre-created `InkSdk`\n * to control exactly when `@polkadot-api/sdk-ink` is loaded.\n *\n * @param cdmJson - The CDM manifest.\n * @param client - A `PolkadotClient` for the chain where contracts are deployed (e.g., `client.raw.assetHub`).\n * @param options - Optional configuration (signerManager, defaults).\n *\n * @example\n * ```ts\n * import { createChainClient } from \"@parity/product-sdk-chain-client\";\n * import { paseo_asset_hub } from \"@parity/product-sdk-descriptors/paseo-asset-hub\";\n * import { ContractManager } from \"@parity/product-sdk-contracts\";\n *\n * const client = await createChainClient({\n * chains: { assetHub: paseo_asset_hub },\n * rpcs: { assetHub: [\"wss://sys.ibp.network/asset-hub-paseo\"] },\n * });\n * const manager = await ContractManager.fromClient(cdmJson, client.raw.assetHub, {\n * signerManager,\n * });\n * ```\n */\n static async fromClient(\n cdmJson: CdmJson,\n client: PolkadotClient,\n options?: ContractManagerOptions,\n ): Promise<ContractManager> {\n const { createInkSdk } = await import(\"@polkadot-api/sdk-ink\");\n const inkSdk = createInkSdk(client, { atBest: true });\n return new ContractManager(cdmJson, inkSdk, options);\n }\n\n private getContractData(library: string): CdmJsonContract {\n const contractsForTarget = this.cdmJson.contracts?.[this.targetHash];\n if (!contractsForTarget || !(library in contractsForTarget)) {\n throw new ContractNotFoundError(library, this.targetHash);\n }\n return contractsForTarget[library];\n }\n\n /**\n * Get a typed contract handle.\n *\n * Each method on the returned object has `.query()` for read-only calls\n * and `.tx()` for signed transactions. When codegen augments\n * {@link Contracts}, passing a known library name returns a fully-typed\n * handle. Without codegen the generic overload still works — methods are\n * accessible but untyped.\n */\n getContract<K extends string & keyof Contracts>(library: K): Contract<Contracts[K]>;\n getContract(library: string): Contract<ContractDef>;\n getContract(library: string): Contract<ContractDef> {\n const data = this.getContractData(library);\n const descriptor = { abi: data.abi };\n const inkContract = this.inkSdk.getContract(descriptor as any, data.address);\n return wrapContract(inkContract, data.abi, this.defaults);\n }\n\n /** Get the on-chain address of an installed contract. */\n getAddress(library: string): HexString {\n return this.getContractData(library).address;\n }\n}\n\n/**\n * Create a contract handle from a raw address and ABI — no `cdm.json` needed.\n *\n * @example\n * ```ts\n * import { createInkSdk } from \"@polkadot-api/sdk-ink\";\n *\n * const inkSdk = createInkSdk(client.raw.assetHub, { atBest: true });\n * const counter = createContract(inkSdk, \"0xC472...\", abi, {\n * signerManager: signerManager,\n * });\n * await counter.getCount.query();\n * await counter.increment.tx();\n * ```\n */\nexport function createContract(\n inkSdk: InkSdk,\n address: HexString,\n abi: AbiEntry[],\n options?: ContractOptions,\n): Contract<ContractDef> {\n const inkContract = inkSdk.getContract({ abi } as any, address);\n const defaults: ContractDefaults = {\n signerManager: options?.signerManager,\n origin: options?.defaultOrigin,\n signer: options?.defaultSigner,\n };\n return wrapContract(inkContract, abi, defaults);\n}\n\n/**\n * Create a contract handle from a raw `PolkadotClient`, address, and ABI.\n *\n * Convenience wrapper that creates the InkSdk internally via dynamic import.\n * For size-sensitive apps, use {@link createContract} with a pre-created `InkSdk`.\n *\n * @example\n * ```ts\n * const counter = await createContractFromClient(client.raw.assetHub, \"0xC472...\", abi);\n * const { value } = await counter.getCount.query();\n * ```\n */\nexport async function createContractFromClient(\n client: PolkadotClient,\n address: HexString,\n abi: AbiEntry[],\n options?: ContractOptions,\n): Promise<Contract<ContractDef>> {\n const { createInkSdk } = await import(\"@polkadot-api/sdk-ink\");\n const inkSdk = createInkSdk(client, { atBest: true });\n return createContract(inkSdk, address, abi, options);\n}\n"],"mappings":";;;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,YAAY,mBAAmB;;;ACHjC,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACrC,YAAY,SAAiB,SAAwB;AACjD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EAChB;AACJ;AAGO,IAAM,6BAAN,cAAyC,cAAc;AAAA,EAC1D,cAAc;AACV;AAAA,MACI;AAAA,IAEJ;AACA,SAAK,OAAO;AAAA,EAChB;AACJ;AAGO,IAAM,wBAAN,cAAoC,cAAc;AAAA,EAC5C;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,YAAoB;AAC7C,UAAM,aAAa,OAAO,sCAAsC,UAAU,EAAE;AAC5E,SAAK,OAAO;AACZ,S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AE,IAAI,GAAU,OAAO;AAC9D,QAAM,WAA6B;AAAA,IAC/B,eAAe,SAAS;AAAA,IACxB,QAAQ,SAAS;AAAA,IACjB,QAAQ,SAAS;AAAA,EACrB;AACA,SAAO,aAAa,aAAa,KAAK,QAAQ;AAClD;AAcA,eAAsB,yBAClB,QACA,SACA,KACA,SAC8B;AAC9B,QAAM,EAAE,aAAa,IAAI,MAAM,OAAO,uBAAuB;AAC7D,QAAM,SAAS,aAAa,QAAQ,EAAE,QAAQ,KAAK,CAAC;AACpD,SAAO,eAAe,QAAQ,SAAS,KAAK,OAAO;AACvD;","names":["mockSigner"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@parity/product-sdk-contracts",
|
|
3
|
+
"description": "Typed contract interactions on Polkadot Asset Hub",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./codegen": {
|
|
14
|
+
"types": "./dist/codegen.d.ts",
|
|
15
|
+
"import": "./dist/codegen.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@polkadot-api/sdk-ink": "^0.6.2",
|
|
27
|
+
"@polkadot-labs/hdkd-helpers": "^0.0.27",
|
|
28
|
+
"polkadot-api": "^1.23.3",
|
|
29
|
+
"@parity/product-sdk-logger": "0.1.0",
|
|
30
|
+
"@parity/product-sdk-signer": "0.1.0",
|
|
31
|
+
"@parity/product-sdk-keys": "0.1.0",
|
|
32
|
+
"@parity/product-sdk-tx": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.4.0",
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vitest": "^3.1.4"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"test": "vitest run"
|
|
43
|
+
}
|
|
44
|
+
}
|