dequanto 0.2.8 → 0.2.12

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 (57) hide show
  1. package/lib/cjs/clients/debug/ClientDebugMethods.js +3 -13
  2. package/lib/cjs/clients/debug/ClientDebugMethods.js.map +1 -1
  3. package/lib/cjs/hardhat/HardhatProvider.js +7 -2
  4. package/lib/cjs/hardhat/HardhatProvider.js.map +1 -1
  5. package/lib/cjs/hardhat/HardhatWeb3Client.js +4 -0
  6. package/lib/cjs/hardhat/HardhatWeb3Client.js.map +1 -1
  7. package/lib/cjs/txs/TxDataBuilder.js +20 -0
  8. package/lib/cjs/txs/TxDataBuilder.js.map +1 -1
  9. package/lib/cjs/utils/$color.js +2 -2
  10. package/lib/cjs/utils/$color.js.map +1 -1
  11. package/lib/cjs/utils/$contract.js +10 -0
  12. package/lib/cjs/utils/$contract.js.map +1 -1
  13. package/lib/cjs/utils/$require.js +7 -0
  14. package/lib/cjs/utils/$require.js.map +1 -1
  15. package/lib/cjs/utils/$traces.js +492 -0
  16. package/lib/cjs/utils/$traces.js.map +1 -0
  17. package/lib/esm/clients/debug/ClientDebugMethods.js.map +1 -1
  18. package/lib/esm/clients/debug/ClientDebugMethods.mjs +3 -13
  19. package/lib/esm/hardhat/HardhatProvider.js.map +1 -1
  20. package/lib/esm/hardhat/HardhatProvider.mjs +7 -2
  21. package/lib/esm/hardhat/HardhatWeb3Client.js.map +1 -1
  22. package/lib/esm/hardhat/HardhatWeb3Client.mjs +4 -0
  23. package/lib/esm/txs/TxDataBuilder.js.map +1 -1
  24. package/lib/esm/txs/TxDataBuilder.mjs +20 -0
  25. package/lib/esm/utils/$color.js.map +1 -1
  26. package/lib/esm/utils/$color.mjs +1 -1
  27. package/lib/esm/utils/$contract.js.map +1 -1
  28. package/lib/esm/utils/$contract.mjs +10 -0
  29. package/lib/esm/utils/$require.js.map +1 -1
  30. package/lib/esm/utils/$require.mjs +7 -0
  31. package/lib/esm/utils/$traces.js.map +1 -0
  32. package/lib/esm/utils/$traces.mjs +486 -0
  33. package/lib/types/clients/debug/ClientDebugMethods.d.ts +18 -0
  34. package/lib/types/clients/interfaces/IWeb3Client.d.ts +4 -0
  35. package/lib/types/models/TEth.d.ts +2 -2
  36. package/lib/types/utils/$color.d.ts +62 -0
  37. package/lib/types/utils/$contract.d.ts +8 -0
  38. package/lib/types/utils/$require.d.ts +2 -0
  39. package/lib/types/utils/$traces.d.ts +18 -0
  40. package/package.json +1 -1
  41. package/src/clients/debug/ClientDebugMethods.ts +23 -14
  42. package/src/clients/interfaces/IWeb3Client.ts +4 -0
  43. package/src/hardhat/HardhatProvider.ts +8 -3
  44. package/src/hardhat/HardhatWeb3Client.ts +4 -0
  45. package/src/models/TEth.ts +2 -2
  46. package/src/txs/TxDataBuilder.ts +20 -0
  47. package/src/types/TAbi.ts +1 -1
  48. package/src/utils/$color.ts +1 -1
  49. package/src/utils/$contract.ts +17 -1
  50. package/src/utils/$require.ts +9 -0
  51. package/src/utils/$traces.ts +600 -0
  52. package/lib/cjs/utils/$sign.js +0 -118
  53. package/lib/cjs/utils/$sign.js.map +0 -1
  54. package/lib/esm/utils/$sign.js.map +0 -1
  55. package/lib/esm/utils/$sign.mjs +0 -117
  56. package/lib/types/utils/$sign.d.ts +0 -1
  57. package/src/utils/$sign.ts +0 -136
@@ -83,30 +83,39 @@ export class ClientDebugMethods {
83
83
  return this.call('autoMine', enabled);
84
84
  }
85
85
 
86
+ traceCall (data: TEth.TxLike, block?: number | string | 'latest', params?: {
87
+ disableMemory?: boolean
88
+ disableStack?: boolean
89
+ disableStorage?: boolean
90
+ }): Promise<TClientDebugTraces> {
91
+ return this.call('traceCall', data, block ?? 'latest', params);
92
+ }
93
+
86
94
  private call(method: keyof typeof this.methods, ...args: any[]) {
87
95
  let meta = this.methods[method];
88
96
  if (meta?.call == null) {
89
97
  throw new Error(`RPC method for ${method} is not configured in ${this.client.platform}`);
90
98
  }
91
99
  return this.client.pool.call(web3 => {
92
- //let eth = web3.eth as (typeof web3.eth & { [key in typeof method]: Function });
93
-
94
100
  return web3.rpc.request({
95
101
  method: meta.call,
96
102
  params: args
97
103
  });
98
- // if (eth[method] == null) {
99
- // web3.eth.extend({
100
- // methods: [
101
- // {
102
- // name: method,
103
- // call: meta.call,
104
- // params: meta.params,
105
- // }
106
- // ]
107
- // });
108
- // }
109
- // return eth[method](...args);
110
104
  })
111
105
  }
112
106
  }
107
+
108
+
109
+ export type TClientDebugTraces = {
110
+ failed?: boolean
111
+ returnValue?: TEth.Hex
112
+ structLogs?: {
113
+ depth: number
114
+ gas: number
115
+ gasCost: number
116
+ op: string
117
+ pc: number
118
+ memory?: string[]
119
+ stack?: string[]
120
+ }[]
121
+ }
@@ -65,6 +65,10 @@ export interface IWeb3ClientOptions {
65
65
  autoMine?: {
66
66
  call: 'evm_setAutomine' | string,
67
67
  params: 1 | number
68
+ },
69
+ traceCall?: {
70
+ call: 'debug_traceCall' | string,
71
+ params: 3 | number
68
72
  }
69
73
  }
70
74
  }
@@ -218,7 +218,10 @@ export class HardhatProvider {
218
218
  const receipt = await Factory.deploy();
219
219
  const { contract, ContractCtor } = await ContractClassFactory.fromAbi<TReturn>(receipt.contractAddress, abi, client, null);
220
220
  const explorer = await this.explorer();
221
- explorer.inMemoryDb.push({ name: '', abi: abi, address: receipt.contractAddress });
221
+
222
+ const meta = { name: options?.contractName, abi: abi, address: receipt.contractAddress };
223
+ explorer.inMemoryDb.push(meta);
224
+ $contract.store.register(meta);
222
225
 
223
226
  return {
224
227
  contract,
@@ -259,7 +262,9 @@ export class HardhatProvider {
259
262
  const { contract, ContractCtor } = await ContractClassFactory.fromAbi<TReturn>(receipt.contractAddress, abi, client, null);
260
263
 
261
264
  const explorer = await this.explorer();
262
- explorer.inMemoryDb.push({ name: '', abi: abi, address: receipt.contractAddress });
265
+ const meta = { name: options.contractName, abi: abi, address: receipt.contractAddress };
266
+ explorer.inMemoryDb.push(meta);
267
+ $contract.store.register(meta);
263
268
  return {
264
269
  contract,
265
270
  ContractCtor,
@@ -354,7 +359,6 @@ export class HardhatProvider {
354
359
  const hh = await this.getHardhat();
355
360
  await hh.run('compile', hhOptions);
356
361
 
357
-
358
362
  return await this.getContractFromSolPath<T> (solContractPath, {
359
363
  contractName: options?.contractName,
360
364
  paths
@@ -413,6 +417,7 @@ export class HardhatProvider {
413
417
  if (contractName == null) {
414
418
  let matches = Array.from(solidityCode.matchAll(/contract\s+(?<name>[\w]+)/g));
415
419
  contractName = matches[matches.length - 1].groups.name;
420
+ options.contractName = contractName;
416
421
  }
417
422
  $require.notNull(contractName, `Contract name not resolved from the code`);
418
423
  let rnd = $number.randomInt(0, 10**10);
@@ -62,6 +62,10 @@ export class HardhatWeb3Client extends Web3Client {
62
62
  autoMine: {
63
63
  call: 'evm_setAutomine',
64
64
  params: 1
65
+ },
66
+ traceCall: {
67
+ call: 'debug_traceCall',
68
+ params: 3
65
69
  }
66
70
  }
67
71
  });
@@ -192,8 +192,8 @@ export namespace TEth {
192
192
  }
193
193
 
194
194
  export namespace Abi {
195
- export type Type = 'function' | 'constructor' | 'event' | 'fallback';
196
- export type StateMutabilityType = 'pure' | 'view' | 'nonpayable' | 'payable';
195
+ export type Type = 'function' | 'constructor' | 'event' | 'error' | 'fallback' | 'receive';
196
+ export type StateMutabilityType = 'constant' | 'pure' | 'view' | 'nonpayable' | 'payable';
197
197
 
198
198
  export interface Item {
199
199
  anonymous?: boolean;
@@ -13,6 +13,7 @@ import { $abiUtils } from '@dequanto/utils/$abiUtils';
13
13
  import { $hex } from '@dequanto/utils/$hex';
14
14
  import { $contract } from '@dequanto/utils/$contract';
15
15
  import { TxNonceManager } from './TxNonceManager';
16
+ import { $traces } from '@dequanto/utils/$traces';
16
17
 
17
18
  export class TxDataBuilder {
18
19
 
@@ -268,6 +269,25 @@ export class TxDataBuilder {
268
269
  if (parsed) {
269
270
  message += `\nMethod: ` + $contract.formatCall(parsed);
270
271
  }
272
+ if (this.client.debug && this.client.debug.traceCall) {
273
+ try {
274
+ let txData = { from, ...this.data };
275
+ let traces = await this.client.debug.traceCall(txData);
276
+ let output = await $traces.format({
277
+ tx: txData,
278
+ traces,
279
+ color: false,
280
+ shortAddress: false,
281
+ async getABI(address) {
282
+ return $contract.store.getContract(address);
283
+ }
284
+ });
285
+ message += `\nTraces: \n` + output;
286
+ } catch (error) {
287
+ // ignore
288
+ }
289
+ }
290
+
271
291
  throw new Error(message);
272
292
  }
273
293
  }
package/src/types/TAbi.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  export type AbiType = 'function' | 'constructor' | 'event' | 'error' | 'fallback' | 'receive';
3
- export type StateMutabilityType = 'constant' |'pure' | 'view' | 'nonpayable' | 'payable';
3
+ export type StateMutabilityType = 'constant' | 'pure' | 'view' | 'nonpayable' | 'payable';
4
4
 
5
5
  export interface TAbiItem {
6
6
  anonymous?: boolean;
@@ -20,7 +20,7 @@ export function $color_options(opts: { type: 'none' | 'ascii' }) {
20
20
  : ColorData.ColorAscii
21
21
  };
22
22
 
23
- namespace ColorData {
23
+ export namespace ColorData {
24
24
 
25
25
  export const ColorAscii = {
26
26
  type: 'ascii',
@@ -295,15 +295,31 @@ export namespace $contract {
295
295
 
296
296
  export namespace store {
297
297
  const knownContracts = [] as {
298
+ name?: string
299
+ address?: TEth.Address
298
300
  abi: TAbiItem[]
299
301
  }[];
300
302
 
301
303
  export function getFlattened() {
302
304
  return alot(knownContracts).mapMany(x => x.abi).toArray();
303
305
  }
304
- export function register(contract: { abi: TAbiItem[] }) {
306
+ export function register(contract: {
307
+ address?: TEth.Address
308
+ name?: string
309
+ abi: TAbiItem[]
310
+ }) {
305
311
  knownContracts.push(contract)
306
312
  }
313
+
314
+ export function getContract(address: TEth.Address) {
315
+ return knownContracts.find(x => x.address === address);
316
+ }
317
+
318
+ export function getAbiItem(selector: TEth.Hex) {
319
+ return getFlattened().find(item => {
320
+ return $abiUtils.getMethodSignature(item) === selector;
321
+ });
322
+ }
307
323
  }
308
324
 
309
325
  function formatJson(json) {
@@ -126,6 +126,15 @@ export namespace $require {
126
126
  }
127
127
  }
128
128
 
129
+ export function has<T = any>(a: T, arr: T[], message?: string)
130
+ export function has<T = any>(a: string, str: string, message?: string)
131
+ export function has<T = any>(a: T, mix: T[] | string, message: string = '') {
132
+ // not strict equal
133
+ if (mix.includes(a as any) === false) {
134
+ throw new Error(`${a} should be contain ${typeof mix === 'string' ? mix : mix.join(', ')}. ${message}`)
135
+ }
136
+ }
137
+
129
138
  export function Address (val: TAddress | string, message: string = ''): TAddress {
130
139
  if ($is.Address(val) === false) {
131
140
  throw new Error(`Value ${val} is not a valid address. ${message}`);