@quentinadam/evm-base 0.1.1 → 0.1.3

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.
@@ -0,0 +1,6 @@
1
+ export default class MethodSignatureRegistry {
2
+ #private;
3
+ static register(method: string): void;
4
+ static decode(selector: string): string | undefined;
5
+ }
6
+ //# sourceMappingURL=MethodSignatureRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodSignatureRegistry.d.ts","sourceRoot":"","sources":["../src/MethodSignatureRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,OAAO,uBAAuB;;IAG1C,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAI9B,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAwBpD"}
@@ -0,0 +1,31 @@
1
+ import keccak256 from '@quentinadam/hash/keccak256';
2
+ export default class MethodSignatureRegistry {
3
+ static #methods = new Map();
4
+ static register(method) {
5
+ this.#methods.set(keccak256(method).slice(0, 4).toHex(), method);
6
+ }
7
+ static decode(selector) {
8
+ return this.#methods.get(selector);
9
+ }
10
+ static {
11
+ /* @__PURE__ */ (() => {
12
+ const methods = [
13
+ 'approve(address,uint256)',
14
+ 'burn(address,uint256)',
15
+ 'burn(uint256)',
16
+ 'deposit()',
17
+ 'mint(address,uint256)',
18
+ 'mint(uint256)',
19
+ 'sweep()',
20
+ 'sweep(address)',
21
+ 'transfer(address,uint256)',
22
+ 'transferFrom(address,address,uint256)',
23
+ 'withdraw(uint256)',
24
+ ];
25
+ for (const method of methods) {
26
+ this.register(method);
27
+ }
28
+ })();
29
+ }
30
+ }
31
+ //# sourceMappingURL=MethodSignatureRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodSignatureRegistry.js","sourceRoot":"","sources":["../src/MethodSignatureRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,6BAA6B,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C,MAAM,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE5C,MAAM,CAAC,QAAQ,CAAC,MAAc;QAC5B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED;QACE,eAAe,CAAC,CAAC,GAAG,EAAE;YACpB,MAAM,OAAO,GAAG;gBACd,0BAA0B;gBAC1B,uBAAuB;gBACvB,eAAe;gBACf,WAAW;gBACX,uBAAuB;gBACvB,eAAe;gBACf,SAAS;gBACT,gBAAgB;gBAChB,2BAA2B;gBAC3B,uCAAuC;gBACvC,mBAAmB;aACpB,CAAC;YACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACxB,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function createInspectableDataWrapper(bytes: Uint8Array): object;
2
+ //# sourceMappingURL=createInspectableDataWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInspectableDataWrapper.d.ts","sourceRoot":"","sources":["../src/createInspectableDataWrapper.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CA8B9E"}
@@ -0,0 +1,29 @@
1
+ import MethodSignatureRegistry from "./MethodSignatureRegistry.js";
2
+ export default function createInspectableDataWrapper(bytes) {
3
+ return new (class InspectableDataWrapper {
4
+ #bytes;
5
+ constructor(bytes) {
6
+ this.#bytes = bytes;
7
+ }
8
+ #customInspect(inspect, options) {
9
+ if (this.#bytes.length === 0) {
10
+ return inspect([], options);
11
+ }
12
+ const selector = this.#bytes.slice(0, 4).toHex();
13
+ const lines = [MethodSignatureRegistry.decode(selector) ?? selector];
14
+ let index = 4;
15
+ while (index < this.#bytes.length) {
16
+ lines.push(this.#bytes.slice(index, index + 32).toHex());
17
+ index += 32;
18
+ }
19
+ return inspect(lines, options);
20
+ }
21
+ [Symbol.for('Deno.customInspect')](inspect, options) {
22
+ return this.#customInspect(inspect, options);
23
+ }
24
+ [Symbol.for('nodejs.util.inspect.custom')](_depth, options, inspect) {
25
+ return this.#customInspect(inspect, options);
26
+ }
27
+ })(bytes);
28
+ }
29
+ //# sourceMappingURL=createInspectableDataWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInspectableDataWrapper.js","sourceRoot":"","sources":["../src/createInspectableDataWrapper.ts"],"names":[],"mappings":"AACA,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAAC,KAAiB;IACpE,OAAO,IAAI,CAAC,MAAM,sBAAsB;QAC7B,MAAM,CAAa;QAE5B,YAAY,KAAiB;YAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACtB,CAAC;QAED,cAAc,CAAC,OAAkB,EAAE,OAAgB;YACjD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC7B,OAAO,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YAC9B,CAAC;YACD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,CAAC,uBAAuB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC;YACrE,IAAI,KAAK,GAAG,CAAC,CAAC;YACd,OAAO,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;gBACzD,KAAK,IAAI,EAAE,CAAC;YACd,CAAC;YACD,OAAO,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC;QAED,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,OAAkB,EAAE,OAAgB;YACrE,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QAED,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,CAAC,MAAc,EAAE,OAAgB,EAAE,OAAkB;YAC7F,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC,CAAC,KAAK,CAAC,CAAC;AACZ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function createInspectableScaledBigIntWrapper(value: bigint, exponent: number): object;
2
+ //# sourceMappingURL=createInspectableScaledBigIntWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInspectableScaledBigIntWrapper.d.ts","sourceRoot":"","sources":["../src/createInspectableScaledBigIntWrapper.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,oCAAoC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAqCpG"}
@@ -0,0 +1,34 @@
1
+ export default function createInspectableScaledBigIntWrapper(value, exponent) {
2
+ return new (class ScaledBigInt {
3
+ #value;
4
+ #exponent;
5
+ constructor(value, exponent) {
6
+ this.#value = value;
7
+ this.#exponent = exponent;
8
+ }
9
+ [Symbol.for('Deno.customInspect')](inspect, options) {
10
+ return this.#customInspect(inspect, options);
11
+ }
12
+ [Symbol.for('nodejs.util.inspect.custom')](_depth, options, inspect) {
13
+ return this.#customInspect(inspect, options);
14
+ }
15
+ toString() {
16
+ return ((string) => {
17
+ return string.slice(0, -this.#exponent) + '.' + string.slice(-this.#exponent);
18
+ })(this.#value.toString().padStart(this.#exponent + 1, '0')).replace(/\.?0+$/, '') + 'e' + this.#exponent;
19
+ }
20
+ #customInspect(inspect, options) {
21
+ const stylize = options.stylize;
22
+ if (typeof stylize === 'function') {
23
+ return stylize(this.toString(), 'number');
24
+ }
25
+ const coloredNumber = inspect(0, options);
26
+ // deno-lint-ignore no-control-regex
27
+ const start = coloredNumber.match(/^\x1b\[[0-9;]*m/)?.[0] ?? '';
28
+ // deno-lint-ignore no-control-regex
29
+ const end = coloredNumber.match(/\x1b\[[0-9;]*m$/)?.[0] ?? '';
30
+ return `${start}${this.toString()}${end}`;
31
+ }
32
+ })(value, exponent);
33
+ }
34
+ //# sourceMappingURL=createInspectableScaledBigIntWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInspectableScaledBigIntWrapper.js","sourceRoot":"","sources":["../src/createInspectableScaledBigIntWrapper.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,oCAAoC,CAAC,KAAa,EAAE,QAAgB;IAC1F,OAAO,IAAI,CAAC,MAAM,YAAY;QACnB,MAAM,CAAC;QACP,SAAS,CAAC;QAEnB,YAAY,KAAa,EAAE,QAAgB;YACzC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC5B,CAAC;QAED,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,OAAkB,EAAE,OAAgB;YACrE,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QAED,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,CAAC,MAAc,EAAE,OAAgB,EAAE,OAAkB;YAC7F,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QAED,QAAQ;YACN,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;gBACjB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAChF,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5G,CAAC;QAED,cAAc,CAAC,OAAkB,EAAE,OAAgB;YACjD,MAAM,OAAO,GAAI,OAA0B,CAAC,OAAO,CAAC;YACpD,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;gBAClC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;YAC5C,CAAC;YACD,MAAM,aAAa,GAAG,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC1C,oCAAoC;YACpC,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAChE,oCAAoC;YACpC,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC9D,OAAO,GAAG,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,GAAG,EAAE,CAAC;QAC5C,CAAC;KACF,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type InspectFn = (value: unknown, options?: unknown) => string;
2
+ export type InspectOptions = {
3
+ stylize?: ((text: string, styleType: string) => string) | undefined;
4
+ };
5
+ //# sourceMappingURL=inspect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../src/inspect.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;AACtE,MAAM,MAAM,cAAc,GAAG;IAAE,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=inspect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.js","sourceRoot":"","sources":["../src/inspect.ts"],"names":[],"mappings":""}
package/dist/mod.d.ts CHANGED
@@ -4,12 +4,15 @@ import computeCREATE2Address from './computeCREATE2Address.ts';
4
4
  import computeCREATEAddress from './computeCREATEAddress.ts';
5
5
  import Client from './Client.ts';
6
6
  import ClientError from './ClientError.ts';
7
+ import createInspectableDataWrapper from './createInspectableDataWrapper.ts';
8
+ import createInspectableScaledBigIntWrapper from './createInspectableScaledBigIntWrapper.ts';
7
9
  import DataEncoder from './DataEncoder.ts';
8
10
  import ClientHelper from './ClientHelper.ts';
9
11
  import type Log from './Log.ts';
12
+ import MethodSignatureRegistry from './MethodSignatureRegistry.ts';
10
13
  import MulticallClient from './MulticallClient.ts';
11
14
  import type Transaction from './Transaction.ts';
12
15
  import type TransactionReceipt from './TransactionReceipt.ts';
13
- export { ABI, Client, ClientError, ClientHelper, computeCREATE2Address, computeCREATEAddress, DataEncoder, MulticallClient, };
16
+ export { ABI, Client, ClientError, ClientHelper, computeCREATE2Address, computeCREATEAddress, createInspectableDataWrapper, createInspectableScaledBigIntWrapper, DataEncoder, MethodSignatureRegistry, MulticallClient, };
14
17
  export type { Block, Log, Transaction, TransactionReceipt };
15
18
  //# sourceMappingURL=mod.d.ts.map
package/dist/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,CAAC;AAEF,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAC7E,OAAO,oCAAoC,MAAM,2CAA2C,CAAC;AAC7F,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,4BAA4B,EAC5B,oCAAoC,EACpC,WAAW,EACX,uBAAuB,EACvB,eAAe,GAChB,CAAC;AAEF,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/mod.js CHANGED
@@ -3,8 +3,11 @@ import computeCREATE2Address from "./computeCREATE2Address.js";
3
3
  import computeCREATEAddress from "./computeCREATEAddress.js";
4
4
  import Client from "./Client.js";
5
5
  import ClientError from "./ClientError.js";
6
+ import createInspectableDataWrapper from "./createInspectableDataWrapper.js";
7
+ import createInspectableScaledBigIntWrapper from "./createInspectableScaledBigIntWrapper.js";
6
8
  import DataEncoder from "./DataEncoder.js";
7
9
  import ClientHelper from "./ClientHelper.js";
10
+ import MethodSignatureRegistry from "./MethodSignatureRegistry.js";
8
11
  import MulticallClient from "./MulticallClient.js";
9
- export { ABI, Client, ClientError, ClientHelper, computeCREATE2Address, computeCREATEAddress, DataEncoder, MulticallClient, };
12
+ export { ABI, Client, ClientError, ClientHelper, computeCREATE2Address, computeCREATEAddress, createInspectableDataWrapper, createInspectableScaledBigIntWrapper, DataEncoder, MethodSignatureRegistry, MulticallClient, };
10
13
  //# sourceMappingURL=mod.js.map
package/dist/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAInD,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,CAAC"}
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAC7E,OAAO,oCAAoC,MAAM,2CAA2C,CAAC;AAC7F,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAInD,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,4BAA4B,EAC5B,oCAAoC,EACpC,WAAW,EACX,uBAAuB,EACvB,eAAe,GAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quentinadam/evm-base",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "EVM base library",
5
5
  "license": "MIT",
6
6
  "author": "Quentin Adam",
@@ -0,0 +1,34 @@
1
+ import keccak256 from '@quentinadam/hash/keccak256';
2
+
3
+ export default class MethodSignatureRegistry {
4
+ static #methods = new Map<string, string>();
5
+
6
+ static register(method: string) {
7
+ this.#methods.set(keccak256(method).slice(0, 4).toHex(), method);
8
+ }
9
+
10
+ static decode(selector: string): string | undefined {
11
+ return this.#methods.get(selector);
12
+ }
13
+
14
+ static {
15
+ /* @__PURE__ */ (() => {
16
+ const methods = [
17
+ 'approve(address,uint256)',
18
+ 'burn(address,uint256)',
19
+ 'burn(uint256)',
20
+ 'deposit()',
21
+ 'mint(address,uint256)',
22
+ 'mint(uint256)',
23
+ 'sweep()',
24
+ 'sweep(address)',
25
+ 'transfer(address,uint256)',
26
+ 'transferFrom(address,address,uint256)',
27
+ 'withdraw(uint256)',
28
+ ];
29
+ for (const method of methods) {
30
+ this.register(method);
31
+ }
32
+ })();
33
+ }
34
+ }
@@ -0,0 +1,34 @@
1
+ import type { InspectFn } from './inspect.ts';
2
+ import MethodSignatureRegistry from './MethodSignatureRegistry.ts';
3
+
4
+ export default function createInspectableDataWrapper(bytes: Uint8Array): object {
5
+ return new (class InspectableDataWrapper {
6
+ readonly #bytes: Uint8Array;
7
+
8
+ constructor(bytes: Uint8Array) {
9
+ this.#bytes = bytes;
10
+ }
11
+
12
+ #customInspect(inspect: InspectFn, options: unknown): string {
13
+ if (this.#bytes.length === 0) {
14
+ return inspect([], options);
15
+ }
16
+ const selector = this.#bytes.slice(0, 4).toHex();
17
+ const lines = [MethodSignatureRegistry.decode(selector) ?? selector];
18
+ let index = 4;
19
+ while (index < this.#bytes.length) {
20
+ lines.push(this.#bytes.slice(index, index + 32).toHex());
21
+ index += 32;
22
+ }
23
+ return inspect(lines, options);
24
+ }
25
+
26
+ [Symbol.for('Deno.customInspect')](inspect: InspectFn, options: unknown): string {
27
+ return this.#customInspect(inspect, options);
28
+ }
29
+
30
+ [Symbol.for('nodejs.util.inspect.custom')](_depth: number, options: unknown, inspect: InspectFn): string {
31
+ return this.#customInspect(inspect, options);
32
+ }
33
+ })(bytes);
34
+ }
@@ -0,0 +1,40 @@
1
+ import type { InspectFn, InspectOptions } from './inspect.ts';
2
+
3
+ export default function createInspectableScaledBigIntWrapper(value: bigint, exponent: number): object {
4
+ return new (class ScaledBigInt {
5
+ readonly #value;
6
+ readonly #exponent;
7
+
8
+ constructor(value: bigint, exponent: number) {
9
+ this.#value = value;
10
+ this.#exponent = exponent;
11
+ }
12
+
13
+ [Symbol.for('Deno.customInspect')](inspect: InspectFn, options: unknown): string {
14
+ return this.#customInspect(inspect, options);
15
+ }
16
+
17
+ [Symbol.for('nodejs.util.inspect.custom')](_depth: number, options: unknown, inspect: InspectFn): string {
18
+ return this.#customInspect(inspect, options);
19
+ }
20
+
21
+ toString() {
22
+ return ((string) => {
23
+ return string.slice(0, -this.#exponent) + '.' + string.slice(-this.#exponent);
24
+ })(this.#value.toString().padStart(this.#exponent + 1, '0')).replace(/\.?0+$/, '') + 'e' + this.#exponent;
25
+ }
26
+
27
+ #customInspect(inspect: InspectFn, options: unknown): string {
28
+ const stylize = (options as InspectOptions).stylize;
29
+ if (typeof stylize === 'function') {
30
+ return stylize(this.toString(), 'number');
31
+ }
32
+ const coloredNumber = inspect(0, options);
33
+ // deno-lint-ignore no-control-regex
34
+ const start = coloredNumber.match(/^\x1b\[[0-9;]*m/)?.[0] ?? '';
35
+ // deno-lint-ignore no-control-regex
36
+ const end = coloredNumber.match(/\x1b\[[0-9;]*m$/)?.[0] ?? '';
37
+ return `${start}${this.toString()}${end}`;
38
+ }
39
+ })(value, exponent);
40
+ }
package/src/inspect.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type InspectFn = (value: unknown, options?: unknown) => string;
2
+ export type InspectOptions = { stylize?: ((text: string, styleType: string) => string) | undefined };
package/src/mod.ts CHANGED
@@ -4,9 +4,12 @@ import computeCREATE2Address from './computeCREATE2Address.ts';
4
4
  import computeCREATEAddress from './computeCREATEAddress.ts';
5
5
  import Client from './Client.ts';
6
6
  import ClientError from './ClientError.ts';
7
+ import createInspectableDataWrapper from './createInspectableDataWrapper.ts';
8
+ import createInspectableScaledBigIntWrapper from './createInspectableScaledBigIntWrapper.ts';
7
9
  import DataEncoder from './DataEncoder.ts';
8
10
  import ClientHelper from './ClientHelper.ts';
9
11
  import type Log from './Log.ts';
12
+ import MethodSignatureRegistry from './MethodSignatureRegistry.ts';
10
13
  import MulticallClient from './MulticallClient.ts';
11
14
  import type Transaction from './Transaction.ts';
12
15
  import type TransactionReceipt from './TransactionReceipt.ts';
@@ -18,7 +21,10 @@ export {
18
21
  ClientHelper,
19
22
  computeCREATE2Address,
20
23
  computeCREATEAddress,
24
+ createInspectableDataWrapper,
25
+ createInspectableScaledBigIntWrapper,
21
26
  DataEncoder,
27
+ MethodSignatureRegistry,
22
28
  MulticallClient,
23
29
  };
24
30