@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/utils/ensure.js CHANGED
@@ -4,27 +4,35 @@ export const ensureStorageApiSupports = (version) => {
4
4
  const numberedVersion = typeof version === 'number' ? version : parseInt(version);
5
5
  assert(numberedVersion >= 5, `Contract Storage Api Only Available for metadata version >= 5, current version: ${version}`);
6
6
  };
7
- export function ensurePalletPresence(client, registry) {
8
- if (registry.isRevive()) {
9
- try {
10
- !!client.call.reviveApi.call.meta && !!client.tx.revive.call.meta;
11
- }
12
- catch {
13
- throw new DedotError('Pallet Revive is not available');
14
- }
7
+ function ensurePalletRevive(client) {
8
+ try {
9
+ !!client.call.reviveApi.call.meta && !!client.tx.revive.call.meta;
15
10
  }
16
- else {
17
- try {
18
- !!client.call.contractsApi.call.meta && !!client.tx.contracts.call.meta;
19
- }
20
- catch {
21
- throw new DedotError('Pallet Contracts is not available');
22
- }
11
+ catch {
12
+ throw new DedotError('Pallet Revive is not available');
23
13
  }
24
14
  }
25
- export async function ensureContractPresence(client, registry, address) {
15
+ function ensurePalletContracts(client) {
16
+ try {
17
+ !!client.call.contractsApi.call.meta && !!client.tx.contracts.call.meta;
18
+ }
19
+ catch {
20
+ throw new DedotError('Pallet Contracts is not available');
21
+ }
22
+ }
23
+ export function ensurePalletPresence(client, isRevive) {
24
+ isRevive ? ensurePalletRevive(client) : ensurePalletContracts(client);
25
+ }
26
+ export async function ensureContractPresence(client, isRevive, address, cache) {
27
+ // Check cache first if available
28
+ if (cache) {
29
+ const cached = cache.get(`${isRevive}::${address}`);
30
+ if (cached) {
31
+ return; // Contract presence was already verified
32
+ }
33
+ }
26
34
  const contractInfo = await (async () => {
27
- if (registry.isRevive()) {
35
+ if (isRevive) {
28
36
  const accountInfo = await client.query.revive.accountInfoOf(address);
29
37
  if (accountInfo?.accountType && accountInfo?.accountType?.type === 'Contract') {
30
38
  return accountInfo.accountType.value;
@@ -35,17 +43,25 @@ export async function ensureContractPresence(client, registry, address) {
35
43
  }
36
44
  })();
37
45
  ensurePresence(contractInfo, `Contract with address ${address} does not exist on chain!`);
46
+ // Cache successful presence check
47
+ if (cache) {
48
+ cache.set(`${isRevive}::${address}`, true);
49
+ }
38
50
  }
39
- export function ensureValidContractAddress(address, registry) {
40
- if (registry.isRevive()) {
51
+ export function ensureValidContractAddress(address, isRevive) {
52
+ if (isRevive) {
41
53
  assert(isEvmAddress(address), `Invalid contract address: ${address}. Expected an EVM 20-byte address as a hex string or a Uint8Array`);
42
54
  }
43
55
  else {
44
- assert(hexToU8a(accountId32ToHex(address)).length === 32, `Invalid contract address: ${address}. Expected a Substrate 32-byte address as a hex string or a Uint8Array`);
56
+ ensureValidAccountId32Address(address, `Invalid contract address: ${address}. Expected a Substrate 32-byte address as a hex string or a Uint8Array`);
45
57
  }
46
58
  }
47
- export function ensureValidCodeHashOrCode(codeHashOrCode, registry) {
48
- assert(toU8a(codeHashOrCode).length === 32 || (registry.isRevive() ? isPvm(codeHashOrCode) : isWasm(codeHashOrCode)), 'Invalid code hash or code: expected a hash of 32-byte or a valid PVM/WASM code as a hex string or a Uint8Array');
59
+ export function ensureValidAccountId32Address(address, customErrorMessage) {
60
+ assert(hexToU8a(accountId32ToHex(address)).length === 32, customErrorMessage ||
61
+ `Invalid AccountId32 address: ${address}. Expected a Substrate 32-byte address as a hex string or a Uint8Array`);
62
+ }
63
+ export function ensureValidCodeHashOrCode(codeHashOrCode, isRevive) {
64
+ assert(toU8a(codeHashOrCode).length === 32 || (isRevive ? isPvm(codeHashOrCode) : isWasm(codeHashOrCode)), 'Invalid code hash or code: expected a hash of 32-byte or a valid PVM/WASM code as a hex string or a Uint8Array');
49
65
  }
50
66
  const UNSUPPORTED_VERSIONS = ['V3', 'V2', 'V1'];
51
67
  const SUPPORTED_VERSIONS = [6, 5, '4'];
package/utils/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { PortableType, TypeDef } from '@dedot/codecs';
2
- import { ContractMetadata, ContractTypeDef, ReturnFlags } from 'src/types';
1
+ import { AccountId32, Bytes, H160, H256, PortableType, TypeDef } from '@dedot/codecs';
2
+ import { IRuntimeEvent } from '@dedot/codecs/types';
3
+ import { ContractMetadata, ContractTypeDef, ReturnFlags } from '../types/index.js';
3
4
  export declare const extractContractTypes: (contractMetadata: ContractMetadata) => PortableType[];
4
5
  export declare const normalizeContractTypeDef: (def: ContractTypeDef) => TypeDef;
5
6
  export declare function normalizeLabel(label?: string): string;
@@ -15,3 +16,20 @@ export declare enum KnownLazyType {
15
16
  * @param typePath
16
17
  */
17
18
  export declare function isLazyType(typePath?: string | string[] | undefined): KnownLazyType | undefined;
19
+ export type KnownPallets = 'Contracts' | 'Revive';
20
+ export interface ContractEmittedEvent<Pallet extends KnownPallets = 'Contracts'> extends IRuntimeEvent {
21
+ pallet: Pallet;
22
+ palletEvent: {
23
+ name: 'ContractEmitted';
24
+ data: Pallet extends 'Contracts' ? {
25
+ contract: AccountId32;
26
+ data: Bytes;
27
+ } : {
28
+ contract: H160;
29
+ data: Bytes;
30
+ topics: Array<H256>;
31
+ };
32
+ };
33
+ }
34
+ export declare function isInkAbi(metadata: any): boolean;
35
+ export declare function isSolAbi(metadata: any): boolean;
package/utils/types.js CHANGED
@@ -117,3 +117,21 @@ export function isLazyType(typePath) {
117
117
  if (typePath === KNOWN_LAZY_TYPES.STORAGE_VEC)
118
118
  return KnownLazyType.STORAGE_VEC;
119
119
  }
120
+ // https://use.ink/docs/v6/basics/metadata/ink/
121
+ export function isInkAbi(metadata) {
122
+ return (metadata !== null && // --
123
+ 'source' in metadata &&
124
+ 'contract' in metadata &&
125
+ 'spec' in metadata);
126
+ }
127
+ // https://docs.soliditylang.org/en/latest/abi-spec.html#json
128
+ export function isSolAbi(metadata) {
129
+ return (Array.isArray(metadata) &&
130
+ metadata.length > 0 &&
131
+ metadata.some((item) => item.type === 'function' ||
132
+ item.type === 'constructor' ||
133
+ item.type === 'event' ||
134
+ item.type === 'error' ||
135
+ item.type === 'fallback' ||
136
+ item.type === 'receive'));
137
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes