@dedot/contracts 0.17.0 → 0.17.1-next.db98ff20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/Contract.d.ts +5 -4
  2. package/Contract.js +42 -15
  3. package/ContractDeployer.d.ts +5 -4
  4. package/ContractDeployer.js +27 -10
  5. package/SolRegistry.d.ts +22 -0
  6. package/SolRegistry.js +64 -0
  7. package/TypinkRegistry.d.ts +2 -1
  8. package/TypinkRegistry.js +3 -1
  9. package/cjs/Contract.js +43 -16
  10. package/cjs/ContractDeployer.js +25 -8
  11. package/cjs/SolRegistry.js +68 -0
  12. package/cjs/TypinkRegistry.js +2 -0
  13. package/cjs/errors.js +75 -1
  14. package/cjs/executor/index.js +2 -5
  15. package/cjs/executor/{ConstructorQueryExecutor.js → ink/ConstructorQueryExecutor.js} +3 -2
  16. package/cjs/executor/{ConstructorTxExecutor.js → ink/ConstructorTxExecutor.js} +4 -3
  17. package/cjs/executor/{QueryExecutor.js → ink/QueryExecutor.js} +4 -3
  18. package/cjs/executor/{TxExecutor.js → ink/TxExecutor.js} +1 -1
  19. package/cjs/executor/{abstract → ink/abstract}/ContractExecutor.js +1 -1
  20. package/cjs/executor/{abstract → ink/abstract}/DeployerExecutor.js +1 -1
  21. package/cjs/executor/ink/index.js +22 -0
  22. package/cjs/executor/sol/SolConstructorQueryExecutor.js +81 -0
  23. package/cjs/executor/sol/SolConstructorTxExecutor.js +123 -0
  24. package/cjs/executor/sol/SolEventExecutor.js +57 -0
  25. package/cjs/executor/sol/SolQueryExecutor.js +83 -0
  26. package/cjs/executor/sol/SolTxExecutor.js +62 -0
  27. package/cjs/executor/sol/abstract/SolContractExecutor.js +12 -0
  28. package/cjs/executor/sol/abstract/SolDeployerExecutor.js +12 -0
  29. package/cjs/executor/sol/abstract/SolExecutor.js +17 -0
  30. package/cjs/executor/sol/abstract/index.js +19 -0
  31. package/cjs/executor/sol/index.js +22 -0
  32. package/cjs/types/index.js +2 -3
  33. package/cjs/types/ink/index.js +20 -0
  34. package/cjs/types/ink/v6.js +2 -0
  35. package/cjs/types/sol/abi.js +2 -0
  36. package/cjs/types/sol/index.js +17 -0
  37. package/cjs/utils/address.js +2 -2
  38. package/cjs/utils/ensure.js +40 -23
  39. package/cjs/utils/types.js +21 -1
  40. package/errors.d.ts +64 -5
  41. package/errors.js +70 -0
  42. package/executor/index.d.ts +2 -5
  43. package/executor/index.js +2 -5
  44. package/executor/{ConstructorQueryExecutor.d.ts → ink/ConstructorQueryExecutor.d.ts} +1 -2
  45. package/executor/{ConstructorQueryExecutor.js → ink/ConstructorQueryExecutor.js} +3 -2
  46. package/executor/{ConstructorTxExecutor.d.ts → ink/ConstructorTxExecutor.d.ts} +1 -2
  47. package/executor/{ConstructorTxExecutor.js → ink/ConstructorTxExecutor.js} +4 -3
  48. package/executor/{EventExecutor.d.ts → ink/EventExecutor.d.ts} +2 -2
  49. package/executor/{QueryExecutor.d.ts → ink/QueryExecutor.d.ts} +1 -2
  50. package/executor/{QueryExecutor.js → ink/QueryExecutor.js} +4 -3
  51. package/executor/{TxExecutor.d.ts → ink/TxExecutor.d.ts} +1 -2
  52. package/executor/{TxExecutor.js → ink/TxExecutor.js} +1 -1
  53. package/executor/{abstract → ink/abstract}/ContractExecutor.d.ts +2 -2
  54. package/executor/{abstract → ink/abstract}/ContractExecutor.js +1 -1
  55. package/executor/{abstract → ink/abstract}/DeployerExecutor.d.ts +2 -2
  56. package/executor/{abstract → ink/abstract}/DeployerExecutor.js +1 -1
  57. package/executor/{abstract → ink/abstract}/Executor.d.ts +2 -2
  58. package/executor/ink/index.d.ts +6 -0
  59. package/executor/ink/index.js +6 -0
  60. package/executor/sol/SolConstructorQueryExecutor.d.ts +5 -0
  61. package/executor/sol/SolConstructorQueryExecutor.js +77 -0
  62. package/executor/sol/SolConstructorTxExecutor.d.ts +5 -0
  63. package/executor/sol/SolConstructorTxExecutor.js +119 -0
  64. package/executor/sol/SolEventExecutor.d.ts +6 -0
  65. package/executor/sol/SolEventExecutor.js +53 -0
  66. package/executor/sol/SolQueryExecutor.d.ts +5 -0
  67. package/executor/sol/SolQueryExecutor.js +79 -0
  68. package/executor/sol/SolTxExecutor.d.ts +5 -0
  69. package/executor/sol/SolTxExecutor.js +58 -0
  70. package/executor/sol/abstract/SolContractExecutor.d.ts +9 -0
  71. package/executor/sol/abstract/SolContractExecutor.js +8 -0
  72. package/executor/sol/abstract/SolDeployerExecutor.d.ts +11 -0
  73. package/executor/sol/abstract/SolDeployerExecutor.js +8 -0
  74. package/executor/sol/abstract/SolExecutor.d.ts +13 -0
  75. package/executor/sol/abstract/SolExecutor.js +13 -0
  76. package/executor/sol/abstract/index.d.ts +3 -0
  77. package/executor/sol/abstract/index.js +3 -0
  78. package/executor/sol/index.d.ts +6 -0
  79. package/executor/sol/index.js +6 -0
  80. package/package.json +7 -7
  81. package/storage/BaseLazyObject.d.ts +1 -1
  82. package/types/index.d.ts +44 -121
  83. package/types/index.js +2 -3
  84. package/types/ink/index.d.ts +9 -0
  85. package/types/ink/index.js +4 -0
  86. package/types/ink/shared.d.ts +100 -0
  87. package/types/ink/v6.js +1 -0
  88. package/types/shared.d.ts +80 -99
  89. package/types/sol/abi.d.ts +45 -0
  90. package/types/sol/abi.js +1 -0
  91. package/types/sol/index.d.ts +1 -0
  92. package/types/sol/index.js +1 -0
  93. package/utils/address.js +2 -2
  94. package/utils/ensure.d.ts +8 -7
  95. package/utils/ensure.js +38 -22
  96. package/utils/types.d.ts +20 -2
  97. package/utils/types.js +18 -0
  98. /package/cjs/executor/{EventExecutor.js → ink/EventExecutor.js} +0 -0
  99. /package/cjs/executor/{abstract → ink/abstract}/Executor.js +0 -0
  100. /package/cjs/executor/{abstract → ink/abstract}/index.js +0 -0
  101. /package/cjs/types/{v4.js → ink/shared.js} +0 -0
  102. /package/cjs/types/{v5.js → ink/v4.js} +0 -0
  103. /package/cjs/types/{v6.js → ink/v5.js} +0 -0
  104. /package/executor/{EventExecutor.js → ink/EventExecutor.js} +0 -0
  105. /package/executor/{abstract → ink/abstract}/Executor.js +0 -0
  106. /package/executor/{abstract → ink/abstract}/index.d.ts +0 -0
  107. /package/executor/{abstract → ink/abstract}/index.js +0 -0
  108. /package/types/{v4.js → ink/shared.js} +0 -0
  109. /package/types/{v4.d.ts → ink/v4.d.ts} +0 -0
  110. /package/types/{v5.js → ink/v4.js} +0 -0
  111. /package/types/{v5.d.ts → ink/v5.d.ts} +0 -0
  112. /package/types/{v6.js → ink/v5.js} +0 -0
  113. /package/types/{v6.d.ts → ink/v6.d.ts} +0 -0
package/cjs/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isContractInstantiateLangError = exports.isContractInstantiateDispatchError = exports.isContractInstantiateError = exports.isContractLangError = exports.isContractDispatchError = exports.isContractExecutionError = exports.ContractLangError = exports.ContractDispatchError = exports.ContractExecutionError = exports.ContractInstantiateLangError = exports.ContractInstantiateDispatchError = exports.ContractInstantiateError = void 0;
3
+ exports.isSolContractInstantiateError = exports.isSolContractExecutionError = exports.isContractInstantiateLangError = exports.isContractInstantiateDispatchError = exports.isContractInstantiateError = exports.isContractLangError = exports.isContractDispatchError = exports.isContractExecutionError = exports.SolContractExecutionError = exports.SolContractInstantiateError = exports.ContractLangError = exports.ContractDispatchError = exports.ContractExecutionError = exports.ContractInstantiateLangError = exports.ContractInstantiateDispatchError = exports.ContractInstantiateError = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
5
  const index_js_1 = require("./utils/index.js");
6
6
  const formatDispatchError = (err, moduleError) => {
@@ -202,6 +202,52 @@ class ContractLangError extends ContractExecutionError {
202
202
  }
203
203
  }
204
204
  exports.ContractLangError = ContractLangError;
205
+ /**
206
+ * Represents a custom error that occurred during the instantiation of a solidity smart contract.
207
+ * This class extends `ContractInstantiateError` and includes properties for the error name and description.
208
+ *
209
+ * @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
210
+ *
211
+ * @extends ContractInstantiateError
212
+ */
213
+ class SolContractInstantiateError extends ContractInstantiateError {
214
+ name = 'SolContractInstantiateError';
215
+ details;
216
+ constructor(raw, { details, message }) {
217
+ super(raw);
218
+ this.details = details;
219
+ if (message) {
220
+ this.message = message;
221
+ }
222
+ else if (details) {
223
+ this.message = `Error: ${details.errorName}`;
224
+ }
225
+ }
226
+ }
227
+ exports.SolContractInstantiateError = SolContractInstantiateError;
228
+ /**
229
+ * Represents a custom error that occurred during the execution of a smart contract call.
230
+ * This class extends `ContractExecutionError` and includes properties for the error name and description.
231
+ *
232
+ * @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
233
+ *
234
+ * @extends ContractExecutionError
235
+ */
236
+ class SolContractExecutionError extends ContractExecutionError {
237
+ name = 'SolContractExecutionError';
238
+ details;
239
+ constructor(raw, { details, message }) {
240
+ super(raw);
241
+ this.details = details;
242
+ if (message) {
243
+ this.message = message;
244
+ }
245
+ else if (details) {
246
+ this.message = `Error: ${details.errorName}`;
247
+ }
248
+ }
249
+ }
250
+ exports.SolContractExecutionError = SolContractExecutionError;
205
251
  /**
206
252
  * Checks if the provided error is an instance of `ContractExecutionError`.
207
253
  *
@@ -297,3 +343,31 @@ function isContractInstantiateLangError(e) {
297
343
  return e instanceof ContractInstantiateLangError;
298
344
  }
299
345
  exports.isContractInstantiateLangError = isContractInstantiateLangError;
346
+ /**
347
+ * Checks if the provided error is an instance of `isSolContractExecutionError`.
348
+ * This function is used to determine if a given error is a custom error specific to a smart contract.
349
+ *
350
+ * @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
351
+ *
352
+ * @param e - The error to be checked. This should be an instance of `Error`.
353
+ *
354
+ * @returns `true` if the error is an instance of `isSolContractExecutionError`, `false` otherwise.
355
+ */
356
+ function isSolContractExecutionError(e) {
357
+ return e instanceof SolContractExecutionError;
358
+ }
359
+ exports.isSolContractExecutionError = isSolContractExecutionError;
360
+ /**
361
+ * Checks if the provided error is an instance of `SolContractInstantiateError`.
362
+ * This function is used to determine if a given error is a custom error specific to the instantiation of a smart contract.
363
+ *
364
+ * @template ContractApi - The type of the contract API. Defaults to `SolGenericContractApi`.
365
+ *
366
+ * @param e - The error to be checked. This should be an instance of `Error`.
367
+ *
368
+ * @returns `true` if the error is an instance of `SolContractInstantiateError`, `false` otherwise.
369
+ */
370
+ function isSolContractInstantiateError(e) {
371
+ return e instanceof SolContractInstantiateError;
372
+ }
373
+ exports.isSolContractInstantiateError = isSolContractInstantiateError;
@@ -14,8 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./abstract/index.js"), exports);
18
- __exportStar(require("./TxExecutor.js"), exports);
19
- __exportStar(require("./QueryExecutor.js"), exports);
20
- __exportStar(require("./ConstructorTxExecutor.js"), exports);
21
- __exportStar(require("./EventExecutor.js"), exports);
17
+ __exportStar(require("./ink/index.js"), exports);
18
+ __exportStar(require("./sol/index.js"), exports);
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConstructorQueryExecutor = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
- const errors_js_1 = require("../errors.js");
6
- const index_js_1 = require("../utils/index.js");
5
+ const errors_js_1 = require("../../errors.js");
6
+ const index_js_1 = require("../../utils/index.js");
7
7
  const index_js_2 = require("./abstract/index.js");
8
8
  class ConstructorQueryExecutor extends index_js_2.DeployerExecutor {
9
9
  doExecute(constructor) {
@@ -16,6 +16,7 @@ class ConstructorQueryExecutor extends index_js_2.DeployerExecutor {
16
16
  const { caller = this.options.defaultCaller, // --
17
17
  value = 0n, gasLimit, storageDepositLimit, salt, } = callOptions;
18
18
  (0, utils_1.assert)(caller, 'Expected a valid caller address in ConstructorCallOptions');
19
+ (0, index_js_1.ensureValidAccountId32Address)(caller);
19
20
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
20
21
  const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
21
22
  const isUpload = (0, utils_1.isPvm)(this.code) || (0, utils_1.isWasm)(this.code);
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConstructorTxExecutor = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
- const Contract_js_1 = require("../Contract.js");
6
- const index_js_1 = require("../utils/index.js");
5
+ const Contract_js_1 = require("../../Contract.js");
6
+ const index_js_1 = require("../../utils/index.js");
7
7
  const ConstructorQueryExecutor_js_1 = require("./ConstructorQueryExecutor.js");
8
8
  const index_js_2 = require("./abstract/index.js");
9
9
  class ConstructorTxExecutor extends index_js_2.DeployerExecutor {
@@ -108,8 +108,9 @@ class ConstructorTxExecutor extends index_js_2.DeployerExecutor {
108
108
  const contract = async (overrideOptions) => {
109
109
  const address = await contractAddress();
110
110
  // Check if the contract is existed on chain or not!
111
- await (0, index_js_1.ensureContractPresence)(client, this.registry, address);
111
+ await (0, index_js_1.ensureContractPresence)(client, this.registry.isRevive(), address);
112
112
  return new Contract_js_1.Contract(client, // --
113
+ // @ts-ignore
113
114
  this.metadata, address, {
114
115
  defaultCaller: deployerAddress,
115
116
  ...this.options,
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QueryExecutor = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
- const errors_js_1 = require("../errors.js");
6
- const index_js_1 = require("../utils/index.js");
5
+ const errors_js_1 = require("../../errors.js");
6
+ const index_js_1 = require("../../utils/index.js");
7
7
  const index_js_2 = require("./abstract/index.js");
8
8
  class QueryExecutor extends index_js_2.ContractExecutor {
9
9
  doExecute(message) {
@@ -15,10 +15,11 @@ class QueryExecutor extends index_js_2.ContractExecutor {
15
15
  const callOptions = (params[args.length] || {});
16
16
  const { caller = this.options.defaultCaller, value = 0n, gasLimit, storageDepositLimit } = callOptions;
17
17
  (0, utils_1.assert)(caller, 'Expected a valid caller address in ContractCallOptions');
18
+ (0, index_js_1.ensureValidAccountId32Address)(caller);
18
19
  const formattedInputs = args.map((arg, index) => this.tryEncode(arg, params[index]));
19
20
  const bytes = (0, utils_1.u8aToHex)((0, utils_1.concatU8a)((0, utils_1.hexToU8a)(meta.selector), ...formattedInputs));
20
21
  const client = this.client;
21
- await (0, index_js_1.ensureContractPresence)(client, this.registry, this.address);
22
+ await (0, index_js_1.ensureContractPresence)(client, this.registry.isRevive(), this.address, this.registry.cache);
22
23
  const raw = await (async () => {
23
24
  if (this.registry.isRevive()) {
24
25
  const raw = await client.call.reviveApi.call(caller, // --
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TxExecutor = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
- const index_js_1 = require("../utils/index.js");
5
+ const index_js_1 = require("../../utils/index.js");
6
6
  const QueryExecutor_js_1 = require("./QueryExecutor.js");
7
7
  const index_js_2 = require("./abstract/index.js");
8
8
  class TxExecutor extends index_js_2.ContractExecutor {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContractExecutor = void 0;
4
- const index_js_1 = require("../../utils/index.js");
4
+ const index_js_1 = require("../../../utils/index.js");
5
5
  const Executor_js_1 = require("./Executor.js");
6
6
  class ContractExecutor extends Executor_js_1.Executor {
7
7
  address;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeployerExecutor = void 0;
4
- const index_js_1 = require("../../utils/index.js");
4
+ const index_js_1 = require("../../../utils/index.js");
5
5
  const Executor_js_1 = require("./Executor.js");
6
6
  class DeployerExecutor extends Executor_js_1.Executor {
7
7
  code;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./abstract/index.js"), exports);
18
+ __exportStar(require("./TxExecutor.js"), exports);
19
+ __exportStar(require("./QueryExecutor.js"), exports);
20
+ __exportStar(require("./ConstructorTxExecutor.js"), exports);
21
+ __exportStar(require("./ConstructorQueryExecutor.js"), exports);
22
+ __exportStar(require("./EventExecutor.js"), exports);
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolConstructorQueryExecutor = void 0;
4
+ const utils_1 = require("@dedot/utils");
5
+ const utils_2 = require("viem/utils");
6
+ const errors_js_1 = require("../../errors.js");
7
+ const index_js_1 = require("../../utils/index.js");
8
+ const index_js_2 = require("./abstract/index.js");
9
+ class SolConstructorQueryExecutor extends index_js_2.SolDeployerExecutor {
10
+ doExecute(_) {
11
+ const abiConstructor = this.registry.findAbiConstructor();
12
+ const callFn = async (...params) => {
13
+ const { inputs } = abiConstructor;
14
+ (0, index_js_1.ensureParamsLength)(inputs.length, params.length);
15
+ const callOptions = (params[inputs.length] || {});
16
+ const { caller = this.options.defaultCaller, // --
17
+ value = 0n, gasLimit, storageDepositLimit, salt, } = callOptions;
18
+ (0, utils_1.assert)(caller, 'Expected a valid caller address in ConstructorCallOptions');
19
+ (0, index_js_1.ensureValidAccountId32Address)(caller);
20
+ (0, utils_1.assert)((0, utils_1.isUndefined)(salt) || (0, utils_1.toU8a)(salt).byteLength == 32, 'Invalid salt provided in ConstructorCallOptions: expected a 32-byte value as a hex string or a Uint8Array');
21
+ const bytes = (0, utils_2.encodeDeployData)({
22
+ abi: this.abi,
23
+ bytecode: '0x',
24
+ args: params.slice(0, inputs.length),
25
+ });
26
+ const isUpload = (0, utils_1.isPvm)(this.code);
27
+ const code = {
28
+ type: isUpload ? 'Upload' : 'Existing',
29
+ value: this.code,
30
+ };
31
+ const client = this.client;
32
+ const raw = await (async () => {
33
+ const raw = await client.call.reviveApi.instantiate(caller, // --
34
+ value, gasLimit, storageDepositLimit, code, bytes, salt ? (0, utils_1.toHex)(salt) : undefined);
35
+ const result = raw.result;
36
+ if (result.isOk) {
37
+ // @ts-ignore
38
+ result.value.address = result.value.addr;
39
+ // @ts-ignore
40
+ delete result.value.addr;
41
+ }
42
+ return {
43
+ gasConsumed: raw.gasConsumed,
44
+ gasRequired: raw.gasRequired,
45
+ storageDeposit: raw.storageDeposit,
46
+ result,
47
+ };
48
+ })();
49
+ if (raw.result.isErr) {
50
+ const moduleError = client.registry.findErrorMeta(raw.result.err);
51
+ throw new errors_js_1.ContractInstantiateDispatchError(raw.result.err, raw, moduleError);
52
+ }
53
+ const flags = (0, index_js_1.toReturnFlags)(raw.result.value.result.flags.bits);
54
+ const data = raw.result.value.result.data;
55
+ if (flags.revert) {
56
+ let errorResult;
57
+ try {
58
+ errorResult = (0, utils_2.decodeErrorResult)({
59
+ abi: this.abi,
60
+ data,
61
+ });
62
+ }
63
+ catch (e) {
64
+ // TODO make this better, handle panic!, assert! cases
65
+ throw new errors_js_1.SolContractInstantiateError(raw, { message: `Failed to decode error. Details: ${e.message}` });
66
+ }
67
+ throw new errors_js_1.SolContractInstantiateError(raw, { details: errorResult });
68
+ }
69
+ return {
70
+ data: [],
71
+ raw,
72
+ flags,
73
+ address: raw.result.value.address,
74
+ inputData: bytes,
75
+ };
76
+ };
77
+ callFn.meta = abiConstructor;
78
+ return callFn;
79
+ }
80
+ }
81
+ exports.SolConstructorQueryExecutor = SolConstructorQueryExecutor;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolConstructorTxExecutor = void 0;
4
+ const utils_1 = require("@dedot/utils");
5
+ const utils_2 = require("viem/utils");
6
+ const Contract_js_1 = require("../../Contract.js");
7
+ const index_js_1 = require("../../utils/index.js");
8
+ const SolConstructorQueryExecutor_js_1 = require("./SolConstructorQueryExecutor.js");
9
+ const index_js_2 = require("./abstract/index.js");
10
+ class SolConstructorTxExecutor extends index_js_2.SolDeployerExecutor {
11
+ doExecute(_) {
12
+ const abiConstructor = this.registry.findAbiConstructor();
13
+ // @ts-ignore
14
+ const callFn = (...params) => {
15
+ const { inputs } = abiConstructor;
16
+ (0, index_js_1.ensureParamsLength)(inputs.length, params.length);
17
+ const txCallOptions = (params[inputs.length] || {});
18
+ const { value = 0n, gasLimit, storageDepositLimit, salt } = txCallOptions;
19
+ (0, utils_1.assert)((0, utils_1.isUndefined)(salt) || (0, utils_1.toU8a)(salt).byteLength == 32, 'Invalid salt provided in ConstructorCallOptions: expected a 32-byte value as a hex string or a Uint8Array');
20
+ const bytes = (0, utils_2.encodeDeployData)({
21
+ abi: this.abi,
22
+ bytecode: '0x',
23
+ args: params.slice(0, inputs.length),
24
+ });
25
+ const client = this.client;
26
+ const tx = (() => {
27
+ if ((0, utils_1.isPvm)(this.code)) {
28
+ return client.tx.revive.instantiateWithCode(value, gasLimit, storageDepositLimit, this.code, bytes, salt ? (0, utils_1.toHex)(salt) : undefined);
29
+ }
30
+ else {
31
+ return client.tx.revive.instantiate(value, gasLimit, storageDepositLimit, (0, utils_1.toHex)(this.code), bytes, salt ? (0, utils_1.toHex)(salt) : undefined);
32
+ }
33
+ })();
34
+ let deployerAddress, deployerNonce;
35
+ const calculateContractAddress = async (result) => {
36
+ (0, utils_1.assert)(deployerAddress, 'Deployer address Not Found');
37
+ const { status, dispatchError } = result;
38
+ const onChain = status.type === 'BestChainBlockIncluded' || status.type === 'Finalized';
39
+ (0, utils_1.assert)(onChain, 'The deployment transaction has not yet been included in the best chain block or finalized.');
40
+ (0, utils_1.assert)(!dispatchError, 'The deployment transaction failed to execute. Refer to the dispatch error for more information.');
41
+ if (salt) {
42
+ let code;
43
+ if ((0, utils_1.isPvm)(this.code)) {
44
+ code = this.code;
45
+ }
46
+ else {
47
+ // Pull the raw code in case we're using a code hash here
48
+ code = await client.query.revive.pristineCode((0, utils_1.toHex)(this.code));
49
+ }
50
+ (0, utils_1.assert)(code, 'Contract code binary not found');
51
+ return (0, index_js_1.CREATE2)((0, index_js_1.toEvmAddress)(deployerAddress), // --
52
+ code, bytes, salt);
53
+ }
54
+ else {
55
+ return (0, index_js_1.CREATE1)((0, index_js_1.toEvmAddress)(deployerAddress), // --
56
+ deployerNonce);
57
+ }
58
+ };
59
+ tx.withHooks({
60
+ beforeSign: async (tx, signerAddress) => {
61
+ // Set data for next hooks
62
+ deployerAddress = signerAddress;
63
+ if (!salt) {
64
+ deployerNonce = await client.call.accountNonceApi.accountNonce(deployerAddress);
65
+ }
66
+ const callParams = { ...tx.call.palletCall.params };
67
+ const hasGasLimit = !!callParams.gasLimit;
68
+ const hasStorageDepositLimit = !!callParams.storageDepositLimit;
69
+ // Check if current tx provide gas limit and storage deposit limit
70
+ // If not, we need to do a dry run to get the actual value
71
+ const needsDryRun = !hasGasLimit || !hasStorageDepositLimit;
72
+ if (!needsDryRun)
73
+ return;
74
+ const executor = new SolConstructorQueryExecutor_js_1.SolConstructorQueryExecutor(this.client, // --
75
+ this.registry, this.code, {
76
+ defaultCaller: signerAddress,
77
+ ...this.options,
78
+ });
79
+ const { raw: { gasRequired, storageDeposit }, } = await executor.doExecute('new')(...params);
80
+ // Replace the params with gas limit and storage deposit limit
81
+ if (!hasGasLimit) {
82
+ callParams.gasLimit = gasRequired;
83
+ }
84
+ if (!hasStorageDepositLimit) {
85
+ callParams.storageDepositLimit = storageDeposit.value;
86
+ }
87
+ const newCall = { ...tx.call };
88
+ newCall.palletCall.params = callParams;
89
+ tx.call = newCall;
90
+ },
91
+ transformResult: (result) => {
92
+ let cachedAddress;
93
+ const contractAddress = async () => {
94
+ if (cachedAddress)
95
+ return cachedAddress;
96
+ cachedAddress = await calculateContractAddress(result);
97
+ return cachedAddress;
98
+ };
99
+ const contract = async (overrideOptions) => {
100
+ const address = await contractAddress();
101
+ // Check if the contract is existed on chain or not!
102
+ await (0, index_js_1.ensureContractPresence)(client, true, address);
103
+ return new Contract_js_1.Contract(client, // --
104
+ this.abi, address, {
105
+ defaultCaller: deployerAddress,
106
+ ...this.options,
107
+ ...overrideOptions,
108
+ });
109
+ };
110
+ Object.assign(result, {
111
+ contractAddress,
112
+ contract,
113
+ });
114
+ return result;
115
+ },
116
+ });
117
+ return tx;
118
+ };
119
+ callFn.meta = abiConstructor;
120
+ return callFn;
121
+ }
122
+ }
123
+ exports.SolConstructorTxExecutor = SolConstructorTxExecutor;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolEventExecutor = void 0;
4
+ const api_1 = require("@dedot/api");
5
+ const utils_1 = require("@dedot/utils");
6
+ const index_js_1 = require("./abstract/index.js");
7
+ class SolEventExecutor extends index_js_1.SolContractExecutor {
8
+ doExecute(eventName) {
9
+ const abiEvent = this.registry.findAbiEvent(eventName);
10
+ (0, utils_1.assert)(abiEvent, `Abi item not found: ${eventName}`);
11
+ const is = (event) => {
12
+ if ((0, api_1.isEventRecord)(event)) {
13
+ try {
14
+ event = this.registry.decodeEvent(event, this.address);
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
20
+ return event.name === eventName;
21
+ };
22
+ const find = (events) => {
23
+ if (!events || events.length === 0)
24
+ return undefined;
25
+ if ((0, api_1.isEventRecord)(events[0])) {
26
+ return this.registry.decodeEvents(events, this.address).find(is);
27
+ }
28
+ else {
29
+ return events.find(is);
30
+ }
31
+ };
32
+ const filter = (events) => {
33
+ if ((0, api_1.isEventRecord)(events[0])) {
34
+ return this.registry.decodeEvents(events, this.address).filter(is);
35
+ }
36
+ else {
37
+ return events.filter(is);
38
+ }
39
+ };
40
+ const watch = (callback) => {
41
+ return this.client.query.system.events((records) => {
42
+ const events = filter(records);
43
+ if (events.length === 0)
44
+ return;
45
+ callback(filter(records));
46
+ });
47
+ };
48
+ return {
49
+ is,
50
+ find,
51
+ filter,
52
+ meta: abiEvent,
53
+ watch,
54
+ };
55
+ }
56
+ }
57
+ exports.SolEventExecutor = SolEventExecutor;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolQueryExecutor = void 0;
4
+ const utils_1 = require("@dedot/utils");
5
+ const utils_2 = require("viem/utils");
6
+ const errors_js_1 = require("../../errors.js");
7
+ const index_js_1 = require("../../utils/index.js");
8
+ const SolContractExecutor_js_1 = require("./abstract/SolContractExecutor.js");
9
+ class SolQueryExecutor extends SolContractExecutor_js_1.SolContractExecutor {
10
+ doExecute(name) {
11
+ const abiFunction = this.registry.findAbiFunction(name);
12
+ (0, utils_1.assert)(abiFunction, `Abi item not found: ${name}`);
13
+ const callFn = async (...params) => {
14
+ const { inputs } = abiFunction;
15
+ (0, index_js_1.ensureParamsLength)(inputs.length, params.length);
16
+ const callOptions = (params[inputs.length] || {});
17
+ const { caller = this.options.defaultCaller, value = 0n, gasLimit, storageDepositLimit } = callOptions;
18
+ (0, utils_1.assert)(caller, 'Expected a valid caller address in ContractCallOptions');
19
+ (0, index_js_1.ensureValidAccountId32Address)(caller);
20
+ const bytes = (0, utils_2.encodeFunctionData)({
21
+ abi: this.abi,
22
+ functionName: abiFunction.name,
23
+ args: params.slice(0, inputs.length),
24
+ });
25
+ const client = this.client;
26
+ await (0, index_js_1.ensureContractPresence)(client, true, this.address, this.registry.cache);
27
+ const raw = await (async () => {
28
+ const raw = await client.call.reviveApi.call(caller, // --
29
+ this.address, value, gasLimit, storageDepositLimit, bytes);
30
+ return {
31
+ gasConsumed: raw.gasConsumed,
32
+ gasRequired: raw.gasRequired,
33
+ storageDeposit: raw.storageDeposit,
34
+ result: raw.result,
35
+ };
36
+ })();
37
+ if (raw.result.isErr) {
38
+ const moduleError = client.registry.findErrorMeta(raw.result.err);
39
+ throw new errors_js_1.ContractDispatchError(raw.result.err, raw, moduleError);
40
+ }
41
+ const flags = (0, index_js_1.toReturnFlags)(raw.result.value.flags.bits);
42
+ const data = raw.result.value.data;
43
+ if (flags.revert) {
44
+ let errorResult;
45
+ try {
46
+ errorResult = (0, utils_2.decodeErrorResult)({
47
+ abi: this.abi,
48
+ data,
49
+ });
50
+ }
51
+ catch (e) {
52
+ // TODO make this better, handle panic!, assert! cases
53
+ throw new errors_js_1.SolContractExecutionError(raw, { message: `Failed to decode error. Details: ${e.message}` });
54
+ }
55
+ throw new errors_js_1.SolContractExecutionError(raw, { details: errorResult });
56
+ }
57
+ try {
58
+ let decodedData = (0, utils_2.decodeFunctionResult)({
59
+ abi: this.abi,
60
+ functionName: abiFunction.name,
61
+ data,
62
+ });
63
+ // if this is a tx, then this is a dry run, so the data will be default to []
64
+ const isTx = abiFunction.stateMutability === 'payable' || abiFunction.stateMutability === 'nonpayable';
65
+ if (isTx && data === '0x' && decodedData === undefined) {
66
+ decodedData = [];
67
+ }
68
+ return {
69
+ data: decodedData,
70
+ raw,
71
+ flags,
72
+ inputData: bytes,
73
+ };
74
+ }
75
+ catch (e) {
76
+ throw new errors_js_1.SolContractExecutionError(raw, { message: `Failed to decode result. Details: ${e.message}` });
77
+ }
78
+ };
79
+ callFn.meta = abiFunction;
80
+ return callFn;
81
+ }
82
+ }
83
+ exports.SolQueryExecutor = SolQueryExecutor;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolTxExecutor = void 0;
4
+ const utils_1 = require("@dedot/utils");
5
+ const utils_2 = require("viem/utils");
6
+ const index_js_1 = require("../../utils/index.js");
7
+ const SolQueryExecutor_js_1 = require("./SolQueryExecutor.js");
8
+ const SolContractExecutor_js_1 = require("./abstract/SolContractExecutor.js");
9
+ class SolTxExecutor extends SolContractExecutor_js_1.SolContractExecutor {
10
+ doExecute(name) {
11
+ const txAbiFunction = this.registry.findTxAbiFunction(name);
12
+ (0, utils_1.assert)(txAbiFunction, `Abi item not found: ${name}`);
13
+ const callFn = (...params) => {
14
+ const { inputs } = txAbiFunction;
15
+ (0, index_js_1.ensureParamsLength)(inputs.length, params.length);
16
+ const txCallOptions = (params[inputs.length] || {});
17
+ const { value = 0n, gasLimit, storageDepositLimit } = txCallOptions;
18
+ const bytes = (0, utils_2.encodeFunctionData)({
19
+ abi: this.abi,
20
+ functionName: txAbiFunction.name,
21
+ args: params.slice(0, inputs.length),
22
+ });
23
+ const client = this.client;
24
+ const tx = (() => {
25
+ return client.tx.revive.call(this.address, // --
26
+ value, gasLimit, storageDepositLimit || 0n, bytes);
27
+ })();
28
+ tx.withHooks({
29
+ beforeSign: async (tx, signerAddress) => {
30
+ const callParams = { ...tx.call.palletCall.params };
31
+ const hasGasLimit = !!callParams.gasLimit;
32
+ const hasStorageDepositLimit = !!callParams.storageDepositLimit;
33
+ // Check if current tx provide gas limit and storage deposit limit
34
+ // If not, we need to do a dry run to get the actual value
35
+ const needsDryRun = !hasGasLimit || !hasStorageDepositLimit;
36
+ if (!needsDryRun)
37
+ return;
38
+ const executor = new SolQueryExecutor_js_1.SolQueryExecutor(this.client, // --
39
+ this.registry, this.address, {
40
+ defaultCaller: signerAddress,
41
+ ...this.options,
42
+ });
43
+ const { raw } = await executor.doExecute(name)(...params);
44
+ const { gasRequired, storageDeposit } = raw;
45
+ if (!callParams.gasLimit) {
46
+ callParams.gasLimit = gasRequired;
47
+ }
48
+ if (!callParams.storageDepositLimit) {
49
+ callParams.storageDepositLimit = storageDeposit.value;
50
+ }
51
+ const newCall = { ...tx.call };
52
+ newCall.palletCall.params = callParams;
53
+ tx.call = newCall;
54
+ },
55
+ });
56
+ return tx;
57
+ };
58
+ callFn.meta = txAbiFunction;
59
+ return callFn;
60
+ }
61
+ }
62
+ exports.SolTxExecutor = SolTxExecutor;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolContractExecutor = void 0;
4
+ const SolExecutor_js_1 = require("./SolExecutor.js");
5
+ class SolContractExecutor extends SolExecutor_js_1.SolExecutor {
6
+ address;
7
+ constructor(client, registry, address, options) {
8
+ super(client, registry, options);
9
+ this.address = address;
10
+ }
11
+ }
12
+ exports.SolContractExecutor = SolContractExecutor;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolDeployerExecutor = void 0;
4
+ const SolExecutor_js_1 = require("./SolExecutor.js");
5
+ class SolDeployerExecutor extends SolExecutor_js_1.SolExecutor {
6
+ code;
7
+ constructor(client, registry, code, options) {
8
+ super(client, registry, options);
9
+ this.code = code;
10
+ }
11
+ }
12
+ exports.SolDeployerExecutor = SolDeployerExecutor;