@pezkuwi/api-contract 16.5.5 → 16.5.6

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.
Files changed (234) hide show
  1. package/Abi/index.js +359 -0
  2. package/Abi/toLatestCompatible.js +30 -0
  3. package/Abi/toV1.js +21 -0
  4. package/Abi/toV2.js +27 -0
  5. package/Abi/toV3.js +10 -0
  6. package/Abi/toV4.js +10 -0
  7. package/LICENSE +201 -0
  8. package/README.md +1 -1
  9. package/augment.js +1 -0
  10. package/base/Base.js +40 -0
  11. package/base/Blueprint.js +51 -0
  12. package/base/Code.js +74 -0
  13. package/base/Contract.js +127 -0
  14. package/{src/base/index.ts → base/index.js} +0 -3
  15. package/base/mock.js +38 -0
  16. package/{build/base → base}/util.d.ts +1 -1
  17. package/base/util.js +33 -0
  18. package/bundle-pezkuwi-api-contract.js +1238 -0
  19. package/{src/bundle.ts → bundle.js} +0 -6
  20. package/cjs/Abi/index.d.ts +31 -0
  21. package/cjs/Abi/index.js +363 -0
  22. package/cjs/Abi/toLatestCompatible.d.ts +15 -0
  23. package/cjs/Abi/toLatestCompatible.js +36 -0
  24. package/cjs/Abi/toV1.d.ts +3 -0
  25. package/cjs/Abi/toV1.js +24 -0
  26. package/cjs/Abi/toV2.d.ts +3 -0
  27. package/cjs/Abi/toV2.js +30 -0
  28. package/cjs/Abi/toV3.d.ts +3 -0
  29. package/cjs/Abi/toV3.js +13 -0
  30. package/cjs/Abi/toV4.d.ts +3 -0
  31. package/cjs/Abi/toV4.js +13 -0
  32. package/cjs/augment.d.ts +1 -0
  33. package/cjs/augment.js +3 -0
  34. package/cjs/base/Base.d.ts +13 -0
  35. package/cjs/base/Base.js +44 -0
  36. package/cjs/base/Blueprint.d.ts +24 -0
  37. package/cjs/base/Blueprint.js +57 -0
  38. package/cjs/base/Code.d.ts +22 -0
  39. package/cjs/base/Code.js +80 -0
  40. package/cjs/base/Contract.d.ts +25 -0
  41. package/cjs/base/Contract.js +133 -0
  42. package/cjs/base/index.d.ts +3 -0
  43. package/cjs/base/index.js +14 -0
  44. package/cjs/base/mock.d.ts +3 -0
  45. package/cjs/base/mock.js +41 -0
  46. package/{src/base/types.ts → cjs/base/types.d.ts} +6 -21
  47. package/cjs/base/types.js +2 -0
  48. package/cjs/base/util.d.ts +16 -0
  49. package/cjs/base/util.js +42 -0
  50. package/cjs/bundle.d.ts +4 -0
  51. package/cjs/bundle.js +10 -0
  52. package/cjs/index.js +5 -0
  53. package/cjs/package.json +3 -0
  54. package/cjs/packageDetect.d.ts +1 -0
  55. package/cjs/packageDetect.js +7 -0
  56. package/cjs/packageInfo.js +4 -0
  57. package/cjs/promise/index.js +23 -0
  58. package/cjs/promise/types.js +2 -0
  59. package/cjs/rx/index.js +23 -0
  60. package/cjs/rx/types.js +2 -0
  61. package/cjs/types.js +2 -0
  62. package/cjs/util.js +13 -0
  63. package/index.d.ts +2 -0
  64. package/index.js +2 -0
  65. package/package.json +384 -15
  66. package/packageDetect.d.ts +1 -0
  67. package/{src/packageDetect.ts → packageDetect.js} +0 -8
  68. package/packageInfo.d.ts +6 -0
  69. package/packageInfo.js +1 -0
  70. package/promise/index.d.ts +13 -0
  71. package/promise/index.js +17 -0
  72. package/{src/promise/types.ts → promise/types.d.ts} +0 -4
  73. package/promise/types.js +1 -0
  74. package/rx/index.d.ts +13 -0
  75. package/rx/index.js +17 -0
  76. package/{src/rx/types.ts → rx/types.d.ts} +0 -4
  77. package/rx/types.js +1 -0
  78. package/types.d.ts +79 -0
  79. package/types.js +1 -0
  80. package/util.d.ts +5 -0
  81. package/util.js +10 -0
  82. package/src/Abi/Abi.spec.ts +0 -235
  83. package/src/Abi/index.ts +0 -477
  84. package/src/Abi/toLatestCompatible.spec.ts +0 -219
  85. package/src/Abi/toLatestCompatible.ts +0 -52
  86. package/src/Abi/toV1.ts +0 -35
  87. package/src/Abi/toV2.ts +0 -58
  88. package/src/Abi/toV3.ts +0 -18
  89. package/src/Abi/toV4.ts +0 -21
  90. package/src/augment.ts +0 -4
  91. package/src/base/Base.ts +0 -52
  92. package/src/base/Blueprint.ts +0 -90
  93. package/src/base/Code.spec.ts +0 -47
  94. package/src/base/Code.ts +0 -142
  95. package/src/base/Contract.ts +0 -197
  96. package/src/base/mock.ts +0 -48
  97. package/src/base/util.ts +0 -56
  98. package/src/checkTypes.manual.ts +0 -45
  99. package/src/index.ts +0 -6
  100. package/src/mod.ts +0 -4
  101. package/src/packageInfo.ts +0 -6
  102. package/src/promise/index.ts +0 -28
  103. package/src/rx/index.ts +0 -28
  104. package/src/test/compare/ink_v0_delegator.test.json +0 -47
  105. package/src/test/compare/ink_v0_dns.test.json +0 -232
  106. package/src/test/compare/ink_v0_erc20.test.json +0 -253
  107. package/src/test/compare/ink_v0_erc721.test.json +0 -415
  108. package/src/test/compare/ink_v0_flipper.test.json +0 -9
  109. package/src/test/compare/ink_v0_flipperBundle.test.json +0 -9
  110. package/src/test/compare/ink_v0_incrementer.test.json +0 -9
  111. package/src/test/compare/ink_v0_multisigPlain.test.json +0 -562
  112. package/src/test/compare/ink_v1_flipper.test.json +0 -9
  113. package/src/test/compare/ink_v1_psp22.test.json +0 -531
  114. package/src/test/compare/ink_v2_erc20.test.json +0 -205
  115. package/src/test/compare/ink_v2_flipper.test.json +0 -9
  116. package/src/test/compare/ink_v3_flipper.test.json +0 -9
  117. package/src/test/compare/ink_v3_traitErc20.test.json +0 -205
  118. package/src/test/compare/ink_v4_erc20Contract.test.json +0 -253
  119. package/src/test/compare/ink_v4_erc20Metadata.test.json +0 -253
  120. package/src/test/compare/ink_v4_flipperContract.test.json +0 -155
  121. package/src/test/compare/ink_v4_flipperMetadata.test.json +0 -155
  122. package/src/test/compare/ink_v5_erc20.test.json +0 -370
  123. package/src/test/compare/ink_v5_erc20AnonymousTransferMetadata.test.json +0 -370
  124. package/src/test/compare/ink_v5_erc20Contract.test.json +0 -370
  125. package/src/test/compare/ink_v5_erc20Metadata.test.json +0 -370
  126. package/src/test/compare/ink_v5_flipperContract.test.json +0 -174
  127. package/src/test/compare/ink_v5_flipperMetadata.test.json +0 -174
  128. package/src/test/compare/ink_v6_erc20Contract.test.json +0 -418
  129. package/src/test/compare/ink_v6_erc20Metadata.test.json +0 -418
  130. package/src/test/compare/solang_v0_ints256.test.json +0 -9
  131. package/src/test/compare/user_v0_assetTransfer.test.json +0 -54
  132. package/src/test/compare/user_v0_enumExample.test.json +0 -303
  133. package/src/test/compare/user_v0_recursive.test.json +0 -27
  134. package/src/test/compare/user_v0_withString.test.json +0 -260
  135. package/src/test/compare/user_v3_ask.test.json +0 -71
  136. package/src/test/compare/user_v4_events.test.json +0 -1328
  137. package/src/test/contracts/index.ts +0 -20
  138. package/src/test/contracts/ink/index.ts +0 -13
  139. package/src/test/contracts/ink/v0/accumulator.wasm +0 -0
  140. package/src/test/contracts/ink/v0/adder.wasm +0 -0
  141. package/src/test/contracts/ink/v0/delegator.json +0 -252
  142. package/src/test/contracts/ink/v0/delegator.wasm +0 -0
  143. package/src/test/contracts/ink/v0/dns.json +0 -713
  144. package/src/test/contracts/ink/v0/dns.wasm +0 -0
  145. package/src/test/contracts/ink/v0/erc20.json +0 -704
  146. package/src/test/contracts/ink/v0/erc20.wasm +0 -0
  147. package/src/test/contracts/ink/v0/erc721.json +0 -1197
  148. package/src/test/contracts/ink/v0/erc721.wasm +0 -0
  149. package/src/test/contracts/ink/v0/flipper.contract.json +0 -107
  150. package/src/test/contracts/ink/v0/flipper.json +0 -106
  151. package/src/test/contracts/ink/v0/flipper.wasm +0 -0
  152. package/src/test/contracts/ink/v0/incrementer.json +0 -108
  153. package/src/test/contracts/ink/v0/incrementer.wasm +0 -0
  154. package/src/test/contracts/ink/v0/index.ts +0 -11
  155. package/src/test/contracts/ink/v0/multisig_plain.json +0 -1466
  156. package/src/test/contracts/ink/v0/multisig_plain.wasm +0 -0
  157. package/src/test/contracts/ink/v0/subber.wasm +0 -0
  158. package/src/test/contracts/ink/v0/trait-flipper.json +0 -103
  159. package/src/test/contracts/ink/v0/trait-flipper.wasm +0 -0
  160. package/src/test/contracts/ink/v1/flipper.contract.json +0 -111
  161. package/src/test/contracts/ink/v1/index.ts +0 -6
  162. package/src/test/contracts/ink/v1/psp22_minter_pauser.contract.json +0 -1722
  163. package/src/test/contracts/ink/v2/erc20.contract.json +0 -630
  164. package/src/test/contracts/ink/v2/flipper.contract.json +0 -103
  165. package/src/test/contracts/ink/v2/index.ts +0 -5
  166. package/src/test/contracts/ink/v3/flipper.contract.json +0 -105
  167. package/src/test/contracts/ink/v3/index.ts +0 -6
  168. package/src/test/contracts/ink/v3/trait_erc20.contract.json +0 -631
  169. package/src/test/contracts/ink/v4/erc20.contract.json +0 -1
  170. package/src/test/contracts/ink/v4/erc20.json +0 -821
  171. package/src/test/contracts/ink/v4/erc20.wasm +0 -0
  172. package/src/test/contracts/ink/v4/flipper.contract.json +0 -1
  173. package/src/test/contracts/ink/v4/flipper.json +0 -396
  174. package/src/test/contracts/ink/v4/flipper.wasm +0 -0
  175. package/src/test/contracts/ink/v4/index.ts +0 -7
  176. package/src/test/contracts/ink/v5/erc20.contract.json +0 -1
  177. package/src/test/contracts/ink/v5/erc20.json +0 -1025
  178. package/src/test/contracts/ink/v5/erc20.wasm +0 -0
  179. package/src/test/contracts/ink/v5/erc20_anonymous_transfer.json +0 -1025
  180. package/src/test/contracts/ink/v5/flipper.contract.json +0 -1
  181. package/src/test/contracts/ink/v5/flipper.json +0 -420
  182. package/src/test/contracts/ink/v5/flipper.wasm +0 -0
  183. package/src/test/contracts/ink/v5/index.ts +0 -8
  184. package/src/test/contracts/ink/v6/erc20.contract.json +0 -1
  185. package/src/test/contracts/ink/v6/erc20.json +0 -1081
  186. package/src/test/contracts/ink/v6/erc20.polkavm +0 -0
  187. package/src/test/contracts/ink/v6/index.ts +0 -5
  188. package/src/test/contracts/solang/index.ts +0 -7
  189. package/src/test/contracts/solang/v0/index.ts +0 -4
  190. package/src/test/contracts/solang/v0/ints256.json +0 -113
  191. package/src/test/contracts/solang/v0/ints256.sol +0 -13
  192. package/src/test/contracts/solang/v0/ints256.wasm +0 -0
  193. package/src/test/contracts/user/index.ts +0 -9
  194. package/src/test/contracts/user/v0/assetTransfer.json +0 -299
  195. package/src/test/contracts/user/v0/assetTransfer.wasm +0 -0
  196. package/src/test/contracts/user/v0/enumExample.json +0 -528
  197. package/src/test/contracts/user/v0/enumExample.wasm +0 -0
  198. package/src/test/contracts/user/v0/index.ts +0 -7
  199. package/src/test/contracts/user/v0/recursive.contract.json +0 -1
  200. package/src/test/contracts/user/v0/withString.json +0 -777
  201. package/src/test/contracts/user/v3/ask.json +0 -550
  202. package/src/test/contracts/user/v3/index.ts +0 -4
  203. package/src/test/contracts/user/v4/events.contract.json +0 -2990
  204. package/src/test/contracts/user/v4/index.ts +0 -4
  205. package/src/test/contracts/util.ts +0 -14
  206. package/src/types.ts +0 -98
  207. package/src/util.ts +0 -20
  208. package/tsconfig.build.json +0 -22
  209. package/tsconfig.build.tsbuildinfo +0 -1
  210. package/tsconfig.spec.json +0 -26
  211. /package/{build/Abi → Abi}/index.d.ts +0 -0
  212. /package/{build/Abi → Abi}/toLatestCompatible.d.ts +0 -0
  213. /package/{build/Abi → Abi}/toV1.d.ts +0 -0
  214. /package/{build/Abi → Abi}/toV2.d.ts +0 -0
  215. /package/{build/Abi → Abi}/toV3.d.ts +0 -0
  216. /package/{build/Abi → Abi}/toV4.d.ts +0 -0
  217. /package/{build/augment.d.ts → augment.d.ts} +0 -0
  218. /package/{build/base → base}/Base.d.ts +0 -0
  219. /package/{build/base → base}/Blueprint.d.ts +0 -0
  220. /package/{build/base → base}/Code.d.ts +0 -0
  221. /package/{build/base → base}/Contract.d.ts +0 -0
  222. /package/{build/base → base}/index.d.ts +0 -0
  223. /package/{build/base → base}/mock.d.ts +0 -0
  224. /package/{build/base → base}/types.d.ts +0 -0
  225. /package/{build/packageDetect.d.ts → base/types.js} +0 -0
  226. /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
  227. /package/{build → cjs}/index.d.ts +0 -0
  228. /package/{build → cjs}/packageInfo.d.ts +0 -0
  229. /package/{build → cjs}/promise/index.d.ts +0 -0
  230. /package/{build → cjs}/promise/types.d.ts +0 -0
  231. /package/{build → cjs}/rx/index.d.ts +0 -0
  232. /package/{build → cjs}/rx/types.d.ts +0 -0
  233. /package/{build → cjs}/types.d.ts +0 -0
  234. /package/{build → cjs}/util.d.ts +0 -0
@@ -1,219 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
-
6
- import { TypeRegistry } from '@pezkuwi/types';
7
-
8
- import abis from '../test/contracts/index.js';
9
- import { v0ToLatestCompatible, v1ToLatestCompatible, v2ToLatestCompatible, v3ToLatestCompatible, v4ToLatestCompatible, v5ToLatestCompatible, v6ToLatestCompatible } from './toLatestCompatible.js';
10
-
11
- describe('v0ToLatestCompatible', (): void => {
12
- const registry = new TypeRegistry();
13
- const contract = registry.createType('ContractMetadata', { V0: abis['ink_v0_erc20'] });
14
- const latest = v0ToLatestCompatible(registry, contract.asV0);
15
-
16
- it('has the correct constructors', (): void => {
17
- expect(
18
- latest.spec.constructors.map(({ label }) => label.toString())
19
- ).toEqual(['new']);
20
- });
21
-
22
- it('has the correct messages', (): void => {
23
- expect(
24
- latest.spec.messages.map(({ label }) => label.toString())
25
- ).toEqual(['total_supply', 'balance_of', 'allowance', 'transfer', 'approve', 'transfer_from']);
26
- });
27
-
28
- it('has the correct events', (): void => {
29
- expect(
30
- latest.spec.events.map(({ label }) => label.toString())
31
- ).toEqual(['Transfer', 'Approval']);
32
- });
33
-
34
- it('has the correct constructor arguments', (): void => {
35
- expect(
36
- latest.spec.constructors[0].args.map(({ label }) => label.toString())
37
- ).toEqual(['initial_supply']);
38
- });
39
-
40
- it('has the correct message arguments', (): void => {
41
- expect(
42
- latest.spec.messages[1].args.map(({ label }) => label.toString())
43
- ).toEqual(['owner']);
44
- });
45
-
46
- it('has the correct event arguments', (): void => {
47
- expect(
48
- latest.spec.events[0].args.map(({ label }) => label.toString())
49
- ).toEqual(['from', 'to', 'value']);
50
- });
51
-
52
- it('has the latest compatible version number', (): void => {
53
- expect(latest.version.toString()).toEqual('4');
54
- });
55
- });
56
-
57
- describe('v1ToLatestCompatible', (): void => {
58
- const registry = new TypeRegistry();
59
- const contract = registry.createType('ContractMetadata', { V1: abis['ink_v1_flipper']['V1'] });
60
- const latest = v1ToLatestCompatible(registry, contract.asV1);
61
-
62
- it('has the correct constructors', (): void => {
63
- expect(
64
- latest.spec.constructors.map(({ label }) => label.toString())
65
- ).toEqual(['new', 'default']);
66
- });
67
-
68
- it('has the correct messages', (): void => {
69
- expect(
70
- latest.spec.messages.map(({ label }) => label.toString())
71
- ).toEqual(['flip', 'get']);
72
- });
73
-
74
- it('has the correct messages with namespaced method name', (): void => {
75
- const contract = registry.createType('ContractMetadata', { V1: abis['ink_v1_psp22']['V1'] });
76
- const latest = v1ToLatestCompatible(registry, contract.asV1);
77
-
78
- expect(
79
- latest.spec.messages.map(({ label }) => label.toString())
80
- ).toEqual([
81
- 'PSP22Metadata::token_name', 'PSP22Metadata::token_symbol', 'PSP22Metadata::token_decimals', 'PSP22Mintable::mint', 'PSP22::decrease_allowance', 'PSP22::transfer', 'PSP22::approve', 'PSP22::allowance', 'PSP22::transfer_from', 'PSP22::balance_of', 'PSP22::increase_allowance', 'PSP22::total_supply', 'pause', 'unpause'
82
- ]);
83
- });
84
-
85
- it('has the correct constructor arguments', (): void => {
86
- expect(
87
- latest.spec.constructors[0].args.map(({ label }) => label.toString())
88
- ).toEqual(['init_value']);
89
- });
90
-
91
- it('has the latest compatible version number', (): void => {
92
- expect(latest.version.toString()).toEqual('4');
93
- });
94
- });
95
-
96
- describe('v2ToLatestCompatible', (): void => {
97
- const registry = new TypeRegistry();
98
- const contract = registry.createType('ContractMetadata', { V2: abis['ink_v2_flipper']['V2'] });
99
- const latest = v2ToLatestCompatible(registry, contract.asV2);
100
-
101
- it('has the correct constructor flag', (): void => {
102
- expect(
103
- latest.spec.constructors[0].payable.isTrue
104
- ).toEqual(true);
105
- });
106
-
107
- it('has the latest compatible version number', (): void => {
108
- expect(latest.version.toString()).toEqual('4');
109
- });
110
- });
111
-
112
- describe('v3ToLatestCompatible', (): void => {
113
- const registry = new TypeRegistry();
114
- const contract = registry.createType('ContractMetadata', { V3: abis['ink_v3_flipper']['V3'] });
115
- const latest = v3ToLatestCompatible(registry, contract.asV3);
116
-
117
- it('has the correct constructor flags', (): void => {
118
- expect(
119
- latest.spec.constructors[0].payable.isTrue
120
- ).toEqual(false);
121
- expect(
122
- latest.spec.constructors[1].payable.isTrue
123
- ).toEqual(true);
124
- });
125
-
126
- it('has the correct messages', (): void => {
127
- const contract = registry.createType('ContractMetadata', { V3: abis['ink_v3_traitErc20']['V3'] });
128
- const latest = v3ToLatestCompatible(registry, contract.asV3);
129
-
130
- expect(
131
- latest.spec.messages.map(({ label }) => label.toString())
132
- ).toEqual([
133
- 'BaseErc20::total_supply', 'BaseErc20::balance_of', 'BaseErc20::allowance', 'BaseErc20::transfer', 'BaseErc20::approve', 'BaseErc20::transfer_from'
134
- ]);
135
- });
136
-
137
- it('has the latest compatible version number', (): void => {
138
- expect(latest.version.toString()).toEqual('4');
139
- });
140
- });
141
-
142
- describe('v4ToLatestCompatible', (): void => {
143
- const registry = new TypeRegistry();
144
- const contract = registry.createType('ContractMetadata', { V4: abis['ink_v4_flipperContract'] });
145
- const latest = v4ToLatestCompatible(registry, contract.asV4);
146
-
147
- it('has the correct constructor flags', (): void => {
148
- expect(
149
- latest.spec.constructors[0].payable.isTrue
150
- ).toEqual(false);
151
- expect(
152
- latest.spec.constructors[1].payable.isTrue
153
- ).toEqual(false);
154
- });
155
-
156
- it('has the latest compatible version number', (): void => {
157
- expect(latest.version.toString()).toEqual('4');
158
- });
159
- });
160
-
161
- describe('v5ToLatestCompatible', (): void => {
162
- const registry = new TypeRegistry();
163
- const contract = registry.createType('ContractMetadata', { V5: abis['ink_v5_erc20Metadata'] });
164
- const latest = v5ToLatestCompatible(registry, contract.asV5);
165
-
166
- it('has the correct messages', (): void => {
167
- expect(
168
- latest.spec.messages.map(({ label }) => label.toString())
169
- ).toEqual(['total_supply', 'balance_of', 'allowance', 'transfer', 'approve', 'transfer_from']);
170
- });
171
-
172
- it('has new event fields', (): void => {
173
- expect(
174
- latest.spec.events.length
175
- ).toEqual(2);
176
-
177
- expect(
178
- latest.spec.events.every((e) => e.has('module_path'))
179
- ).toEqual(true);
180
-
181
- expect(latest.spec.events[0].module_path.toString()).toEqual('erc20::erc20');
182
-
183
- expect(
184
- latest.spec.events.every((e) => e.has('signature_topic'))
185
- ).toEqual(true);
186
-
187
- expect(latest.spec.events[0].signature_topic.toHex()).toEqual('0xb5b61a3e6a21a16be4f044b517c28ac692492f73c5bfd3f60178ad98c767f4cb');
188
- });
189
-
190
- it('has the latest compatible version number', (): void => {
191
- expect(latest.version.toString()).toEqual('5');
192
- });
193
- });
194
-
195
- describe('v6ToLatestCompatible', (): void => {
196
- const registry = new TypeRegistry();
197
- const contract = registry.createType('ContractMetadata', { V6: abis['ink_v6_erc20Metadata'] });
198
- const latest = v6ToLatestCompatible(registry, contract.asV6);
199
-
200
- it('has the correct messages', (): void => {
201
- expect(
202
- latest.spec.messages.map(({ label }) => label.toString())
203
- ).toEqual(['total_supply', 'balance_of', 'allowance', 'transfer', 'approve', 'transfer_from']);
204
- });
205
-
206
- it('has H160 as the type of balance_of argument', (): void => {
207
- const arg = latest.spec.messages.find(
208
- (m) => m.label.toString() === 'balance_of'
209
- )?.args[0];
210
-
211
- const name = arg?.type.displayName?.[0]?.toString();
212
-
213
- expect(name).toBe('H160');
214
- });
215
-
216
- it('has the latest compatible version number', (): void => {
217
- expect(latest.version.toString()).toEqual('6');
218
- });
219
- });
@@ -1,52 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ContractMetadataV4, ContractMetadataV5, ContractMetadataV6 } from '@pezkuwi/types/interfaces';
5
- import type { Registry } from '@pezkuwi/types/types';
6
- import type { ContractMetadataSupported } from './index.js';
7
-
8
- import { v0ToV1 } from './toV1.js';
9
- import { v1ToV2 } from './toV2.js';
10
- import { v2ToV3 } from './toV3.js';
11
- import { v3ToV4 } from './toV4.js';
12
-
13
- // The versions where an enum is used, aka V0 is missing
14
- // (Order from newest, i.e. we expect more on newest vs oldest)
15
- export const enumVersions = ['V6', 'V5', 'V4', 'V3', 'V2', 'V1'] as const;
16
-
17
- type Versions = typeof enumVersions[number] | 'V0';
18
-
19
- type Converter = (registry: Registry, vx: any) => ContractMetadataSupported;
20
-
21
- // Helper to convert metadata from one step to the next
22
- function createConverter <I, O> (next: (registry: Registry, input: O) => ContractMetadataSupported, step: (registry: Registry, input: I) => O): (registry: Registry, input: I) => ContractMetadataSupported {
23
- return (registry: Registry, input: I): ContractMetadataSupported =>
24
- next(registry, step(registry, input));
25
- }
26
-
27
- export function v6ToLatestCompatible (_registry: Registry, v6: ContractMetadataV6): ContractMetadataV6 {
28
- return v6;
29
- }
30
-
31
- export function v5ToLatestCompatible (_registry: Registry, v5: ContractMetadataV5): ContractMetadataV5 {
32
- return v5;
33
- }
34
-
35
- export function v4ToLatestCompatible (_registry: Registry, v4: ContractMetadataV4): ContractMetadataV4 {
36
- return v4;
37
- }
38
-
39
- export const v3ToLatestCompatible = /*#__PURE__*/ createConverter(v4ToLatestCompatible, v3ToV4);
40
- export const v2ToLatestCompatible = /*#__PURE__*/ createConverter(v3ToLatestCompatible, v2ToV3);
41
- export const v1ToLatestCompatible = /*#__PURE__*/ createConverter(v2ToLatestCompatible, v1ToV2);
42
- export const v0ToLatestCompatible = /*#__PURE__*/ createConverter(v1ToLatestCompatible, v0ToV1);
43
-
44
- export const convertVersions: [Versions, Converter][] = [
45
- ['V6', v6ToLatestCompatible],
46
- ['V5', v5ToLatestCompatible],
47
- ['V4', v4ToLatestCompatible],
48
- ['V3', v3ToLatestCompatible],
49
- ['V2', v2ToLatestCompatible],
50
- ['V1', v1ToLatestCompatible],
51
- ['V0', v0ToLatestCompatible]
52
- ];
package/src/Abi/toV1.ts DELETED
@@ -1,35 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ContractMetadataV0, ContractMetadataV1 } from '@pezkuwi/types/interfaces';
5
- import type { Registry } from '@pezkuwi/types/types';
6
-
7
- import { convertSiV0toV1 } from '@pezkuwi/types';
8
- import { objectSpread } from '@pezkuwi/util';
9
-
10
- interface Named {
11
- name: unknown;
12
- }
13
-
14
- function v0ToV1Names (all: Named[]): unknown[] {
15
- return all.map((e) =>
16
- objectSpread({}, e, {
17
- name: Array.isArray(e.name)
18
- ? e.name
19
- : [e.name]
20
- }));
21
- }
22
-
23
- export function v0ToV1 (registry: Registry, v0: ContractMetadataV0): ContractMetadataV1 {
24
- if (!v0.metadataVersion.length) {
25
- throw new Error('Invalid format for V0 (detected) contract metadata');
26
- }
27
-
28
- return registry.createType('ContractMetadataV1', objectSpread({}, v0, {
29
- spec: objectSpread({}, v0.spec, {
30
- constructors: v0ToV1Names(v0.spec.constructors),
31
- messages: v0ToV1Names(v0.spec.messages)
32
- }),
33
- types: convertSiV0toV1(registry, v0.types)
34
- }));
35
- }
package/src/Abi/toV2.ts DELETED
@@ -1,58 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { Text } from '@pezkuwi/types';
5
- import type { ContractConstructorSpecV0, ContractEventSpecV0, ContractMessageSpecV0, ContractMetadataV1, ContractMetadataV2 } from '@pezkuwi/types/interfaces';
6
- import type { Registry } from '@pezkuwi/types/types';
7
-
8
- import { objectSpread } from '@pezkuwi/util';
9
-
10
- type WithArgs = keyof typeof ARG_TYPES;
11
-
12
- interface NamedEntry {
13
- name: Text | Text[];
14
- }
15
-
16
- type GetArgsType<T extends WithArgs> = T extends 'ContractConstructorSpec'
17
- ? ContractConstructorSpecV0
18
- : T extends ContractEventSpecV0
19
- ? ContractEventSpecV0
20
- : ContractMessageSpecV0;
21
-
22
- interface ArgsEntry <T extends WithArgs> extends NamedEntry {
23
- args: GetArgsType<T>['args'][0][];
24
- }
25
-
26
- const ARG_TYPES = {
27
- ContractConstructorSpec: 'ContractMessageParamSpecV2',
28
- ContractEventSpec: 'ContractEventParamSpecV2',
29
- ContractMessageSpec: 'ContractMessageParamSpecV2'
30
- } as const;
31
-
32
- function v1ToV2Label (entry: NamedEntry): { label: Text } {
33
- return objectSpread({}, entry, {
34
- label: Array.isArray(entry.name)
35
- ? entry.name.join('::')
36
- : entry.name
37
- });
38
- }
39
-
40
- function v1ToV2Labels <T extends WithArgs> (registry: Registry, outType: T, all: ArgsEntry<T>[]): unknown[] {
41
- return all.map((e) =>
42
- registry.createType(`${outType}V2`, objectSpread(v1ToV2Label(e), {
43
- args: e.args.map((a) =>
44
- registry.createType(ARG_TYPES[outType], v1ToV2Label(a))
45
- )
46
- }))
47
- );
48
- }
49
-
50
- export function v1ToV2 (registry: Registry, v1: ContractMetadataV1): ContractMetadataV2 {
51
- return registry.createType('ContractMetadataV2', objectSpread({}, v1, {
52
- spec: objectSpread({}, v1.spec, {
53
- constructors: v1ToV2Labels(registry, 'ContractConstructorSpec', v1.spec.constructors),
54
- events: v1ToV2Labels(registry, 'ContractEventSpec', v1.spec.events),
55
- messages: v1ToV2Labels(registry, 'ContractMessageSpec', v1.spec.messages)
56
- })
57
- }));
58
- }
package/src/Abi/toV3.ts DELETED
@@ -1,18 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ContractMetadataV2, ContractMetadataV3 } from '@pezkuwi/types/interfaces';
5
- import type { Registry } from '@pezkuwi/types/types';
6
-
7
- import { objectSpread } from '@pezkuwi/util';
8
-
9
- export function v2ToV3 (registry: Registry, v2: ContractMetadataV2): ContractMetadataV3 {
10
- return registry.createType('ContractMetadataV3', objectSpread({}, v2, {
11
- spec: objectSpread({}, v2.spec, {
12
- constructors: v2.spec.constructors.map((c) =>
13
- // V3 introduces the payable flag on constructors, for <V3, it is always true
14
- registry.createType('ContractConstructorSpecV3', objectSpread({}, c, { payable: true }))
15
- )
16
- })
17
- }));
18
- }
package/src/Abi/toV4.ts DELETED
@@ -1,21 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ContractMetadataV3, ContractMetadataV4 } from '@pezkuwi/types/interfaces';
5
- import type { Registry } from '@pezkuwi/types/types';
6
-
7
- import { objectSpread } from '@pezkuwi/util';
8
-
9
- export function v3ToV4 (registry: Registry, v3: ContractMetadataV3): ContractMetadataV4 {
10
- return registry.createType('ContractMetadataV4', objectSpread({}, v3, {
11
- spec: objectSpread({}, v3.spec, {
12
- constructors: v3.spec.constructors.map((c) =>
13
- registry.createType('ContractConstructorSpecV4', objectSpread({}, c))
14
- ),
15
- messages: v3.spec.messages.map((m) =>
16
- registry.createType('ContractMessageSpecV3', objectSpread({}, m))
17
- )
18
- }),
19
- version: registry.createType('Text', '4')
20
- }));
21
- }
package/src/augment.ts DELETED
@@ -1,4 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import '@pezkuwi/api-augment';
package/src/base/Base.ts DELETED
@@ -1,52 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ApiBase } from '@pezkuwi/api/base';
5
- import type { ApiTypes, DecorateMethod } from '@pezkuwi/api/types';
6
- import type { WeightV2 } from '@pezkuwi/types/interfaces';
7
- import type { Registry } from '@pezkuwi/types/types';
8
-
9
- import { isFunction } from '@pezkuwi/util';
10
-
11
- import { Abi } from '../Abi/index.js';
12
-
13
- export abstract class Base<ApiType extends ApiTypes> {
14
- readonly abi: Abi;
15
- readonly api: ApiBase<ApiType>;
16
-
17
- protected readonly _decorateMethod: DecorateMethod<ApiType>;
18
- protected readonly _isWeightV1: boolean;
19
- protected readonly _isRevive: boolean;
20
-
21
- constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
22
- if (!api || !api.isConnected || !api.tx) {
23
- throw new Error('Your API has not been initialized correctly and is not connected to a chain');
24
- }
25
-
26
- this.abi = abi instanceof Abi
27
- ? abi
28
- : new Abi(abi, api.registry.getChainProperties());
29
- this.api = api;
30
- this._decorateMethod = decorateMethod;
31
- this._isWeightV1 = !api.registry.createType<WeightV2>('Weight').proofSize;
32
- this._isRevive = this.abi.isRevive;
33
-
34
- if (this._isRevive) {
35
- if (!api.tx.revive || !isFunction(api.tx.revive.instantiateWithCode) || api.tx.revive.instantiateWithCode.meta.args.length !== 6) {
36
- throw new Error('The runtime does not expose api.tx.revive.instantiateWithCode with storageDepositLimit');
37
- } else if (!api.call.reviveApi || !isFunction(api.call.reviveApi.call)) {
38
- throw new Error('Your runtime does not expose the api.call.reviveApi.call runtime interfaces');
39
- }
40
- } else {
41
- if (!api.tx.contracts || !isFunction(api.tx.contracts.instantiateWithCode) || api.tx.contracts.instantiateWithCode.meta.args.length !== 6) {
42
- throw new Error('The runtime does not expose api.tx.contracts.instantiateWithCode with storageDepositLimit');
43
- } else if (!api.call.contractsApi || !isFunction(api.call.contractsApi.call)) {
44
- throw new Error('Your runtime does not expose the api.call.contractsApi.call runtime interfaces');
45
- }
46
- }
47
- }
48
-
49
- public get registry (): Registry {
50
- return this.api.registry;
51
- }
52
- }
@@ -1,90 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ApiBase } from '@pezkuwi/api/base';
5
- import type { SubmittableExtrinsic } from '@pezkuwi/api/submittable/types';
6
- import type { ApiTypes, DecorateMethod } from '@pezkuwi/api/types';
7
- import type { AccountId, EventRecord, Hash } from '@pezkuwi/types/interfaces';
8
- import type { ISubmittableResult } from '@pezkuwi/types/types';
9
- import type { Abi } from '../Abi/index.js';
10
- import type { AbiConstructor, BlueprintOptions } from '../types.js';
11
- import type { MapConstructorExec } from './types.js';
12
-
13
- import { SubmittableResult } from '@pezkuwi/api';
14
- import { BN_ZERO, isUndefined } from '@pezkuwi/util';
15
-
16
- import { applyOnEvent } from '../util.js';
17
- import { Base } from './Base.js';
18
- import { Contract } from './Contract.js';
19
- import { convertWeight, createBluePrintTx, encodeSalt } from './util.js';
20
-
21
- export type BlueprintConstructor<ApiType extends ApiTypes> = new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array) => Blueprint<ApiType>;
22
-
23
- export class BlueprintSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
24
- readonly contract?: Contract<ApiType> | undefined;
25
-
26
- constructor (result: ISubmittableResult, contract?: Contract<ApiType>) {
27
- super(result);
28
-
29
- this.contract = contract;
30
- }
31
- }
32
-
33
- export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
34
- /**
35
- * @description The on-chain code hash for this blueprint
36
- */
37
- readonly codeHash: Hash;
38
-
39
- readonly #tx: MapConstructorExec<ApiType> = {};
40
-
41
- constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) {
42
- super(api, abi, decorateMethod);
43
-
44
- this.codeHash = this.registry.createType('Hash', codeHash);
45
-
46
- this.abi.constructors.forEach((c): void => {
47
- if (isUndefined(this.#tx[c.method])) {
48
- this.#tx[c.method] = createBluePrintTx(c, (o, p) => this.#deploy(c, o, p));
49
- }
50
- });
51
- }
52
-
53
- public get tx (): MapConstructorExec<ApiType> {
54
- return this.#tx;
55
- }
56
-
57
- #deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> => {
58
- const palletTx = this._isRevive
59
- ? this.api.tx.revive
60
- : this.api.tx.contracts;
61
-
62
- return palletTx.instantiate(
63
- value,
64
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
65
- // @ts-ignore jiggle v1 weights, metadata points to latest
66
- this._isWeightV1
67
- ? convertWeight(gasLimit).v1Weight
68
- : convertWeight(gasLimit).v2Weight,
69
- storageDepositLimit,
70
- this.codeHash,
71
- this.abi.findConstructor(constructorOrId).toU8a(params),
72
- encodeSalt(salt)
73
- ).withResultTransform((result: ISubmittableResult) =>
74
- new BlueprintSubmittableResult(result, applyOnEvent(result, ['Instantiated'], ([record]: EventRecord[]) =>
75
- new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod), this._isRevive
76
- )
77
- )
78
- );
79
- };
80
- }
81
-
82
- export function extendBlueprint <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): BlueprintConstructor<ApiType> {
83
- return class extends Blueprint<ApiType> {
84
- static __BlueprintType = type;
85
-
86
- constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array) {
87
- super(api, abi, codeHash, decorateMethod);
88
- }
89
- };
90
- }
@@ -1,47 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
-
6
- import fs from 'node:fs';
7
-
8
- import { toPromiseMethod } from '@pezkuwi/api';
9
-
10
- import v0contractFlipper from '../test/contracts/ink/v0/flipper.contract.json' assert { type: 'json' };
11
- import v0abiFlipper from '../test/contracts/ink/v0/flipper.json' assert { type: 'json' };
12
- import v1contractFlipper from '../test/contracts/ink/v1/flipper.contract.json' assert { type: 'json' };
13
- import v6contractErc20 from '../test/contracts/ink/v6/erc20.contract.json' assert { type: 'json' };
14
- import { Code } from './Code.js';
15
- import { mockApi, mockReviveApi } from './mock.js';
16
-
17
- const v0wasmFlipper = fs.readFileSync(new URL('../test/contracts/ink/v0/flipper.wasm', import.meta.url), 'utf-8');
18
-
19
- describe('Code', (): void => {
20
- it('can construct with an individual ABI/WASM combo', (): void => {
21
- expect(
22
- () => new Code(mockApi, v0abiFlipper as Record<string, unknown>, v0wasmFlipper, toPromiseMethod)
23
- ).not.toThrow();
24
- });
25
-
26
- it('can construct with an .contract ABI (v0)', (): void => {
27
- expect(
28
- () => new Code(mockApi, v0contractFlipper as Record<string, unknown>, null, toPromiseMethod)
29
- ).not.toThrow();
30
- });
31
-
32
- it('can construct with an .contract ABI (v1)', (): void => {
33
- expect(
34
- () => new Code(mockApi, v1contractFlipper as Record<string, unknown>, null, toPromiseMethod)
35
- ).not.toThrow();
36
- });
37
-
38
- it('can construct a revive compatible contract (v6)', (): void => {
39
- expect(
40
- () => new Code(mockApi, v6contractErc20 as Record<string, unknown>, null, toPromiseMethod)
41
- ).toThrow('The runtime does not expose api.tx.revive.instantiateWithCode with storageDepositLimit');
42
-
43
- expect(
44
- () => new Code(mockReviveApi, v6contractErc20 as Record<string, unknown>, null, toPromiseMethod)
45
- ).not.toThrow();
46
- });
47
- });