dequanto 0.1.22 → 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 (127) hide show
  1. package/lib/cjs/chains/arbitrum/TokensServiceArbitrum.d.ts +1 -1
  2. package/lib/cjs/clients/EvmWeb3Client.d.ts +3 -0
  3. package/lib/cjs/clients/EvmWeb3Client.js +23 -4
  4. package/lib/cjs/clients/EvmWeb3Client.js.map +1 -1
  5. package/lib/cjs/clients/Web3Client.d.ts +2 -2
  6. package/lib/cjs/clients/Web3ClientFactory.js +1 -1
  7. package/lib/cjs/clients/Web3ClientFactory.js.map +1 -1
  8. package/lib/cjs/config/ConfigDefaults.js +14 -0
  9. package/lib/cjs/config/ConfigDefaults.js.map +1 -1
  10. package/lib/cjs/erc4337/models/UserOperation.d.ts +1 -1
  11. package/lib/cjs/gen/GeneratorFromAbi.d.ts +3 -1
  12. package/lib/cjs/gen/GeneratorFromAbi.js +87 -68
  13. package/lib/cjs/gen/GeneratorFromAbi.js.map +1 -1
  14. package/lib/cjs/gen/GeneratorStorageReader.d.ts +1 -0
  15. package/lib/cjs/gen/GeneratorStorageReader.js +13 -1
  16. package/lib/cjs/gen/GeneratorStorageReader.js.map +1 -1
  17. package/lib/cjs/hardhat/HardhatProvider.d.ts +24 -1
  18. package/lib/cjs/hardhat/HardhatProvider.js +27 -13
  19. package/lib/cjs/hardhat/HardhatProvider.js.map +1 -1
  20. package/lib/cjs/ns/providers/EnsProvider.d.ts +2 -2
  21. package/lib/cjs/safe/GnosisSafeFactory.js.map +1 -1
  22. package/lib/cjs/safe/GnosisSafeService.js.map +1 -1
  23. package/lib/cjs/safe/SafeTx.js.map +1 -1
  24. package/lib/cjs/safe/transport/FileServiceTransport.js.map +1 -1
  25. package/lib/cjs/safe/transport/InMemoryServiceTransport.js.map +1 -1
  26. package/lib/cjs/services/TimelockService/TimelockService.d.ts +1 -1
  27. package/lib/cjs/tokens/TokenExchanges/AmmV2ExchangeBase.d.ts +4 -4
  28. package/lib/cjs/tokens/TokenExchanges/AmmV2ExchangeBase.js.map +1 -1
  29. package/lib/cjs/tokens/TokenExchanges/OneInchExchange.js.map +1 -1
  30. package/lib/cjs/tokens/TokenOracles/amm/AmmV1Oracle.js.map +1 -1
  31. package/lib/cjs/tokens/TokenService.js.map +1 -1
  32. package/lib/cjs/tokens/TokensService.d.ts +1 -1
  33. package/lib/cjs/tokens/TokensService.js.map +1 -1
  34. package/lib/cjs/tokens/TokensServiceBsc.d.ts +1 -1
  35. package/lib/cjs/tokens/TokensServicePolygon.d.ts +1 -1
  36. package/lib/cjs/tokens/TokensServiceXDai.d.ts +1 -1
  37. package/lib/cjs/utils/$logger.js +4 -0
  38. package/lib/cjs/utils/$logger.js.map +1 -1
  39. package/lib/cjs/utils/$path.js +4 -2
  40. package/lib/cjs/utils/$path.js.map +1 -1
  41. package/lib/cjs/wallets/Wallet.js.map +1 -1
  42. package/lib/esm/chains/arbitrum/TokensServiceArbitrum.d.ts +1 -1
  43. package/lib/esm/clients/EvmWeb3Client.d.ts +3 -0
  44. package/lib/esm/clients/EvmWeb3Client.js.map +1 -1
  45. package/lib/esm/clients/EvmWeb3Client.mjs +21 -3
  46. package/lib/esm/clients/Web3Client.d.ts +2 -2
  47. package/lib/esm/clients/Web3ClientFactory.js.map +1 -1
  48. package/lib/esm/clients/Web3ClientFactory.mjs +1 -1
  49. package/lib/esm/config/ConfigDefaults.js.map +1 -1
  50. package/lib/esm/config/ConfigDefaults.mjs +14 -0
  51. package/lib/esm/erc4337/models/UserOperation.d.ts +1 -1
  52. package/lib/esm/gen/GeneratorFromAbi.d.ts +3 -1
  53. package/lib/esm/gen/GeneratorFromAbi.js.map +1 -1
  54. package/lib/esm/gen/GeneratorFromAbi.mjs +87 -68
  55. package/lib/esm/gen/GeneratorStorageReader.d.ts +1 -0
  56. package/lib/esm/gen/GeneratorStorageReader.js.map +1 -1
  57. package/lib/esm/gen/GeneratorStorageReader.mjs +13 -1
  58. package/lib/esm/hardhat/HardhatProvider.d.ts +24 -1
  59. package/lib/esm/hardhat/HardhatProvider.js.map +1 -1
  60. package/lib/esm/hardhat/HardhatProvider.mjs +27 -13
  61. package/lib/esm/ns/providers/EnsProvider.d.ts +2 -2
  62. package/lib/esm/safe/GnosisSafeFactory.js.map +1 -1
  63. package/lib/esm/safe/GnosisSafeService.js.map +1 -1
  64. package/lib/esm/safe/SafeTx.js.map +1 -1
  65. package/lib/esm/safe/transport/FileServiceTransport.js.map +1 -1
  66. package/lib/esm/safe/transport/InMemoryServiceTransport.js.map +1 -1
  67. package/lib/esm/services/TimelockService/TimelockService.d.ts +1 -1
  68. package/lib/esm/tokens/TokenExchanges/AmmV2ExchangeBase.d.ts +4 -4
  69. package/lib/esm/tokens/TokenExchanges/AmmV2ExchangeBase.js.map +1 -1
  70. package/lib/esm/tokens/TokenExchanges/OneInchExchange.js.map +1 -1
  71. package/lib/esm/tokens/TokenOracles/amm/AmmV1Oracle.js.map +1 -1
  72. package/lib/esm/tokens/TokenService.js.map +1 -1
  73. package/lib/esm/tokens/TokensService.d.ts +1 -1
  74. package/lib/esm/tokens/TokensService.js.map +1 -1
  75. package/lib/esm/tokens/TokensServiceBsc.d.ts +1 -1
  76. package/lib/esm/tokens/TokensServicePolygon.d.ts +1 -1
  77. package/lib/esm/tokens/TokensServiceXDai.d.ts +1 -1
  78. package/lib/esm/utils/$logger.js.map +1 -1
  79. package/lib/esm/utils/$logger.mjs +4 -0
  80. package/lib/esm/utils/$path.js.map +1 -1
  81. package/lib/esm/utils/$path.mjs +4 -2
  82. package/lib/esm/wallets/Wallet.js.map +1 -1
  83. package/package.json +4 -3
  84. package/src/chains/arbitrum/TokensServiceArbitrum.ts +1 -1
  85. package/src/clients/EvmWeb3Client.ts +23 -2
  86. package/src/clients/Web3Client.ts +2 -2
  87. package/src/clients/Web3ClientFactory.ts +1 -1
  88. package/src/config/ConfigDefaults.ts +14 -0
  89. package/src/erc4337/models/UserOperation.ts +1 -1
  90. package/src/gen/GeneratorFromAbi.ts +94 -68
  91. package/src/gen/GeneratorStorageReader.ts +16 -2
  92. package/src/gen/templates/ContractStorageReaderTemplate.d.ts.tmpl +7 -0
  93. package/src/gen/{ContractTemplate.d.ts.template → templates/ContractTemplate.d.ts.tmpl} +29 -30
  94. package/src/hardhat/HardhatProvider.ts +33 -22
  95. package/src/ns/providers/EnsProvider.ts +2 -2
  96. package/src/safe/GnosisSafeFactory.ts +2 -2
  97. package/src/safe/GnosisSafeService.ts +1 -1
  98. package/src/safe/SafeTx.ts +1 -1
  99. package/src/safe/transport/FileServiceTransport.ts +1 -1
  100. package/src/safe/transport/InMemoryServiceTransport.ts +1 -1
  101. package/src/services/TimelockService/TimelockService.ts +1 -1
  102. package/src/services/TimelockService/TimelockServiceFallbackSafe.ts +1 -1
  103. package/src/tokens/TokenExchanges/AmmV2ExchangeBase.ts +4 -4
  104. package/src/tokens/TokenExchanges/OneInchExchange.ts +1 -1
  105. package/src/tokens/TokenOracles/amm/AmmV1Oracle.ts +1 -1
  106. package/src/tokens/TokenService.ts +1 -1
  107. package/src/tokens/TokensService.ts +1 -1
  108. package/src/tokens/TokensServiceBsc.ts +1 -1
  109. package/src/tokens/TokensServicePolygon.ts +1 -1
  110. package/src/tokens/TokensServiceXDai.ts +1 -1
  111. package/src/utils/$logger.ts +4 -0
  112. package/src/utils/$path.ts +4 -2
  113. package/src/wallets/Wallet.ts +1 -1
  114. package/tsconfig.json +1 -0
  115. package/lib/cjs/gen/ContractStorageReaderTemplate.js +0 -13
  116. package/lib/cjs/gen/ContractStorageReaderTemplate.js.map +0 -1
  117. package/lib/cjs/gen/ContractTemplate.js +0 -56
  118. package/lib/cjs/gen/ContractTemplate.js.map +0 -1
  119. package/lib/esm/gen/ContractStorageReaderTemplate.js.map +0 -1
  120. package/lib/esm/gen/ContractStorageReaderTemplate.mjs +0 -13
  121. package/lib/esm/gen/ContractTemplate.js.map +0 -1
  122. package/lib/esm/gen/ContractTemplate.mjs +0 -49
  123. package/src/gen/ContractStorageReaderTemplate.d.ts.template +0 -14
  124. /package/src/gen/{ContractStorageReaderTemplate.js → templates/ContractStorageReaderTemplate.js.tmpl} +0 -0
  125. /package/src/gen/{ContractStorageReaderTemplate.ts → templates/ContractStorageReaderTemplate.ts.tmpl} +0 -0
  126. /package/src/gen/{ContractTemplate.js → templates/ContractTemplate.js.tmpl} +0 -0
  127. /package/src/gen/{ContractTemplate.ts → templates/ContractTemplate.ts.tmpl} +0 -0
@@ -59,27 +59,36 @@ export class GeneratorFromAbi {
59
59
  return null;
60
60
  })
61
61
  .filter(Boolean)
62
- .map(x => x[ opts?.target ?? 'ts' ])
63
- .map(Str.formatMethod)
64
- .toArray();
62
+ .mapFull(arr => {
63
+ return {
64
+ ts: arr.map(x => Str.formatMethod(x.ts)),
65
+ js: arr.map(x => Str.formatMethod(x.js)),
66
+ types: arr.map(x => Str.formatMethod(x.types)),
67
+ }
68
+ });
65
69
 
66
70
 
67
- let methodTypes = alot(abiJson)
71
+ let methodTypings = alot(abiJson)
68
72
  .filter(x => x.type === 'function')
69
73
  .groupBy(x => x.name)
70
74
  .map(group => {
71
75
  let item = group.values[0];
72
- return Gen.serializeMethodTypeTs(item.name, group.values);
76
+ return Gen.serializeMethodTypingsTs(item.name, group.values);
73
77
  })
74
78
  .filter(Boolean)
75
79
  .toArray();
76
80
 
77
- let eventsArr = abiJson
81
+ let eventsArr = alot(abiJson)
78
82
  .filter(x => x.type === 'event')
79
83
  .map(x => Gen.serializeEvent(x))
80
84
  .filter(Boolean)
81
- .map(x => x[ opts?.target ?? 'ts' ])
82
- .map(Str.formatMethod);
85
+ .mapFull(arr => {
86
+ return {
87
+ ts: arr.map(x => Str.formatMethod(x.ts)),
88
+ js: arr.map(x => Str.formatMethod(x.js)),
89
+ types: arr.map(x => Str.formatMethod(x.types)),
90
+ }
91
+ })
83
92
 
84
93
  let eventTypes = alot(abiJson)
85
94
  .filter(x => x.type === 'event')
@@ -94,19 +103,29 @@ export class GeneratorFromAbi {
94
103
 
95
104
  //let eventInterfacesAll = Gen.serializeEventsInterfacesAllTs(abiJson.filter(x => x.type === 'event'));
96
105
 
97
- let eventsExtractorsArr = abiJson
106
+ let eventsExtractorsArr = alot(abiJson)
98
107
  .filter(x => x.type === 'event')
99
108
  .map(x => Gen.serializeEventExtractor(x))
100
109
  .filter(Boolean)
101
- .map(x => x[ opts?.target ?? 'ts' ])
102
- .map(Str.formatMethod);
110
+ .mapFull(arr => {
111
+ return {
112
+ ts: arr.map(x => Str.formatMethod(x.ts)),
113
+ js: arr.map(x => Str.formatMethod(x.js)),
114
+ types: arr.map(x => Str.formatMethod(x.types)),
115
+ }
116
+ });
103
117
 
104
- let eventsFetchersArr = abiJson
118
+ let eventsFetchersArr = alot(abiJson)
105
119
  .filter(x => x.type === 'event')
106
120
  .map(x => Gen.serializeEventFetcher(x))
107
121
  .filter(Boolean)
108
- .map(x => x[ opts?.target ?? 'ts' ])
109
- .map(Str.formatMethod);
122
+ .mapFull(arr => {
123
+ return {
124
+ ts: arr.map(x => Str.formatMethod(x.ts)),
125
+ js: arr.map(x => Str.formatMethod(x.js)),
126
+ types: arr.map(x => Str.formatMethod(x.types)),
127
+ }
128
+ });
110
129
 
111
130
  // let eventInterfaces = abiJson
112
131
  // .filter(x => x.type === 'event')
@@ -114,15 +133,22 @@ export class GeneratorFromAbi {
114
133
  // .filter(Boolean)
115
134
  // .map(Str.formatMethod);
116
135
 
117
- let methods = methodsArr.join('\n\n');
118
- let events = eventsArr.join('\n\n');
119
- let eventsExtractors = eventsExtractorsArr.join('\n\n');
120
- let eventsFetchers = eventsFetchersArr.join('\n\n');
136
+ let methods = methodsArr[targetType].join('\n\n');
137
+ let methodsTypings = methodsArr.types.join('\n\n');
138
+ let events = eventsArr[targetType].join('\n\n');
139
+ let eventsTypings = eventsArr.types.join('\n\n');
140
+
141
+ let eventsExtractors = eventsExtractorsArr[targetType].join('\n\n');
142
+ let eventsExtractorsTypings = eventsExtractorsArr.types.join('\n\n');
143
+
144
+ let eventsFetchers = eventsFetchersArr[targetType].join('\n\n');
145
+ let eventsFetchersTypings = eventsFetchersArr.types.join('\n\n');
121
146
 
122
147
  let name = opts.name;
123
- let templatePath = $path.resolve(`/src/gen/ContractTemplate.${ targetType }`);
148
+ let templatePath = $path.resolve(`/src/gen/templates/ContractTemplate.${ targetType }.tmpl`);
124
149
  let template = await File.readAsync<string>(templatePath, { skipHooks: true });
125
-
150
+ let templateDtsPath = $path.resolve(`/src/gen/templates/ContractTemplate.d.ts.tmpl`);
151
+ let templateDts = await File.readAsync<string>(templateDtsPath, { skipHooks: true });
126
152
 
127
153
  let EtherscanStr;
128
154
  let EthWeb3ClientStr;
@@ -130,44 +156,8 @@ export class GeneratorFromAbi {
130
156
  let sourceUri: string;
131
157
  let Web3ClientOptions = '';
132
158
  let EvmScanOptions = '';
133
- let importPfx = targetType === 'js' ? 'dequanto' : '@dequanto';
159
+ let importPfx = true /* always */ ? 'dequanto' : '@dequanto';
134
160
  switch (opts.network) {
135
- case 'bsc':
136
- EtherscanStr = 'Bscscan';
137
- EthWeb3ClientStr = 'BscWeb3Client';
138
- imports = [
139
- `import { Bscscan } from '${importPfx}/explorer/Bscscan'`,
140
- `import { BscWeb3Client } from '${importPfx}/clients/BscWeb3Client'`,
141
- ];
142
- sourceUri = `https://bscscan.com/address/${opts.address}#code`;
143
- break;
144
- case 'polygon':
145
- EtherscanStr = 'Polyscan';
146
- EthWeb3ClientStr = 'PolyWeb3Client';
147
- imports = [
148
- `import { Polyscan } from '${importPfx}/explorer/Polyscan'`,
149
- `import { PolyWeb3Client } from '${importPfx}/clients/PolyWeb3Client'`,
150
- ];
151
- sourceUri = `https://polygonscan.com/address/${opts.address}#code`;
152
- break;
153
- case 'xdai':
154
- EtherscanStr = 'XDaiscan';
155
- EthWeb3ClientStr = 'XDaiWeb3Client';
156
- imports = [
157
- `import { XDaiscan } from '${importPfx}/chains/xdai/XDaiscan'`,
158
- `import { XDaiWeb3Client } from '${importPfx}/chains/xdai/XDaiWeb3Client'`,
159
- ];
160
- sourceUri = `https://blockscout.com/xdai/mainnet/address/${opts.address}/contracts`;
161
- break;
162
- case 'eth':
163
- EtherscanStr = 'Etherscan';
164
- EthWeb3ClientStr = 'EthWeb3Client';
165
- imports = [
166
- `import { Etherscan } from '${importPfx}/explorer/Etherscan'`,
167
- `import { EthWeb3Client } from '${importPfx}/clients/EthWeb3Client'`,
168
- ];
169
- sourceUri = `https://etherscan.io/address/${opts.address}#code`;
170
- break;
171
161
  case 'hardhat':
172
162
  EtherscanStr = 'Etherscan';
173
163
  EthWeb3ClientStr = 'HardhatWeb3Client';
@@ -222,6 +212,7 @@ export class GeneratorFromAbi {
222
212
  let storageReaderInitializer = '';
223
213
  let storageReaderProperty = '';
224
214
  let storageReaderClass = '';
215
+ let storageReaderClassTypings = '';
225
216
  try {
226
217
  let storageReaderGenerator = new GeneratorStorageReader();
227
218
  let reader = await storageReaderGenerator.generate({ ...opts, target: targetType });
@@ -231,6 +222,7 @@ export class GeneratorFromAbi {
231
222
  }
232
223
  if (reader.className) {
233
224
  storageReaderClass = reader.code;
225
+ storageReaderClassTypings = reader.types;
234
226
  storageReaderProperty = targetType === 'ts' ? `declare storage: ${reader.className}` : '';
235
227
  storageReaderInitializer = `this.storage = new ${reader.className}(this.address, this.client, this.explorer);`;
236
228
  $logger.log(`green<StorageReader> was generated`);
@@ -270,13 +262,43 @@ export class GeneratorFromAbi {
270
262
 
271
263
 
272
264
  .replace(`/* $EVENT_TYPES$ */`, () => Str.indent(eventTypes.map(x => x.code).join('\n'), ' '))
273
- .replace(`/* $METHOD_TYPES$ */`, () => Str.indent(methodTypes.map(x => x.code).join('\n'), ' '))
265
+ .replace(`/* $METHOD_TYPES$ */`, () => Str.indent(methodTypings.map(x => x.code).join('\n'), ' '))
274
266
  //.replace(`/* $METHOD_INTERFACES$ */`, () => methodInterfacesArr.map(x => x.code).join('\n\n') + '\n\n' + methodInterfacesAll.code + '\n\n')
275
267
  ;
276
268
 
269
+ let codeDts = templateDts
270
+
271
+ .replace(`/* IMPORTS */`, () => imports.join('\n'))
272
+ .replace(`/* ERRORS */`, () => Gen.serializeErrors(className, abiJson))
273
+ .replace(/\$NAME\$/g, className)
274
+ .replace(`$ADDRESS$`, opts.address ? `'${opts.address}'` : 'null')
275
+ .replace(`/* METHODS */`, methodsTypings)
276
+ .replace(`/* EVENTS */`, eventsTypings)
277
+ .replace(`/* EVENTS_EXTRACTORS */`, eventsExtractorsTypings)
278
+ .replace(`/* EVENTS_FETCHERS */`, eventsFetchersTypings)
279
+ .replace(`$ABI$`, () => JSON.stringify(abiJson))
280
+ .replace(`$DATE$`, $date.format(new Date(), 'yyyy-MM-dd HH:mm'))
281
+ .replace(`$EXPLORER_URL$`, sourceUri)
282
+ //.replace(`/* $EVENT_INTERFACES$ */`, () => eventInterfaces.join('\n') + '\n\n' + eventInterfacesAll.code + '\n\n')
283
+
284
+ .replace(`/* STORAGE_READER_INITIALIZER */`, storageReaderInitializer)
285
+ .replace(`/* STORAGE_READER_PROPERTY */`, storageReaderProperty)
286
+ .replace(`/* STORAGE_READER_CLASS */`, () => storageReaderClassTypings)
287
+ .replace(`/* TX_CALLER_METHODS */`, () => Gen.serializeTxCallerMethods(className, abiJson)[targetType])
288
+ .replace(`/* TX_DATA_METHODS */`, () => Gen.serializeTxDataMethods(className, abiJson)[targetType])
289
+
290
+
291
+ .replace(`/* $EVENT_TYPES$ */`, () => Str.indent(eventTypes.map(x => x.code).join('\n'), ' '))
292
+ .replace(`/* $METHOD_TYPES$ */`, () => Str.indent(methodTypings.map(x => x.code).join('\n'), ' '))
293
+ ;
277
294
 
278
295
 
279
296
  await File.writeAsync(outputPath, code, { skipHooks: true });
297
+ if (targetType === 'js') {
298
+ let outputPathDts = outputPath.replace(/\.\w+$/, '.d.ts');
299
+ await File.writeAsync(outputPathDts, codeDts, { skipHooks: true });
300
+ }
301
+
280
302
 
281
303
  if (opts.saveAbi) {
282
304
  let path = class_Uri.combine(opts.output, outputDirectory, `${outputFilename}Abi.json`);
@@ -372,7 +394,7 @@ namespace Gen {
372
394
  };
373
395
  }
374
396
 
375
- export function serializeMethodTypeTs(name: string, abis: TAbiItem[]) {
397
+ export function serializeMethodTypingsTs(name: string, abis: TAbiItem[]) {
376
398
  let args = abis.map(abi => {
377
399
  let { fnInputArgumentsTargets } = serializeArgumentsTs(abi);
378
400
  return `[ ${fnInputArgumentsTargets.ts} ]`;
@@ -443,6 +465,9 @@ namespace Gen {
443
465
  return this.$onLog('${abi.name}', fn);
444
466
  }
445
467
  `,
468
+ types: `
469
+ on${abi.name} (fn?: (event: TClientEventsStreamData<TEventArguments<'${abi.name}'>>) => void): ClientEventsStream<TClientEventsStreamData<TEventArguments<'${abi.name}'>>>
470
+ `,
446
471
  js: `
447
472
  on${abi.name} (fn) {
448
473
  return this.$onLog('${abi.name}', fn);
@@ -458,6 +483,9 @@ namespace Gen {
458
483
  return this.$extractLogs(tx, abi) as any as ITxLogItem<TEventParams<'${abi.name}'>>[];
459
484
  }
460
485
  `,
486
+ types: `
487
+ extractLogs${abi.name} (tx: TEth.TxReceipt): ITxLogItem<TEventParams<'${abi.name}'>>[]
488
+ `,
461
489
  js: `
462
490
  extractLogs${abi.name} (tx) {
463
491
  let abi = this.$getAbiItem('event', '${abi.name}');
@@ -481,13 +509,11 @@ namespace Gen {
481
509
  }
482
510
  `,
483
511
  types: `
484
- async getPastLogs${abi.name} (options?: {
512
+ getPastLogs${abi.name} (options?: {
485
513
  fromBlock?: number | Date
486
514
  toBlock?: number | Date
487
515
  params?: { ${indexedParams} }
488
- }): Promise<ITxLogItem<TEventParams<'${abi.name}'>>[]> {
489
- return await this.$getPastLogsParsed('${abi.name}', options) as any;
490
- }
516
+ }): Promise<ITxLogItem<TEventParams<'${abi.name}'>>[]>
491
517
  `,
492
518
  js: `
493
519
  async getPastLogs${abi.name} (options) {
@@ -536,7 +562,7 @@ namespace Gen {
536
562
  `,
537
563
  types: `
538
564
  // ${$abiUtils.getMethodSignature(abi)}
539
- async ${abi.name} (${fnInputArgumentsTargets.ts}): ${fnResult}
565
+ ${abi.name} (${fnInputArgumentsTargets.ts}): ${fnResult}
540
566
  `,
541
567
  js: `
542
568
  // ${$abiUtils.getMethodSignature(abi)}
@@ -568,7 +594,7 @@ namespace Gen {
568
594
  `,
569
595
  types: `
570
596
  ${overrides}
571
- async ${abi.name} (...args): ${fnResult}
597
+ ${abi.name} (...args): ${fnResult}
572
598
  `,
573
599
  js: `
574
600
  async ${abi.name} (...args) {
@@ -594,7 +620,7 @@ namespace Gen {
594
620
  `,
595
621
  types: `
596
622
  // ${$abiUtils.getMethodSignature(abi)}
597
- async ${abi.name} (sender: TSender, ${fnInputArgumentsTargets.ts}): Promise<TxWriter>
623
+ ${abi.name} (sender: TSender, ${fnInputArgumentsTargets.ts}): Promise<TxWriter>
598
624
  `,
599
625
  js: `
600
626
  // ${$abiUtils.getMethodSignature(abi)}
@@ -616,7 +642,7 @@ namespace Gen {
616
642
  }
617
643
  `,
618
644
  types: `
619
- async $constructor (deployer: TSender, ${fnInputArgumentsTargets.ts}): Promise<TxWriter>
645
+ $constructor (deployer: TSender, ${fnInputArgumentsTargets.ts}): Promise<TxWriter>
620
646
  `,
621
647
  js: `
622
648
  async $constructor (deployer, ${fnInputArgumentsTargets.js}) {
@@ -646,7 +672,7 @@ namespace Gen {
646
672
  `,
647
673
  types: `
648
674
  ${overrides}
649
- async ${abi.name} (sender: TSender, ...args): Promise<TxWriter>
675
+ ${abi.name} (sender: TSender, ...args): Promise<TxWriter>
650
676
  `,
651
677
  js: `
652
678
  async ${abi.name} (sender, ...args) {
@@ -24,7 +24,7 @@ export class GeneratorStorageReader {
24
24
  [file: string]: { content: string }
25
25
  },
26
26
  client?: Web3Client
27
- }): Promise<{ code?: string, className?: string, sourcePath?: string, error?: Error }> {
27
+ }): Promise<{ code?: string, types?: string, className?: string, sourcePath?: string, error?: Error }> {
28
28
 
29
29
  let targetType = opts.target ?? 'ts';
30
30
  let { client, sources, contractName, address } = opts;
@@ -60,19 +60,29 @@ export class GeneratorStorageReader {
60
60
 
61
61
  let methods = this.serializeSlots(slots);
62
62
  let codeMethods = methods.map(x => x[targetType]).join('\n\n');
63
+ let codeMethodsTypings = methods.map(x => x.types).join('\n\n');
63
64
 
64
- let templatePath = $path.resolve(`/src/gen/ContractStorageReaderTemplate.${targetType}`);
65
+ let templatePath = $path.resolve(`/src/gen/templates/ContractStorageReaderTemplate.${targetType}.tmpl`);
65
66
  let template = await File.readAsync<string>(templatePath, { skipHooks: true });
67
+
68
+ let templateTypingsPath = $path.resolve(`/src/gen/templates/ContractStorageReaderTemplate.d.ts.tmpl`);
69
+ let templateTypings = await File.readAsync<string>(templateTypingsPath, { skipHooks: true });
70
+
66
71
  let className = $gen.toClassName(opts.name + 'StorageReader');
67
72
  let code = template
68
73
  .replace(`$NAME$`, className)
69
74
  .replace(`/* METHODS */`, () => codeMethods)
70
75
  .replace(`$SLOTS$`, () => JSON.stringify(slots, null, ' '))
71
76
 
77
+ let codeTypings = templateTypings
78
+ .replace(`$NAME$`, className)
79
+ .replace(`/* METHODS */`, () => codeMethodsTypings)
80
+ .replace(`$SLOTS$`, () => JSON.stringify(slots, null, ' '))
72
81
 
73
82
  return {
74
83
  className: className,
75
84
  code: code,
85
+ types: codeTypings,
76
86
  sourcePath: file.path
77
87
  };
78
88
  }
@@ -84,6 +94,7 @@ export class GeneratorStorageReader {
84
94
  return {
85
95
  ts: Str.formatMethod(entry.ts),
86
96
  js: Str.formatMethod(entry.js),
97
+ types: Str.formatMethod(entry.types),
87
98
  }
88
99
  });
89
100
  }
@@ -98,6 +109,9 @@ export class GeneratorStorageReader {
98
109
  return this.$storage.get(['${name}', ${ parametersCall ?? '' }]);
99
110
  }
100
111
  `,
112
+ types: `
113
+ ${name}(${parametersTypes?.ts ?? ''}): Promise<${returnType}>
114
+ `,
101
115
  js: `
102
116
  async ${name}(${parametersTypes?.js ?? ''}) {
103
117
  return this.$storage.get(['${name}', ${ parametersCall ?? '' }]);
@@ -0,0 +1,7 @@
1
+ declare class $NAME$ extends ContractStorageReaderBase {
2
+
3
+ /* METHODS */
4
+
5
+ $slots: $SLOTS$
6
+
7
+ }
@@ -3,24 +3,24 @@
3
3
  * Implementation: $EXPLORER_URL$
4
4
  */
5
5
  import di from 'a-di';
6
- import { TAddress } from '@dequanto/models/TAddress';
7
- import { TAccount } from '@dequanto/models/TAccount';
8
- import { TBufferLike } from '@dequanto/models/TBufferLike';
9
- import { ClientEventsStream, TClientEventsStreamData } from '@dequanto/clients/ClientEventsStream';
10
- import { ContractBase } from '@dequanto/contracts/ContractBase';
11
- import { ContractBaseUtils } from '@dequanto/contracts/utils/ContractBaseUtils';
12
- import { ContractStorageReaderBase } from '@dequanto/contracts/ContractStorageReaderBase';
13
- import { TxWriter } from '@dequanto/txs/TxWriter';
14
- import { ITxLogItem } from '@dequanto/txs/receipt/ITxLogItem';
15
- import { Web3Client } from '@dequanto/clients/Web3Client';
16
- import { IBlockChainExplorer } from '@dequanto/explorer/IBlockChainExplorer';
17
- import { SubjectStream } from '@dequanto/class/SubjectStream';
18
-
19
-
20
- import type { ContractWriter } from '@dequanto/contracts/ContractWriter';
21
- import type { TAbiItem } from '@dequanto/types/TAbi';
22
- import type { TEth } from '@dequanto/models/TEth';
23
- import type { TOverrideReturns } from '@dequanto/utils/types';
6
+ import { TAddress } from 'dequanto/models/TAddress';
7
+ import { TAccount } from 'dequanto/models/TAccount';
8
+ import { TBufferLike } from 'dequanto/models/TBufferLike';
9
+ import { ClientEventsStream, TClientEventsStreamData } from 'dequanto/clients/ClientEventsStream';
10
+ import { ContractBase } from 'dequanto/contracts/ContractBase';
11
+ import { ContractBaseUtils } from 'dequanto/contracts/utils/ContractBaseUtils';
12
+ import { ContractStorageReaderBase } from 'dequanto/contracts/ContractStorageReaderBase';
13
+ import { TxWriter } from 'dequanto/txs/TxWriter';
14
+ import { ITxLogItem } from 'dequanto/txs/receipt/ITxLogItem';
15
+ import { Web3Client } from 'dequanto/clients/Web3Client';
16
+ import { IBlockChainExplorer } from 'dequanto/explorer/IBlockChainExplorer';
17
+ import { SubjectStream } from 'dequanto/class/SubjectStream';
18
+
19
+
20
+ import type { ContractWriter } from 'dequanto/contracts/ContractWriter';
21
+ import type { TAbiItem } from 'dequanto/types/TAbi';
22
+ import type { TEth } from 'dequanto/models/TEth';
23
+ import type { TOverrideReturns } from 'dequanto/utils/types';
24
24
 
25
25
 
26
26
  /* IMPORTS */
@@ -28,16 +28,15 @@ import type { TOverrideReturns } from '@dequanto/utils/types';
28
28
  /* ERRORS */
29
29
 
30
30
  export declare class $NAME$ extends ContractBase {
31
- constructor(public address: TEth.Address,
32
- public client: Web3Client,
33
- public explorer: IBlockChainExplorer,
34
- )
31
+
35
32
 
36
33
  Types: T$NAME$Types;
37
34
 
35
+
36
+
38
37
  /* METHODS */
39
38
 
40
- $call (): TxCaller
39
+ $call (): I$NAME$TxCaller
41
40
  $signed (): TOverrideReturns<I$NAME$TxCaller, Promise<{ signed: TEth.Hex, error?: Error & { data?: { type: string, params } } }>>
42
41
  $data (): I$NAME$TxData
43
42
  $gas (): TOverrideReturns<I$NAME$TxCaller, Promise<{ gas?: bigint, price?: bigint, error?: Error & { data?: { type: string, params } } }>>
@@ -54,15 +53,15 @@ export declare class $NAME$ extends ContractBase {
54
53
  onLog (event: keyof TEvents, cb?: (event: TClientEventsStreamData) => void): ClientEventsStream<TClientEventsStreamData>
55
54
 
56
55
 
57
- async getPastLogs <TEventName extends keyof TEvents> (
58
- events: TEventName[]
59
- , options?: TEventLogOptions<TEventParams<TEventName>>
56
+ getPastLogs <TEventName extends keyof TEvents> (
57
+ events: TEventName[], options?: TEventLogOptions<TEventParams<TEventName>>
60
58
  ): Promise<ITxLogItem<TEventParams<TEventName>, TEventName>[]>
61
- async getPastLogs <TEventName extends keyof TEvents> (
62
- event: TEventName
63
- , options?: TEventLogOptions<TEventParams<TEventName>>
59
+
60
+ getPastLogs <TEventName extends keyof TEvents> (
61
+ event: TEventName, options?: TEventLogOptions<TEventParams<TEventName>>
64
62
  ): Promise<ITxLogItem<TEventParams<TEventName>, TEventName>[]>
65
- async getPastLogs (mix: any, options?): Promise<any>
63
+
64
+ getPastLogs (mix: any, options?): Promise<any>
66
65
 
67
66
  /* EVENTS */
68
67
 
@@ -38,6 +38,8 @@ import { Constructor } from '@dequanto/utils/types';
38
38
 
39
39
  type THardhatLib = typeof import('hardhat');
40
40
 
41
+ const rgx_CONTRACT_NAME = /contract\s+(?<contractName>[\w_]+)/ig;
42
+
41
43
  export class HardhatProvider {
42
44
 
43
45
  @memd.deco.memoize()
@@ -302,12 +304,14 @@ export class HardhatProvider {
302
304
 
303
305
  const files = await Directory.readFilesAsync(paths.sources, '*.sol');
304
306
 
305
- return await alot(files).mapAsync(async file => {
307
+ const results = await alot(files).mapAsync(async file => {
306
308
  let solContractPath = file.uri.toLocalFile();
307
309
  return await this.getContractFromSolPath(solContractPath, {
308
310
  paths
309
311
  });
310
312
  }).toArrayAsync();
313
+
314
+ return results.filter(x => x != null);
311
315
  }
312
316
 
313
317
  async compileSol<T extends ContractBase = IContractWrapped> (solContractPath: string, options?: {
@@ -476,6 +480,10 @@ export class HardhatProvider {
476
480
  }) {
477
481
  let outputDir = class_Uri.combine(options.paths.artifacts, solContractPath, '/');
478
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
+ }
479
487
  throw new Error(`No JSONs found in ${outputDir} for ${solContractPath}`);
480
488
  }
481
489
 
@@ -496,11 +504,6 @@ export class HardhatProvider {
496
504
  if (filename == null) {
497
505
  throw new Error(`Filename not extracted from ${solContractPath}`);
498
506
  }
499
-
500
-
501
- // Filename could contain random number, extract main-name
502
-
503
-
504
507
  let files = await Directory.readFilesAsync(outputDir);
505
508
  let jsons = files.filter(x => /(?<!dbg)\.json$/.test(x.uri.file));
506
509
  if (jsons.length === 0) {
@@ -515,24 +518,15 @@ export class HardhatProvider {
515
518
 
516
519
  let jsonFile = getJsonFile(jsons, filename);
517
520
  if (jsonFile == null) {
521
+ // Filename could contain random number, extract main-name
518
522
  const filenameRndSuffix = filename.replace(/_\d+$/, '');
519
523
  if (filenameRndSuffix != null) {
520
524
  jsonFile = getJsonFile(jsons, filenameRndSuffix);
521
525
  }
522
526
  }
523
527
  if (jsonFile == null) {
524
- let sourceFile = solContractPath;
525
- if (await File.existsAsync(sourceFile) === false) {
526
- sourceFile = class_Uri.combine(options.paths.root, sourceFile);
527
- }
528
- if (await File.existsAsync(sourceFile) === false) {
529
- throw new Error(`Source file "${solContractPath}" not found in ${options.paths.root}`);
530
- }
531
-
532
-
533
- let source = await File.readAsync<string>(sourceFile);
534
- let rgx = /contract \s*(?<contractName>[\w_]+)/ig;
535
- let matches = Array.from(source.matchAll(rgx));
528
+ let source = await this.getSolFileContent(solContractPath, options);
529
+ let matches = Array.from(source.matchAll(rgx_CONTRACT_NAME));
536
530
  let contractName = matches[matches.length - 1]?.groups?.contractName;
537
531
  options.contractName = contractName;
538
532
  jsonFile = getJsonFile(jsons, contractName);
@@ -567,11 +561,23 @@ export class HardhatProvider {
567
561
  return { root, artifacts };
568
562
  }
569
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
+ }
570
572
 
571
- private async getContractFromSolPath <T extends ContractBase = IContractWrapped> (solContractPath, options: {
573
+ let source = await File.readAsync<string>(sourceFile);
574
+ return source;
575
+ }
576
+
577
+ public async getContractFromSolPath <T extends ContractBase = IContractWrapped> (solContractPath: string, options?: {
572
578
  contractName?: string
573
579
  paths: {
574
- sources: string
580
+ sources?: string
575
581
  root?: string;
576
582
  artifacts?: string;
577
583
  };
@@ -586,7 +592,10 @@ export class HardhatProvider {
586
592
  root,
587
593
  artifacts,
588
594
  },
589
- })
595
+ });
596
+ if (artifactJsonPath == null) {
597
+ return null;
598
+ }
590
599
 
591
600
  let { abi, bytecode, contractName, linkReferences } = await File.readAsync<IJsonArtifact> (artifactJsonPath);
592
601
  let { contract, ContractCtor } = ContractClassFactory.fromAbi<T>(null, abi, null, null, {
@@ -598,7 +607,9 @@ export class HardhatProvider {
598
607
  }
599
608
  })
600
609
 
601
- let files = await Directory.readFilesAsync(options.paths.sources, '*.sol');
610
+ let files = options?.paths?.sources
611
+ ? await Directory.readFilesAsync(options.paths.sources, '*.sol')
612
+ : [];
602
613
  let fileMap = await alot(files)
603
614
  .mapAsync(async file => {
604
615
  return {
@@ -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';