dequanto 0.1.21 → 0.1.23

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 (227) hide show
  1. package/lib/cjs/abi/coders/array.js +1 -1
  2. package/lib/cjs/abi/coders/array.js.map +1 -1
  3. package/lib/cjs/chains/arbitrum/Arbiscan.d.ts +1 -1
  4. package/lib/cjs/chains/arbitrum/TokensServiceArbitrum.d.ts +1 -1
  5. package/lib/cjs/chains/boba/Bobascan.d.ts +1 -1
  6. package/lib/cjs/chains/xdai/XDaiscan.d.ts +1 -1
  7. package/lib/cjs/clients/EvmWeb3Client.d.ts +3 -0
  8. package/lib/cjs/clients/EvmWeb3Client.js +23 -4
  9. package/lib/cjs/clients/EvmWeb3Client.js.map +1 -1
  10. package/lib/cjs/clients/Web3Client.d.ts +2 -2
  11. package/lib/cjs/clients/Web3ClientFactory.js +1 -1
  12. package/lib/cjs/clients/Web3ClientFactory.js.map +1 -1
  13. package/lib/cjs/config/ConfigDefaults.js +14 -0
  14. package/lib/cjs/config/ConfigDefaults.js.map +1 -1
  15. package/lib/cjs/contracts/ContractBase.d.ts +1 -0
  16. package/lib/cjs/contracts/ContractBase.js.map +1 -1
  17. package/lib/cjs/contracts/ContractClassFactory.d.ts +2 -1
  18. package/lib/cjs/contracts/ContractClassFactory.js +5 -1
  19. package/lib/cjs/contracts/ContractClassFactory.js.map +1 -1
  20. package/lib/cjs/contracts/deploy/ContractDeployer.d.ts +1 -1
  21. package/lib/cjs/contracts/deploy/Deployments.d.ts +1 -1
  22. package/lib/cjs/contracts/deploy/proxy/ProxyDeployment.d.ts +1 -1
  23. package/lib/cjs/contracts/deploy/storage/DeploymentsStorage.d.ts +1 -1
  24. package/lib/cjs/contracts/deploy/storage/DeploymentsStorage.js +3 -3
  25. package/lib/cjs/contracts/deploy/storage/DeploymentsStorage.js.map +1 -1
  26. package/lib/cjs/erc4337/models/UserOperation.d.ts +1 -1
  27. package/lib/cjs/explorer/BlockChainExplorerFactory.d.ts +1 -1
  28. package/lib/cjs/explorer/BlockChainExplorerProvider.d.ts +1 -1
  29. package/lib/cjs/explorer/Bscscan.d.ts +1 -1
  30. package/lib/cjs/explorer/ContractVerifier.d.ts +1 -1
  31. package/lib/cjs/explorer/ContractVerifier.js.map +1 -1
  32. package/lib/cjs/explorer/Etherscan.d.ts +1 -1
  33. package/lib/cjs/explorer/Polyscan.d.ts +1 -1
  34. package/lib/cjs/gen/GeneratorFromAbi.d.ts +6 -1
  35. package/lib/cjs/gen/GeneratorFromAbi.js +107 -60
  36. package/lib/cjs/gen/GeneratorFromAbi.js.map +1 -1
  37. package/lib/cjs/gen/GeneratorStorageReader.d.ts +1 -0
  38. package/lib/cjs/gen/GeneratorStorageReader.js +13 -1
  39. package/lib/cjs/gen/GeneratorStorageReader.js.map +1 -1
  40. package/lib/cjs/hardhat/HardhatProvider.d.ts +47 -2
  41. package/lib/cjs/hardhat/HardhatProvider.js +169 -92
  42. package/lib/cjs/hardhat/HardhatProvider.js.map +1 -1
  43. package/lib/cjs/json/JsonArrayMultiStore.js +4 -2
  44. package/lib/cjs/json/JsonArrayMultiStore.js.map +1 -1
  45. package/lib/cjs/json/JsonArrayStore.d.ts +2 -2
  46. package/lib/cjs/models/TEth.d.ts +2 -2
  47. package/lib/cjs/ns/providers/EnsProvider.d.ts +2 -2
  48. package/lib/cjs/safe/GnosisSafeFactory.js.map +1 -1
  49. package/lib/cjs/safe/GnosisSafeService.js.map +1 -1
  50. package/lib/cjs/safe/SafeTx.js.map +1 -1
  51. package/lib/cjs/safe/transport/FileServiceTransport.js.map +1 -1
  52. package/lib/cjs/safe/transport/InMemoryServiceTransport.js.map +1 -1
  53. package/lib/cjs/services/TimelockService/TimelockService.d.ts +1 -1
  54. package/lib/cjs/solidity/SlotsStorage.js.map +1 -1
  55. package/lib/cjs/tokens/TokenExchanges/AmmV2ExchangeBase.d.ts +4 -4
  56. package/lib/cjs/tokens/TokenExchanges/AmmV2ExchangeBase.js.map +1 -1
  57. package/lib/cjs/tokens/TokenExchanges/OneInchExchange.js.map +1 -1
  58. package/lib/cjs/tokens/TokenOracles/amm/AmmV1Oracle.js.map +1 -1
  59. package/lib/cjs/tokens/TokenService.js.map +1 -1
  60. package/lib/cjs/tokens/TokensService.d.ts +1 -1
  61. package/lib/cjs/tokens/TokensService.js.map +1 -1
  62. package/lib/cjs/tokens/TokensServiceBsc.d.ts +1 -1
  63. package/lib/cjs/tokens/TokensServicePolygon.d.ts +1 -1
  64. package/lib/cjs/tokens/TokensServiceXDai.d.ts +1 -1
  65. package/lib/cjs/utils/$abiParser.js +8 -1
  66. package/lib/cjs/utils/$abiParser.js.map +1 -1
  67. package/lib/cjs/utils/$bigint.d.ts +4 -0
  68. package/lib/cjs/utils/$bigint.js +40 -0
  69. package/lib/cjs/utils/$bigint.js.map +1 -1
  70. package/lib/cjs/utils/$contract.js +6 -0
  71. package/lib/cjs/utils/$contract.js.map +1 -1
  72. package/lib/cjs/utils/$logger.js +4 -0
  73. package/lib/cjs/utils/$logger.js.map +1 -1
  74. package/lib/cjs/utils/$path.d.ts +6 -0
  75. package/lib/cjs/utils/$path.js +21 -0
  76. package/lib/cjs/utils/$path.js.map +1 -1
  77. package/lib/cjs/utils/$sig.d.ts +3 -0
  78. package/lib/cjs/utils/$sig.js +2 -2
  79. package/lib/cjs/utils/$sig.js.map +1 -1
  80. package/lib/cjs/utils/types.d.ts +3 -0
  81. package/lib/cjs/wallets/Wallet.js.map +1 -1
  82. package/lib/esm/abi/coders/array.js.map +1 -1
  83. package/lib/esm/abi/coders/array.mjs +1 -1
  84. package/lib/esm/chains/arbitrum/Arbiscan.d.ts +1 -1
  85. package/lib/esm/chains/arbitrum/TokensServiceArbitrum.d.ts +1 -1
  86. package/lib/esm/chains/boba/Bobascan.d.ts +1 -1
  87. package/lib/esm/chains/xdai/XDaiscan.d.ts +1 -1
  88. package/lib/esm/clients/EvmWeb3Client.d.ts +3 -0
  89. package/lib/esm/clients/EvmWeb3Client.js.map +1 -1
  90. package/lib/esm/clients/EvmWeb3Client.mjs +21 -3
  91. package/lib/esm/clients/Web3Client.d.ts +2 -2
  92. package/lib/esm/clients/Web3ClientFactory.js.map +1 -1
  93. package/lib/esm/clients/Web3ClientFactory.mjs +1 -1
  94. package/lib/esm/config/ConfigDefaults.js.map +1 -1
  95. package/lib/esm/config/ConfigDefaults.mjs +14 -0
  96. package/lib/esm/contracts/ContractBase.d.ts +1 -0
  97. package/lib/esm/contracts/ContractBase.js.map +1 -1
  98. package/lib/esm/contracts/ContractClassFactory.d.ts +2 -1
  99. package/lib/esm/contracts/ContractClassFactory.js.map +1 -1
  100. package/lib/esm/contracts/ContractClassFactory.mjs +5 -1
  101. package/lib/esm/contracts/deploy/ContractDeployer.d.ts +1 -1
  102. package/lib/esm/contracts/deploy/Deployments.d.ts +1 -1
  103. package/lib/esm/contracts/deploy/proxy/ProxyDeployment.d.ts +1 -1
  104. package/lib/esm/contracts/deploy/storage/DeploymentsStorage.d.ts +1 -1
  105. package/lib/esm/contracts/deploy/storage/DeploymentsStorage.js.map +1 -1
  106. package/lib/esm/contracts/deploy/storage/DeploymentsStorage.mjs +3 -3
  107. package/lib/esm/erc4337/models/UserOperation.d.ts +1 -1
  108. package/lib/esm/explorer/BlockChainExplorerFactory.d.ts +1 -1
  109. package/lib/esm/explorer/BlockChainExplorerProvider.d.ts +1 -1
  110. package/lib/esm/explorer/Bscscan.d.ts +1 -1
  111. package/lib/esm/explorer/ContractVerifier.d.ts +1 -1
  112. package/lib/esm/explorer/ContractVerifier.js.map +1 -1
  113. package/lib/esm/explorer/Etherscan.d.ts +1 -1
  114. package/lib/esm/explorer/Polyscan.d.ts +1 -1
  115. package/lib/esm/gen/GeneratorFromAbi.d.ts +6 -1
  116. package/lib/esm/gen/GeneratorFromAbi.js.map +1 -1
  117. package/lib/esm/gen/GeneratorFromAbi.mjs +107 -60
  118. package/lib/esm/gen/GeneratorStorageReader.d.ts +1 -0
  119. package/lib/esm/gen/GeneratorStorageReader.js.map +1 -1
  120. package/lib/esm/gen/GeneratorStorageReader.mjs +13 -1
  121. package/lib/esm/hardhat/HardhatProvider.d.ts +47 -2
  122. package/lib/esm/hardhat/HardhatProvider.js.map +1 -1
  123. package/lib/esm/hardhat/HardhatProvider.mjs +169 -92
  124. package/lib/esm/json/JsonArrayMultiStore.js.map +1 -1
  125. package/lib/esm/json/JsonArrayMultiStore.mjs +4 -2
  126. package/lib/esm/json/JsonArrayStore.d.ts +2 -2
  127. package/lib/esm/models/TEth.d.ts +2 -2
  128. package/lib/esm/ns/providers/EnsProvider.d.ts +2 -2
  129. package/lib/esm/safe/GnosisSafeFactory.js.map +1 -1
  130. package/lib/esm/safe/GnosisSafeService.js.map +1 -1
  131. package/lib/esm/safe/SafeTx.js.map +1 -1
  132. package/lib/esm/safe/transport/FileServiceTransport.js.map +1 -1
  133. package/lib/esm/safe/transport/InMemoryServiceTransport.js.map +1 -1
  134. package/lib/esm/services/TimelockService/TimelockService.d.ts +1 -1
  135. package/lib/esm/solidity/SlotsStorage.js.map +1 -1
  136. package/lib/esm/tokens/TokenExchanges/AmmV2ExchangeBase.d.ts +4 -4
  137. package/lib/esm/tokens/TokenExchanges/AmmV2ExchangeBase.js.map +1 -1
  138. package/lib/esm/tokens/TokenExchanges/OneInchExchange.js.map +1 -1
  139. package/lib/esm/tokens/TokenOracles/amm/AmmV1Oracle.js.map +1 -1
  140. package/lib/esm/tokens/TokenService.js.map +1 -1
  141. package/lib/esm/tokens/TokensService.d.ts +1 -1
  142. package/lib/esm/tokens/TokensService.js.map +1 -1
  143. package/lib/esm/tokens/TokensServiceBsc.d.ts +1 -1
  144. package/lib/esm/tokens/TokensServicePolygon.d.ts +1 -1
  145. package/lib/esm/tokens/TokensServiceXDai.d.ts +1 -1
  146. package/lib/esm/utils/$abiParser.js.map +1 -1
  147. package/lib/esm/utils/$abiParser.mjs +8 -1
  148. package/lib/esm/utils/$bigint.d.ts +4 -0
  149. package/lib/esm/utils/$bigint.js.map +1 -1
  150. package/lib/esm/utils/$bigint.mjs +40 -0
  151. package/lib/esm/utils/$contract.js.map +1 -1
  152. package/lib/esm/utils/$contract.mjs +6 -0
  153. package/lib/esm/utils/$logger.js.map +1 -1
  154. package/lib/esm/utils/$logger.mjs +4 -0
  155. package/lib/esm/utils/$path.d.ts +6 -0
  156. package/lib/esm/utils/$path.js.map +1 -1
  157. package/lib/esm/utils/$path.mjs +21 -0
  158. package/lib/esm/utils/$sig.d.ts +3 -0
  159. package/lib/esm/utils/$sig.js.map +1 -1
  160. package/lib/esm/utils/$sig.mjs +1 -1
  161. package/lib/esm/utils/types.d.ts +3 -0
  162. package/lib/esm/wallets/Wallet.js.map +1 -1
  163. package/package.json +4 -3
  164. package/src/abi/coders/array.ts +1 -1
  165. package/src/chains/arbitrum/TokensServiceArbitrum.ts +1 -1
  166. package/src/clients/EvmWeb3Client.ts +23 -2
  167. package/src/clients/Web3Client.ts +2 -2
  168. package/src/clients/Web3ClientFactory.ts +1 -1
  169. package/src/config/ConfigDefaults.ts +14 -0
  170. package/src/contracts/ContractBase.ts +2 -0
  171. package/src/contracts/ContractClassFactory.ts +8 -2
  172. package/src/contracts/deploy/ContractDeployer.ts +1 -1
  173. package/src/contracts/deploy/Deployments.ts +1 -1
  174. package/src/contracts/deploy/proxy/ProxyDeployment.ts +1 -1
  175. package/src/contracts/deploy/storage/DeploymentsStorage.ts +5 -5
  176. package/src/contracts/wrappers/FnSignedWrapper.ts +1 -1
  177. package/src/erc4337/models/UserOperation.ts +1 -1
  178. package/src/explorer/BlockChainExplorerFactory.ts +1 -1
  179. package/src/explorer/BlockChainExplorerProvider.ts +1 -1
  180. package/src/explorer/ContractVerifier.ts +2 -1
  181. package/src/gen/GeneratorFromAbi.ts +114 -60
  182. package/src/gen/GeneratorStorageReader.ts +16 -2
  183. package/src/gen/templates/ContractStorageReaderTemplate.d.ts.tmpl +7 -0
  184. package/src/gen/templates/ContractTemplate.d.ts.tmpl +110 -0
  185. package/src/hardhat/HardhatProvider.ts +239 -106
  186. package/src/json/JsonArrayMultiStore.ts +4 -2
  187. package/src/json/JsonArrayStore.ts +1 -1
  188. package/src/models/TEth.ts +2 -2
  189. package/src/ns/providers/EnsProvider.ts +2 -2
  190. package/src/safe/GnosisSafeFactory.ts +2 -2
  191. package/src/safe/GnosisSafeService.ts +1 -1
  192. package/src/safe/SafeTx.ts +1 -1
  193. package/src/safe/transport/FileServiceTransport.ts +1 -1
  194. package/src/safe/transport/InMemoryServiceTransport.ts +1 -1
  195. package/src/services/TimelockService/TimelockService.ts +1 -1
  196. package/src/services/TimelockService/TimelockServiceFallbackSafe.ts +1 -1
  197. package/src/solidity/SlotsStorage.ts +2 -1
  198. package/src/tokens/TokenExchanges/AmmV2ExchangeBase.ts +4 -4
  199. package/src/tokens/TokenExchanges/OneInchExchange.ts +1 -1
  200. package/src/tokens/TokenOracles/amm/AmmV1Oracle.ts +1 -1
  201. package/src/tokens/TokenService.ts +1 -1
  202. package/src/tokens/TokensService.ts +1 -1
  203. package/src/tokens/TokensServiceBsc.ts +1 -1
  204. package/src/tokens/TokensServicePolygon.ts +1 -1
  205. package/src/tokens/TokensServiceXDai.ts +1 -1
  206. package/src/types/TAbi.ts +2 -2
  207. package/src/utils/$abiParser.ts +8 -1
  208. package/src/utils/$bigint.ts +41 -0
  209. package/src/utils/$contract.ts +6 -1
  210. package/src/utils/$logger.ts +4 -0
  211. package/src/utils/$path.ts +20 -0
  212. package/src/utils/$sig.ts +1 -1
  213. package/src/utils/types.ts +3 -0
  214. package/src/wallets/Wallet.ts +1 -1
  215. package/tsconfig.json +1 -0
  216. package/lib/cjs/gen/ContractStorageReaderTemplate.js +0 -13
  217. package/lib/cjs/gen/ContractStorageReaderTemplate.js.map +0 -1
  218. package/lib/cjs/gen/ContractTemplate.js +0 -56
  219. package/lib/cjs/gen/ContractTemplate.js.map +0 -1
  220. package/lib/esm/gen/ContractStorageReaderTemplate.js.map +0 -1
  221. package/lib/esm/gen/ContractStorageReaderTemplate.mjs +0 -13
  222. package/lib/esm/gen/ContractTemplate.js.map +0 -1
  223. package/lib/esm/gen/ContractTemplate.mjs +0 -49
  224. /package/src/gen/{ContractStorageReaderTemplate.js → templates/ContractStorageReaderTemplate.js.tmpl} +0 -0
  225. /package/src/gen/{ContractStorageReaderTemplate.ts → templates/ContractStorageReaderTemplate.ts.tmpl} +0 -0
  226. /package/src/gen/{ContractTemplate.js → templates/ContractTemplate.js.tmpl} +0 -0
  227. /package/src/gen/{ContractTemplate.ts → templates/ContractTemplate.ts.tmpl} +0 -0
@@ -4,11 +4,11 @@ import { class_Uri } from 'atma-utils';
4
4
  import { File, env, Directory } from 'atma-io';
5
5
 
6
6
  import type { ContractBase } from '@dequanto/contracts/ContractBase';
7
- import type { Constructor } from 'atma-utils/mixin';
7
+
8
8
  import type { TAbiItem } from '@dequanto/types/TAbi';
9
9
  import type { TEth } from '@dequanto/models/TEth';
10
10
 
11
- import { EoAccount } from "@dequanto/models/TAccount";
11
+ import { EoAccount } from '@dequanto/models/TAccount';
12
12
  import { HardhatWeb3Client } from '@dequanto/hardhat/HardhatWeb3Client';
13
13
  import { Web3Client } from '@dequanto/clients/Web3Client';
14
14
 
@@ -34,9 +34,12 @@ import { TAddress } from '@dequanto/models/TAddress';
34
34
  import { $contract } from '@dequanto/utils/$contract';
35
35
  import { $dependency } from '@dequanto/utils/$dependency';
36
36
  import { TTransport } from '@dequanto/rpc/transports/ITransport';
37
+ import { Constructor } from '@dequanto/utils/types';
37
38
 
38
39
  type THardhatLib = typeof import('hardhat');
39
40
 
41
+ const rgx_CONTRACT_NAME = /contract\s+(?<contractName>[\w_]+)/ig;
42
+
40
43
  export class HardhatProvider {
41
44
 
42
45
  @memd.deco.memoize()
@@ -263,12 +266,14 @@ export class HardhatProvider {
263
266
  };
264
267
  }
265
268
 
266
- async compileSol<T extends ContractBase = IContractWrapped> (solContractPath: string, options?: {
269
+ async compileSolDirectory (dir: string, options?: {
267
270
  paths?: {
268
271
  root?: string
269
272
  artifacts?: string
270
273
  },
271
274
  contractName?: string
275
+ tsgen?: boolean
276
+ install?: string
272
277
  }): Promise<{
273
278
  abi: TAbiItem[]
274
279
  bytecode: TEth.Hex
@@ -276,123 +281,81 @@ export class HardhatProvider {
276
281
  // renamed output
277
282
  artifact: string
278
283
  source: IGeneratorSources
279
- ContractCtor: Constructor<T>
284
+ ContractCtor: Constructor<IContractWrapped>
280
285
  linkReferences?: Record<string /* path */, Record<string /* name */, any>>
281
- }> {
286
+ }[]> {
282
287
 
283
- solContractPath = $path.normalize(solContractPath);
284
-
285
- const dir = solContractPath.replace(/[^\/]+$/, '');
286
- const filename = /(?<filename>[^\/]+)\.\w+$/.exec(solContractPath)?.groups.filename;
287
- // Filename could contain have random number, extract main-name
288
- const filenameRndSuffix = filename.replace(/_\d+$/, '');
289
-
290
- let root = options?.paths?.root;
291
- let artifacts = options?.paths?.artifacts;
292
-
293
- if (filename == null) {
294
- throw new Error(`Filename not extracted from ${solContractPath}`);
288
+ dir = $path.normalize(dir);
289
+ if (await Directory.existsAsync(dir) === false) {
290
+ throw new Error(`Directory "${dir}" does not exist.`);
295
291
  }
296
-
297
- let hhOptions = {
292
+ const paths = {
298
293
  sources: dir,
299
- root,
300
- artifacts,
301
- tsgen: false,
294
+ root: options?.paths?.root,
295
+ artifacts: options?.paths?.artifacts,
296
+ };
297
+ const hhOptions = {
298
+ ...paths,
299
+ tsgen: options?.tsgen ?? false,
300
+ install: options?.install ?? null
302
301
  };
303
302
  const hh = await this.getHardhat();
304
303
  await hh.run('compile', hhOptions);
305
304
 
306
- if (root == null) {
307
- root = 'file://' + $path.normalize(process.cwd());
308
- }
309
- if (artifacts == null && root != null) {
310
- artifacts = class_Uri.combine(root, 'artifacts/');
311
- }
305
+ const files = await Directory.readFilesAsync(paths.sources, '*.sol');
312
306
 
313
- if (solContractPath.toLowerCase().includes(root.toLowerCase())) {
314
- let i = solContractPath.toLowerCase().indexOf(root.toLowerCase());
315
- solContractPath = solContractPath.substring(i + root.length);
316
- }
317
-
318
- let outputDir = class_Uri.combine(artifacts, solContractPath);
319
- let output = class_Uri.combine(outputDir, `${filename}.json`);
320
- if (await File.existsAsync(output) === false) {
321
- let path = `${outputDir}/`;
322
- if (await Directory.existsAsync(path) === false) {
323
- throw new Error(`No JSONs found in ${outputDir}, nor ${output}`);
324
- }
325
- let files = await Directory.readFilesAsync(path);
326
- let jsons = files.filter(x => /(?<!dbg)\.json$/.test(x.uri.file));
327
- if (jsons.length === 0) {
328
- throw new Error(`No JSONs output found in "${outputDir}/"`);
329
- }
330
- if (jsons.length === 1) {
331
- output = jsons[0].uri.toString();
332
- } else {
333
- let jsonFile = getJsonFile(jsons, filename);
334
- if (jsonFile == null) {
335
- jsonFile = getJsonFile(jsons, filenameRndSuffix);
336
- }
337
- if (jsonFile == null) {
338
- let contractName = options?.contractName;
339
- if (contractName == null) {
340
- let source = await File.readAsync<string>(solContractPath);
341
- let rgx = /contract \s*(?<contractName>[\w_]+)/ig;
342
- let matches = Array.from(source.matchAll(rgx));
343
- contractName = matches[matches.length - 1]?.groups?.contractName;
344
- options.contractName = contractName;
345
- }
346
- jsonFile = getJsonFile(jsons, contractName);
347
- }
348
-
349
- if (jsonFile == null) {
350
- $logger.log(`Files: ${ files.map(file => file.uri.file ).join(', ')}`);
351
- throw new Error(`Compiled JSON data not found for "${filename}" in "${outputDir}/"`);
352
- }
353
- output = jsonFile.uri.toString();
354
- }
355
- }
356
- function getJsonFile (files: InstanceType<typeof File>[], filename: string) {
357
- return files.find(file => {
358
- return file.uri.file === `${filename}.json`;
307
+ const results = await alot(files).mapAsync(async file => {
308
+ let solContractPath = file.uri.toLocalFile();
309
+ return await this.getContractFromSolPath(solContractPath, {
310
+ paths
359
311
  });
360
- }
312
+ }).toArrayAsync();
361
313
 
362
- let { abi, bytecode, contractName, linkReferences } = await File.readAsync<{
363
- abi,
364
- bytecode,
365
- contractName,
366
- linkReferences: Record<string /* path */, Record<string /* name */, any>>
367
- }> (output);
368
- let files = await Directory.readFilesAsync(dir, '*.sol');
369
- let { contract, ContractCtor } = ContractClassFactory.fromAbi<T>(null, abi, null, null, {
370
- $meta: {
371
- artifact: output
372
- }
373
- })
314
+ return results.filter(x => x != null);
315
+ }
374
316
 
375
- let fileMap = await alot(files)
376
- .mapAsync(async file => {
377
- return {
378
- key: file.uri.toString(),
379
- content: await file.readAsync<string>()
380
- };
381
- })
382
- .toDictionaryAsync(x => x.key, x => ({ content: x.content }));
317
+ async compileSol<T extends ContractBase = IContractWrapped> (solContractPath: string, options?: {
318
+ paths?: {
319
+ root?: string
320
+ artifacts?: string
321
+ },
322
+ contractName?: string
323
+ tsgen?: boolean
324
+ install?: string
325
+ }): Promise<{
326
+ abi: TAbiItem[]
327
+ bytecode: TEth.Hex
328
+ output: string
329
+ // renamed output
330
+ artifact: string
331
+ source: IGeneratorSources
332
+ ContractCtor: Constructor<T>
333
+ linkReferences?: Record<string /* path */, Record<string /* name */, any>>
334
+ }> {
383
335
 
384
- return {
385
- abi,
386
- bytecode,
387
- output,
388
- artifact: output,
389
- source: {
390
- contractName: contractName ?? options?.contractName,
391
- files: fileMap
392
- },
393
- linkReferences,
394
- ContractCtor
336
+ solContractPath = $path.normalize(solContractPath);
337
+
338
+ const dir = $path.getDirectory(solContractPath);
339
+ const paths = {
340
+ sources: dir,
341
+ root: options?.paths?.root,
342
+ artifacts: options?.paths?.artifacts,
395
343
  };
344
+
345
+ let hhOptions = {
346
+ ...paths,
347
+
348
+ tsgen: options?.tsgen ?? false,
349
+ install: options?.install ?? null
350
+ };
351
+ const hh = await this.getHardhat();
352
+ await hh.run('compile', hhOptions);
353
+
354
+
355
+ return await this.getContractFromSolPath<T> (solContractPath, {
356
+ contractName: options?.contractName,
357
+ paths
358
+ });
396
359
  }
397
360
 
398
361
  async deployCode <TReturn extends ContractBase = IContractWrapped> (
@@ -507,4 +470,174 @@ export class HardhatProvider {
507
470
  return hh.network.provider as any as TTransport.Transport;
508
471
  }
509
472
 
473
+
474
+ private async getArtifactJsonPath (solContractPath: string, options: {
475
+ contractName?: string
476
+ paths: {
477
+ root: string
478
+ artifacts: string
479
+ }
480
+ }) {
481
+ let outputDir = class_Uri.combine(options.paths.artifacts, solContractPath, '/');
482
+ if (await Directory.existsAsync(outputDir) === false) {
483
+ let content = await this.getSolFileContent(solContractPath, options);
484
+ if (rgx_CONTRACT_NAME.test(content) === false) {
485
+ return null;
486
+ }
487
+ throw new Error(`No JSONs found in ${outputDir} for ${solContractPath}`);
488
+ }
489
+
490
+ if (options.contractName != null) {
491
+ let artifactJsonPath = class_Uri.combine(outputDir, `${options.contractName}.json`);
492
+ if (await File.existsAsync(artifactJsonPath)) {
493
+ return artifactJsonPath;
494
+ }
495
+ }
496
+ const { filename } = $path.getFilename(solContractPath);
497
+
498
+ if (filename != null) {
499
+ let artifactJsonPath = class_Uri.combine(outputDir, `${filename}.json`);
500
+ if (await File.existsAsync(artifactJsonPath)) {
501
+ return artifactJsonPath;
502
+ }
503
+ }
504
+ if (filename == null) {
505
+ throw new Error(`Filename not extracted from ${solContractPath}`);
506
+ }
507
+ let files = await Directory.readFilesAsync(outputDir);
508
+ let jsons = files.filter(x => /(?<!dbg)\.json$/.test(x.uri.file));
509
+ if (jsons.length === 0) {
510
+ throw new Error(`No JSONs output found in "${outputDir}/"`);
511
+ }
512
+ if (jsons.length === 1) {
513
+ // Only one JSON artifact found, assume it's the main contract
514
+ let artifactJsonPath = jsons[0].uri.toString();
515
+ return artifactJsonPath;
516
+ }
517
+
518
+
519
+ let jsonFile = getJsonFile(jsons, filename);
520
+ if (jsonFile == null) {
521
+ // Filename could contain random number, extract main-name
522
+ const filenameRndSuffix = filename.replace(/_\d+$/, '');
523
+ if (filenameRndSuffix != null) {
524
+ jsonFile = getJsonFile(jsons, filenameRndSuffix);
525
+ }
526
+ }
527
+ if (jsonFile == null) {
528
+ let source = await this.getSolFileContent(solContractPath, options);
529
+ let matches = Array.from(source.matchAll(rgx_CONTRACT_NAME));
530
+ let contractName = matches[matches.length - 1]?.groups?.contractName;
531
+ options.contractName = contractName;
532
+ jsonFile = getJsonFile(jsons, contractName);
533
+ }
534
+
535
+ if (jsonFile == null) {
536
+ $logger.log(`Files: ${ files.map(file => file.uri.file ).join(', ')}`);
537
+ throw new Error(`Compiled JSON data not found for "${filename}" in "${outputDir}/"`);
538
+ }
539
+ let artifactJsonPath = jsonFile.uri.toString();
540
+ return artifactJsonPath;
541
+
542
+
543
+ function getJsonFile (files: InstanceType<typeof File>[], filename: string) {
544
+ return files.find(file => {
545
+ return file.uri.file === `${filename}.json`;
546
+ });
547
+ }
548
+ }
549
+
550
+ private async getPaths (paths?: { root?: string, artifacts?: string }) {
551
+ let root = paths?.root;
552
+ let artifacts = paths?.artifacts;
553
+
554
+ if (root == null) {
555
+ root = 'file://' + $path.normalize(process.cwd());
556
+ }
557
+ if (artifacts == null) {
558
+ artifacts = class_Uri.combine(root, 'artifacts/');
559
+ }
560
+
561
+ return { root, artifacts };
562
+ }
563
+
564
+ private async getSolFileContent (solContractPath, options: { paths: { root }}) {
565
+ let sourceFile = solContractPath;
566
+ if (await File.existsAsync(sourceFile) === false) {
567
+ sourceFile = class_Uri.combine(options.paths.root, sourceFile);
568
+ }
569
+ if (await File.existsAsync(sourceFile) === false) {
570
+ throw new Error(`Source file "${solContractPath}" not found in ${options.paths.root}`);
571
+ }
572
+
573
+ let source = await File.readAsync<string>(sourceFile);
574
+ return source;
575
+ }
576
+
577
+ public async getContractFromSolPath <T extends ContractBase = IContractWrapped> (solContractPath: string, options?: {
578
+ contractName?: string
579
+ paths: {
580
+ sources?: string
581
+ root?: string;
582
+ artifacts?: string;
583
+ };
584
+ }) {
585
+
586
+ let { root, artifacts } = await this.getPaths (options?.paths);
587
+ let solContractPathRootRelative = $path.getRelativePath(solContractPath, root);
588
+
589
+ let artifactJsonPath = await this.getArtifactJsonPath(solContractPathRootRelative, {
590
+ contractName: options?.contractName,
591
+ paths: {
592
+ root,
593
+ artifacts,
594
+ },
595
+ });
596
+ if (artifactJsonPath == null) {
597
+ return null;
598
+ }
599
+
600
+ let { abi, bytecode, contractName, linkReferences } = await File.readAsync<IJsonArtifact> (artifactJsonPath);
601
+ let { contract, ContractCtor } = ContractClassFactory.fromAbi<T>(null, abi, null, null, {
602
+ contractName,
603
+ $meta: {
604
+ name: contractName,
605
+ source: solContractPathRootRelative,
606
+ artifact: artifactJsonPath
607
+ }
608
+ })
609
+
610
+ let files = options?.paths?.sources
611
+ ? await Directory.readFilesAsync(options.paths.sources, '*.sol')
612
+ : [];
613
+ let fileMap = await alot(files)
614
+ .mapAsync(async file => {
615
+ return {
616
+ key: file.uri.toString(),
617
+ content: await file.readAsync<string>()
618
+ };
619
+ })
620
+ .toDictionaryAsync(x => x.key, x => ({ content: x.content }));
621
+
622
+ return {
623
+ abi,
624
+ bytecode,
625
+ output: artifactJsonPath,
626
+ artifact: artifactJsonPath,
627
+ source: {
628
+ contractName: contractName ?? options?.contractName,
629
+ files: fileMap
630
+ },
631
+ linkReferences,
632
+ ContractCtor
633
+ };
634
+ }
635
+ }
636
+
637
+
638
+ interface IJsonArtifact {
639
+ abi: TEth.Abi.Item[]
640
+ bytecode: TEth.Hex
641
+ contractName: string
642
+ linkReferences: Record<string /* path */, Record<string /* name */, any>>
510
643
  }
@@ -89,14 +89,16 @@ export class JsonArrayMultiStore<T> {
89
89
  private async getGroupedFiles () {
90
90
  try {
91
91
  let files = await Directory.readFilesAsync(this.options.path, '*.json');
92
- let rangeFiles = files
92
+ let rangeFiles = alot(files)
93
93
  .map(file => {
94
94
  return {
95
95
  file,
96
96
  range: this.parseRangeFilename(file.uri.file)
97
97
  };
98
98
  })
99
- .filter(x => x.range != null);
99
+ .filter(x => x.range != null)
100
+ .sortBy(x => x.range.start, 'asc')
101
+ .toArray();
100
102
  return rangeFiles;
101
103
  } catch (e) {
102
104
  return [];
@@ -2,7 +2,7 @@ import alot from 'alot'
2
2
  import { JsonConvert } from 'class-json'
3
3
  import { Alot } from 'alot/alot'
4
4
  import { JsonStoreFs } from './JsonStoreFs'
5
- import type { Constructor } from 'atma-utils'
5
+ import { Constructor } from '@dequanto/utils/types'
6
6
 
7
7
  export interface IStoreOptions<T, TStorage = T> {
8
8
  path: string
@@ -201,7 +201,7 @@ export namespace TEth {
201
201
  }
202
202
 
203
203
  export interface Input {
204
- name: string;
204
+ name?: string;
205
205
  type: string;
206
206
  indexed?: boolean;
207
207
  components?: Input[];
@@ -209,7 +209,7 @@ export namespace TEth {
209
209
  }
210
210
 
211
211
  export interface Output {
212
- name: string;
212
+ name?: string;
213
213
  type: string;
214
214
  components?: Output[];
215
215
  internalType?: string;
@@ -4,8 +4,8 @@ import { EthWeb3Client } from '@dequanto/clients/EthWeb3Client';
4
4
  import { TAddress } from '@dequanto/models/TAddress';
5
5
  import { $require } from '@dequanto/utils/$require';
6
6
  import { $ns } from '../utils/$ns';
7
- import type { EnsPublicResolver } from '@dequanto-contracts/ens/EnsPublicResolver/EnsPublicResolver';
8
- import type { EnsRegistry } from '@dequanto-contracts/ens/EnsRegistry/EnsRegistry';
7
+ import type { EnsPublicResolver } from '@dequanto/prebuilt/ens/EnsPublicResolver/EnsPublicResolver';
8
+ import type { EnsRegistry } from '@dequanto/prebuilt/ens/EnsRegistry/EnsRegistry';
9
9
  import { $is } from '@dequanto/utils/$is';
10
10
  import { TEth } from '@dequanto/models/TEth';
11
11
  import { ContractClassFactory } from '@dequanto/contracts/ContractClassFactory';
@@ -2,10 +2,10 @@ import { EoAccount } from "@dequanto/models/TAccount";
2
2
  import { Web3Client } from '@dequanto/clients/Web3Client';
3
3
  import { TAddress } from '@dequanto/models/TAddress';
4
4
  import { GnosisSafeHandler } from './GnosisSafeHandler';
5
- import { Safe } from '@dequanto-contracts/safe/Safe';
5
+ import { Safe } from '@dequanto/prebuilt/safe/Safe';
6
6
  import { config } from '@dequanto/config/Config';
7
7
  import { $require } from '@dequanto/utils/$require';
8
- import { SafeProxyFactory } from '@dequanto-contracts/safe/SafeProxyFactory';
8
+ import { SafeProxyFactory } from '@dequanto/prebuilt/safe/SafeProxyFactory';
9
9
  import { TEth } from '@dequanto/models/TEth';
10
10
  import { TAbiItem } from '@dequanto/types/TAbi';
11
11
 
@@ -1,4 +1,4 @@
1
- import { GnosisSafe } from '@dequanto-contracts/safe/GnosisSafe';
1
+ import { GnosisSafe } from '@dequanto/prebuilt/safe/GnosisSafe';
2
2
  import { IBlockChainExplorer } from '@dequanto/explorer/IBlockChainExplorer';
3
3
  import { Web3Client } from '@dequanto/clients/Web3Client';
4
4
  import { ContractAbiProvider } from '@dequanto/contracts/ContractAbiProvider';
@@ -7,7 +7,7 @@ import { TxWriter } from '@dequanto/txs/TxWriter';
7
7
  import { $abiUtils } from '@dequanto/utils/$abiUtils';
8
8
  import { TxDataBuilder } from '@dequanto/txs/TxDataBuilder';
9
9
  import { config } from '@dequanto/config/Config';
10
- import { MultiSend } from '@dequanto-contracts/safe/MultiSend';
10
+ import { MultiSend } from '@dequanto/prebuilt/safe/MultiSend';
11
11
  import { ISafeServiceTransport } from './transport/ISafeServiceTransport';
12
12
  import { $hex } from '@dequanto/utils/$hex';
13
13
 
@@ -1,4 +1,4 @@
1
- import { GnosisSafe } from '@dequanto-contracts/safe/GnosisSafe';
1
+ import { GnosisSafe } from '@dequanto/prebuilt/safe/GnosisSafe';
2
2
  import { Web3Client } from '@dequanto/clients/Web3Client';
3
3
  import { EoAccount } from '@dequanto/models/TAccount';
4
4
  import { TAddress } from '@dequanto/models/TAddress';
@@ -1,5 +1,5 @@
1
1
  import alot from 'alot';
2
- import { GnosisSafe } from '@dequanto-contracts/safe/GnosisSafe';
2
+ import { GnosisSafe } from '@dequanto/prebuilt/safe/GnosisSafe';
3
3
  import { Web3Client } from '@dequanto/clients/Web3Client';
4
4
  import type { EoAccount } from '@dequanto/models/TAccount';
5
5
  import type { TAddress } from '@dequanto/models/TAddress';
@@ -1,5 +1,5 @@
1
1
  import memd from 'memd';
2
- import { TimelockController } from '@dequanto-contracts/openzeppelin/TimelockController';
2
+ import { TimelockController } from '@dequanto/prebuilt/openzeppelin/TimelockController';
3
3
  import { ContractBase } from '@dequanto/contracts/ContractBase';
4
4
  import { JsonArrayStore } from '@dequanto/json/JsonArrayStore';
5
5
  import { IAccount } from '@dequanto/models/TAccount';
@@ -1,4 +1,4 @@
1
- import { TimelockController } from '@dequanto-contracts/openzeppelin/TimelockController';
1
+ import { TimelockController } from '@dequanto/prebuilt/openzeppelin/TimelockController';
2
2
  import { ContractBase } from '@dequanto/contracts/ContractBase';
3
3
  import { IAccount } from '@dequanto/models/TAccount';
4
4
  import { TAddress } from '@dequanto/models/TAddress';
@@ -7,7 +7,8 @@ import { SlotDynamicArrayHandler } from './storage/handlers/SlotDynamicArrayHand
7
7
  import { SlotsStorageTransport, ISlotsStorageTransport, SlotsCursorTransport } from './storage/SlotsStorageTransport';
8
8
  import { TAddress } from '@dequanto/models/TAddress';
9
9
  import { ASlotsStorageHandler } from './storage/SlotsStorageHandler';
10
- import { Constructor, is_Object } from 'atma-utils';
10
+ import { Constructor } from '@dequanto/utils/types';
11
+ import { is_Object } from 'atma-utils';
11
12
  import { SlotMappingHandler } from './storage/handlers/SlotMappingHandler';
12
13
  import { SlotStringHandler } from './storage/handlers/SlotStringHandler';
13
14
  import { Accessor, IAccessorItem } from './storage/Accessor';
@@ -12,10 +12,10 @@ import { TokensServiceBsc } from '../TokensServiceBsc';
12
12
  import { $address } from '@dequanto/utils/$address';
13
13
  import { $require } from '@dequanto/utils/$require';
14
14
  import { $cache } from '@dequanto/utils/$cache';
15
- import { AmmFactoryV2Contract } from '@dequanto-contracts/amm/AmmFactoryV2Contract/AmmFactoryV2Contract';
16
- import { AmmMasterChefV2Contract } from '@dequanto-contracts/amm/AmmMasterChefV2Contract/AmmMasterChefV2Contract';
17
- import { AmmVaultV2Contract } from '@dequanto-contracts/amm/AmmVaultV2Contract/AmmVaultV2Contract';
18
- import { AmmPairV2Contract } from '@dequanto-contracts/amm/AmmPairV2Contract/AmmPairV2Contract';
15
+ import { AmmFactoryV2Contract } from '@dequanto/prebuilt/amm/AmmFactoryV2Contract/AmmFactoryV2Contract';
16
+ import { AmmMasterChefV2Contract } from '@dequanto/prebuilt/amm/AmmMasterChefV2Contract/AmmMasterChefV2Contract';
17
+ import { AmmVaultV2Contract } from '@dequanto/prebuilt/amm/AmmVaultV2Contract/AmmVaultV2Contract';
18
+ import { AmmPairV2Contract } from '@dequanto/prebuilt/amm/AmmPairV2Contract/AmmPairV2Contract';
19
19
 
20
20
 
21
21
  interface ILPPair extends IToken {
@@ -11,7 +11,7 @@ import { TxWriter } from '@dequanto/txs/TxWriter';
11
11
  import { TxDataBuilder } from '@dequanto/txs/TxDataBuilder';
12
12
  import { Web3Client } from '@dequanto/clients/Web3Client';
13
13
  import { IBlockChainExplorer } from '@dequanto/explorer/IBlockChainExplorer';
14
- import { ERC20 } from '@dequanto-contracts/openzeppelin/ERC20';
14
+ import { ERC20 } from '@dequanto/prebuilt/openzeppelin/ERC20';
15
15
  import { $http } from '@dequanto/utils/$http';
16
16
 
17
17
  const PLATFORMS = {
@@ -17,7 +17,7 @@ import { TAddress } from '@dequanto/models/TAddress';
17
17
  import { IBlockChainExplorer } from '@dequanto/explorer/IBlockChainExplorer';
18
18
  import { ContractReader } from '@dequanto/contracts/ContractReader';
19
19
  import { $config } from '@dequanto/utils/$config';
20
- import { ERC20 } from '@dequanto-contracts/openzeppelin/ERC20';
20
+ import { ERC20 } from '@dequanto/prebuilt/openzeppelin/ERC20';
21
21
  import { TokensService } from '@dequanto/tokens/TokensService';
22
22
  import { $bigint } from '@dequanto/utils/$bigint';
23
23
  import { $block } from '@dequanto/utils/$block';
@@ -8,7 +8,7 @@ import { $bigint } from '@dequanto/utils/$bigint';
8
8
  import { TokensServiceFactory } from './TokensServiceFactory';
9
9
  import { $require } from '@dequanto/utils/$require';
10
10
  import { TokensService } from './TokensService';
11
- import { WETH } from '@dequanto-contracts/weth/WETH/WETH';
11
+ import { WETH } from '@dequanto/prebuilt/weth/WETH/WETH';
12
12
  import { BlockDateResolver } from '@dequanto/blocks/BlockDateResolver';
13
13
 
14
14
 
@@ -8,7 +8,7 @@ import { ITokenProvider } from './TokenProviders/ITokenProvider';
8
8
  import { Web3ClientFactory } from '@dequanto/clients/Web3ClientFactory';
9
9
  import { BlockChainExplorerProvider } from '@dequanto/explorer/BlockChainExplorerProvider';
10
10
  import { TokenDataProvider } from './TokenDataProvider';
11
- import { ERC20 } from '@dequanto-contracts/openzeppelin/ERC20';
11
+ import { ERC20 } from '@dequanto/prebuilt/openzeppelin/ERC20';
12
12
 
13
13
 
14
14
  export class TokensService {
@@ -2,7 +2,7 @@ import di from 'a-di';
2
2
  import { TokensService } from './TokensService';
3
3
  import { Bscscan } from '@dequanto/explorer/Bscscan';
4
4
  import { TAddress } from '@dequanto/models/TAddress';
5
- import { ERC20 } from '@dequanto-contracts/openzeppelin/ERC20';
5
+ import { ERC20 } from '@dequanto/prebuilt/openzeppelin/ERC20';
6
6
 
7
7
  export class TokensServiceBsc extends TokensService {
8
8
  constructor () {
@@ -2,7 +2,7 @@ import di from 'a-di';
2
2
  import { TokensService } from './TokensService';
3
3
  import { TAddress } from '@dequanto/models/TAddress';
4
4
  import { Polyscan } from '@dequanto/explorer/Polyscan';
5
- import { ERC20 } from '@dequanto-contracts/openzeppelin/ERC20';
5
+ import { ERC20 } from '@dequanto/prebuilt/openzeppelin/ERC20';
6
6
 
7
7
  export class TokensServicePolygon extends TokensService {
8
8
  constructor () {
@@ -4,7 +4,7 @@ import { TAddress } from '@dequanto/models/TAddress';
4
4
  import { XDaiscan } from '@dequanto/chains/xdai/XDaiscan';
5
5
  import { IToken } from '@dequanto/models/IToken';
6
6
  import { ITokenProvider } from './TokenProviders/ITokenProvider';
7
- import { ERC20 } from '@dequanto-contracts/openzeppelin/ERC20';
7
+ import { ERC20 } from '@dequanto/prebuilt/openzeppelin/ERC20';
8
8
 
9
9
  export class TokensServiceXDai extends TokensService {
10
10
  constructor () {
package/src/types/TAbi.ts CHANGED
@@ -20,13 +20,13 @@ export interface TAbiInput {
20
20
  name?: string;
21
21
  type: string;
22
22
  indexed?: boolean;
23
- components?: TAbiInput[];
23
+ components?: TAbiInput[];
24
24
  internalType?: string;
25
25
  }
26
26
 
27
27
  export interface TAbiOutput {
28
28
  name?: string;
29
29
  type: string;
30
- components?: TAbiOutput[];
30
+ components?: TAbiOutput[];
31
31
  internalType?: string;
32
32
  }