dequanto 0.2.33 → 0.2.35

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 (43) hide show
  1. package/lib/cjs/clients/ClientPool.js +2 -2
  2. package/lib/cjs/clients/ClientPool.js.map +1 -1
  3. package/lib/cjs/clients/Web3BatchRequests.js +2 -2
  4. package/lib/cjs/clients/Web3BatchRequests.js.map +1 -1
  5. package/lib/cjs/clients/Web3Client.js +4 -4
  6. package/lib/cjs/clients/Web3Client.js.map +1 -1
  7. package/lib/cjs/contracts/ContractBase.js +13 -2
  8. package/lib/cjs/contracts/ContractBase.js.map +1 -1
  9. package/lib/cjs/contracts/ContractReader.js +2 -2
  10. package/lib/cjs/contracts/ContractReader.js.map +1 -1
  11. package/lib/cjs/rpc/RpcBase.js +7 -1
  12. package/lib/cjs/rpc/RpcBase.js.map +1 -1
  13. package/lib/cjs/rpc/RpcContract.js +16 -4
  14. package/lib/cjs/rpc/RpcContract.js.map +1 -1
  15. package/lib/esm/clients/ClientPool.js.map +1 -1
  16. package/lib/esm/clients/ClientPool.mjs +2 -2
  17. package/lib/esm/clients/Web3BatchRequests.js.map +1 -1
  18. package/lib/esm/clients/Web3BatchRequests.mjs +2 -2
  19. package/lib/esm/clients/Web3Client.js.map +1 -1
  20. package/lib/esm/clients/Web3Client.mjs +4 -4
  21. package/lib/esm/contracts/ContractBase.js.map +1 -1
  22. package/lib/esm/contracts/ContractBase.mjs +13 -2
  23. package/lib/esm/contracts/ContractReader.js.map +1 -1
  24. package/lib/esm/contracts/ContractReader.mjs +2 -2
  25. package/lib/esm/rpc/RpcBase.js.map +1 -1
  26. package/lib/esm/rpc/RpcBase.mjs +7 -1
  27. package/lib/esm/rpc/RpcContract.js.map +1 -1
  28. package/lib/esm/rpc/RpcContract.mjs +16 -4
  29. package/lib/types/clients/ClientPool.d.ts +3 -1
  30. package/lib/types/clients/Web3BatchRequests.d.ts +3 -1
  31. package/lib/types/clients/Web3Client.d.ts +6 -2
  32. package/lib/types/contracts/ContractBase.d.ts +2 -2
  33. package/lib/types/contracts/ContractReader.d.ts +3 -1
  34. package/lib/types/rpc/RpcBase.d.ts +3 -1
  35. package/lib/types/rpc/RpcContract.d.ts +3 -1
  36. package/package.json +1 -1
  37. package/src/clients/ClientPool.ts +4 -2
  38. package/src/clients/Web3BatchRequests.ts +4 -2
  39. package/src/clients/Web3Client.ts +8 -4
  40. package/src/contracts/ContractBase.ts +16 -7
  41. package/src/contracts/ContractReader.ts +4 -2
  42. package/src/rpc/RpcBase.ts +9 -2
  43. package/src/rpc/RpcContract.ts +18 -4
@@ -32,18 +32,30 @@ export class RpcContract {
32
32
  throw err;
33
33
  }
34
34
  }
35
- async batch(req) {
35
+ async batch(req, options) {
36
36
  let requests = await this.getCallRequestsRaw(req);
37
37
  try {
38
- let responseArr = await this.client.batch(requests.map(x => x.methodRequest));
38
+ let responseArr = await this.client.batch(requests.map(x => x.methodRequest), options);
39
39
  return responseArr.map((resp, i) => {
40
40
  let abi = requests[i].methodAbi;
41
41
  if (abi == null) {
42
42
  return resp;
43
43
  }
44
- let outputs = abi.outputs;
44
+ let returnABI = abi.outputs;
45
+ if (resp != null && typeof resp === 'object' && 'error' in resp) {
46
+ let defaults = null;
47
+ try {
48
+ const defaultHex = $abiCoder.encode(returnABI, [null]);
49
+ defaults = utils.deserializeOutput(defaultHex, returnABI);
50
+ }
51
+ catch (error) { }
52
+ return {
53
+ defaults,
54
+ ...resp
55
+ };
56
+ }
45
57
  let hex = typeof resp === 'string' ? resp : resp.data;
46
- let result = utils.deserializeOutput(hex, outputs);
58
+ let result = utils.deserializeOutput(hex, returnABI);
47
59
  return result;
48
60
  });
49
61
  }
@@ -132,7 +132,9 @@ export declare class WClient {
132
132
  sendTransaction(tx: any): PromiseEvent<TEth.TxReceipt>;
133
133
  sign(address: TEth.Address, message: string): Promise<string>;
134
134
  signTypedData(address: TEth.Address, typedData: DataLike<RpcTypes.TypedData>): Promise<TEth.Hex>;
135
- callBatched<TResult = any>(requests: TRpc.IRpcAction[]): Promise<TResult[]>;
135
+ callBatched<TResult = any>(requests: TRpc.IRpcAction[], options?: {
136
+ allowErrors?: boolean;
137
+ }): Promise<TResult[]>;
136
138
  call<TResult extends PromiseLike<any>>(fn: (wClient: WClient) => TResult, options?: {
137
139
  batchRequestCount?: number;
138
140
  }): Promise<{
@@ -16,6 +16,8 @@ export declare namespace Web3BatchRequests {
16
16
  private rpc;
17
17
  private requests;
18
18
  constructor(rpc: Rpc, requests: TRpc.IRpcAction[]);
19
- execute(): Promise<any[]>;
19
+ execute(options?: {
20
+ allowErrors?: boolean;
21
+ }): Promise<any[]>;
20
22
  }
21
23
  }
@@ -34,7 +34,9 @@ export declare abstract class Web3Client implements IWeb3Client {
34
34
  constructor(options: IWeb3ClientOptions);
35
35
  constructor(endpoints: IRpcConfig[]);
36
36
  request<TResult = any>(req: TRpc.IRpcAction): Promise<TResult>;
37
- batch(requests: TRpc.IRpcAction[]): Promise<any[]>;
37
+ batch(requests: TRpc.IRpcAction[], options?: {
38
+ allowErrors?: boolean;
39
+ }): Promise<any[]>;
38
40
  getEventStream(address: TEth.Address, abi: TAbiItem[], event: string): ClientEventsStream<any>;
39
41
  with<TResult>(fn: (wClient: WClient) => Promise<TResult>): Promise<TResult>;
40
42
  getWeb3(options?: IPoolWeb3Request): Promise<void>;
@@ -44,7 +46,9 @@ export declare abstract class Web3Client implements IWeb3Client {
44
46
  subscribe(type: 'newHeads' | 'newBlockHeaders', callback?: (error: Error, blockHeader: TEth.Block) => void): Promise<RpcSubscription<TEth.Block>>;
45
47
  subscribe(type: 'newPendingTransactions' | 'pendingTransactions', callback?: (error: Error, transactionHash: TEth.Hex) => void): Promise<RpcSubscription<TEth.Hex>>;
46
48
  readContract(req: TRpcContractCall): Promise<any>;
47
- readContractBatch(requests: TRpcContractCall[]): Promise<any[]>;
49
+ readContractBatch(requests: TRpcContractCall[], options?: {
50
+ allowErrors?: boolean;
51
+ }): Promise<any[]>;
48
52
  getBalance(address: TEth.Address, blockNumber?: DataLike<RpcTypes.BlockNumberOrTagOrHash>): Promise<bigint>;
49
53
  getBalances(addresses: TEth.Address[], blockNumber?: DataLike<RpcTypes.BlockNumberOrTagOrHash>): Promise<bigint[]>;
50
54
  getTransactionCount(address: TEth.Address, blockNumber?: DataLike<RpcTypes.BlockNumberOrTagOrHash>): Promise<bigint>;
@@ -77,8 +77,8 @@ export declare abstract class ContractBase {
77
77
  value?: number | string | bigint;
78
78
  }, ...params: any[]): Promise<TxWriter>;
79
79
  protected $getAbiItem(type: 'event' | 'function' | 'string', name: string, argsCount?: number): TAbiItem;
80
- protected $getAbiItemOverload(fnName: string, args: any[]): any;
81
- protected $getAbiItemOverload(abis: (string | TAbiItem)[], args: any[]): any;
80
+ protected $getAbiItemOverload(fnName: string, args: any[]): TAbiItem;
81
+ protected $getAbiItemOverload(abis: (string | TAbiItem)[], args: any[]): TAbiItem;
82
82
  protected $extractLogs(tx: TEth.TxReceipt, abiItem: TAbiItem): ITxLogItem<{
83
83
  [name: string]: any;
84
84
  }, string>[];
@@ -87,5 +87,7 @@ export declare namespace ContractReaderUtils {
87
87
  type TIContractReadParamsInferredMany<T extends IContractReadParams[]> = {
88
88
  [P in keyof T]: T[P] extends IContractReadParams<infer P> ? P : never;
89
89
  };
90
- function readAsyncBatch(client: Web3Client, requests: (IContractReadParams | null)[]): Promise<any[]>;
90
+ function readAsyncBatch(client: Web3Client, requests: (IContractReadParams | null)[], options?: {
91
+ allowErrors?: boolean;
92
+ }): Promise<any[]>;
91
93
  }
@@ -8,7 +8,9 @@ export declare abstract class RpcBase {
8
8
  };
9
9
  constructor(transportInfo?: TTransport.Options.Any);
10
10
  request<TResult = any>(req: TRpc.IRpcAction): Promise<TResult>;
11
- batch(arr: TRpc.IRpcAction[]): Promise<any[]>;
11
+ batch(arr: TRpc.IRpcAction[], options?: {
12
+ allowErrors?: boolean;
13
+ }): Promise<any[]>;
12
14
  extend(rpcInfos: {
13
15
  name: string;
14
16
  call: string;
@@ -24,7 +24,9 @@ export declare class RpcContract {
24
24
  private defaults?;
25
25
  constructor(client: Web3Client, defaults?: TRpcContract);
26
26
  request(req: TRpcContractCall): Promise<any>;
27
- batch(req: TRpcContractCall[]): Promise<any[]>;
27
+ batch(req: TRpcContractCall[], options?: {
28
+ allowErrors?: boolean;
29
+ }): Promise<any[]>;
28
30
  private getCallRequestsRaw;
29
31
  private getCallRequestRaw;
30
32
  static createCalldata(request: TRpcContractCall, options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dequanto",
3
- "version": "0.2.33",
3
+ "version": "0.2.35",
4
4
  "author": {
5
5
  "name": "Alex Kit",
6
6
  "email": "alex.kit@atmajs.com"
@@ -911,7 +911,9 @@ export class WClient {
911
911
  .eth_signTypedData_v4(address, typedData);
912
912
  }
913
913
 
914
- async callBatched<TResult = any>(requests: TRpc.IRpcAction[]): Promise<TResult[]> {
914
+ async callBatched<TResult = any>(requests: TRpc.IRpcAction[], options?: {
915
+ allowErrors?: boolean
916
+ }): Promise<TResult[]> {
915
917
  let total = requests.length;
916
918
  let spanLimit = this.getSpanLimit(requests.length);
917
919
  let output = [] as TResult[];
@@ -925,7 +927,7 @@ export class WClient {
925
927
  }
926
928
  let { status, error, result: pageResult } = await this.call(async (client) => {
927
929
  let batch = new Web3BatchRequests.BatchRequest(client.rpc, page);
928
- let results = await batch.execute();
930
+ let results = await batch.execute(options);
929
931
  return results;
930
932
  });
931
933
  if (status === ClientStatus.Ok) {
@@ -38,13 +38,15 @@ export namespace Web3BatchRequests {
38
38
  constructor(private rpc: Rpc, private requests: TRpc.IRpcAction[]) {
39
39
  }
40
40
 
41
- async execute(): Promise<any[]> {
41
+ async execute(options?: {
42
+ allowErrors?: boolean
43
+ }): Promise<any[]> {
42
44
  if (this.requests.length === 0) {
43
45
  return [];
44
46
  }
45
47
 
46
48
  let rpc = this.rpc;
47
- let response = await rpc.batch(this.requests);
49
+ let response = await rpc.batch(this.requests, options);
48
50
  return response;
49
51
  }
50
52
 
@@ -97,9 +97,11 @@ export abstract class Web3Client implements IWeb3Client {
97
97
  });
98
98
  }
99
99
 
100
- async batch(requests: TRpc.IRpcAction[]): Promise<any[]> {
100
+ async batch(requests: TRpc.IRpcAction[], options?: {
101
+ allowErrors?: boolean
102
+ }): Promise<any[]> {
101
103
  return this.with (async web3 => {
102
- return web3.callBatched(requests);
104
+ return web3.callBatched(requests, options);
103
105
  });
104
106
  }
105
107
 
@@ -187,9 +189,11 @@ export abstract class Web3Client implements IWeb3Client {
187
189
  return result;
188
190
  }
189
191
 
190
- async readContractBatch(requests: TRpcContractCall[]) {
192
+ async readContractBatch(requests: TRpcContractCall[], options?: {
193
+ allowErrors?: boolean
194
+ }) {
191
195
  let reader = new RpcContract(this);
192
- let result = await reader.batch(requests);
196
+ let result = await reader.batch(requests, options);
193
197
  return result;
194
198
  }
195
199
 
@@ -65,7 +65,7 @@ export abstract class ContractBase {
65
65
  public client: Web3Client,
66
66
  public explorer: IBlockchainExplorer
67
67
  ) {
68
- if ($is.Address(address) && $contract.store.has(address) === false) {
68
+ if ($is.Address(address) && address !== $address.ZERO && $contract.store.has(address) === false) {
69
69
  const Ctor = this.constructor as Constructor<ContractBase>;
70
70
  const cloned = new Ctor(null, null, null);
71
71
  const meta = {
@@ -388,13 +388,12 @@ export abstract class ContractBase {
388
388
  return ContractBaseUtils.$getAbiItem(this.abi, type, name, argsCount);
389
389
  }
390
390
 
391
- protected $getAbiItemOverload(fnName: string, args: any[])
392
- protected $getAbiItemOverload(abis: (string | TAbiItem)[], args: any[])
393
- protected $getAbiItemOverload(mix: string | (string | TAbiItem)[], args: any[]) {
391
+ protected $getAbiItemOverload(fnName: string, args: any[]): TAbiItem
392
+ protected $getAbiItemOverload(abis: (string | TAbiItem)[], args: any[]): TAbiItem
393
+ protected $getAbiItemOverload(mix: string | (string | TAbiItem)[], args: any[]): TAbiItem {
394
394
  let abis = typeof mix === 'string'
395
395
  ? this.abi.filter(x => x.type === 'function' && x.name === mix)
396
396
  : mix;
397
-
398
397
  let $abis = abis
399
398
  .map(methodAbi => {
400
399
  if (typeof methodAbi === 'string') {
@@ -643,9 +642,20 @@ function filterABIbyArguments(abis: TAbiItem[], args: any[], tupleCheck: 'shallo
643
642
  if (item.type === 'string' && typeof arg === 'string') {
644
643
  continue;
645
644
  }
646
- if (/^u?int/.test(item.type) && (typeof arg === 'number' || typeof arg === 'bigint')) {
645
+ if (item.type === 'bytes32' && $is.HexBytes32(arg)) {
646
+ continue;
647
+ }
648
+ if (item.type === 'bytes' && $is.HexBytes32(arg)) {
647
649
  continue;
648
650
  }
651
+ if (/^u?int/.test(item.type)) {
652
+ if (typeof arg === 'number' || typeof arg === 'bigint') {
653
+ continue;
654
+ }
655
+ if (typeof arg === 'string' && /^\d+$/.test(arg)) {
656
+ continue;
657
+ }
658
+ }
649
659
  if (/tuple/.test(item.type)) {
650
660
  arg ??= {};
651
661
  if (tupleCheck === 'shallow') {
@@ -679,7 +689,6 @@ function filterABIbyArguments(abis: TAbiItem[], args: any[], tupleCheck: 'shallo
679
689
  }
680
690
  continue;
681
691
  }
682
-
683
692
  }
684
693
  return false;
685
694
  }
@@ -354,7 +354,9 @@ export namespace ContractReaderUtils {
354
354
 
355
355
  ;
356
356
 
357
- export async function readAsyncBatch(client: Web3Client, requests: (IContractReadParams | null)[]) {
357
+ export async function readAsyncBatch(client: Web3Client, requests: (IContractReadParams | null)[], options?: {
358
+ allowErrors?: boolean
359
+ }) {
358
360
 
359
361
  let rpcRequests = await alot(requests).map(async request => {
360
362
  if (request == null) {
@@ -389,7 +391,7 @@ export namespace ContractReaderUtils {
389
391
  mapped[i] = idx;
390
392
  }
391
393
 
392
- let outputs = await client.readContractBatch(rpcRequestsNotEmpty);
394
+ let outputs = await client.readContractBatch(rpcRequestsNotEmpty, options);
393
395
  return rpcRequests.map((_, i) => {
394
396
  return outputs[mapped[i]] ?? null;
395
397
  });
@@ -39,7 +39,9 @@ export abstract class RpcBase {
39
39
  return this._deserialize(req.method, result);
40
40
  }
41
41
 
42
- async batch (arr: TRpc.IRpcAction[]): Promise<any[]> {
42
+ async batch (arr: TRpc.IRpcAction[], options?: {
43
+ allowErrors?: boolean
44
+ }): Promise<any[]> {
43
45
  let body = arr.map(req => this._wrapBody(req));
44
46
  let resp = await this._transport.request(body);
45
47
  if (Array.isArray(resp) === false && arr.length === 1 && 'error' in resp === false && 'result' in resp === true) {
@@ -56,9 +58,14 @@ export abstract class RpcBase {
56
58
  return resp.map((resp, i) => {
57
59
  let req = arr[i];
58
60
  if ('error' in resp) {
61
+ if (options?.allowErrors) {
62
+ return {
63
+ error: new Error(resp.error.message),
64
+ request: req
65
+ };
66
+ }
59
67
  throw new RpcError(resp.error, `BatchRequest ${i + 1}/${arr.length} (${req.method} ${JSON.stringify(req.params)})`);
60
68
  }
61
-
62
69
  let result = this._unwrapBody(resp);
63
70
  return this._deserialize(req.method, result);
64
71
  });
@@ -63,20 +63,34 @@ export class RpcContract {
63
63
  }
64
64
  }
65
65
 
66
- async batch (req: TRpcContractCall[]) {
66
+ async batch (req: TRpcContractCall[], options?: {
67
+ allowErrors?: boolean
68
+ }) {
67
69
 
68
70
  let requests = await this.getCallRequestsRaw(req);
69
71
  try {
70
- let responseArr = await this.client.batch(requests.map(x => x.methodRequest));
72
+ let responseArr = await this.client.batch(requests.map(x => x.methodRequest), options);
71
73
 
72
74
  return responseArr.map((resp, i) => {
73
75
  let abi = requests[i].methodAbi;
74
76
  if (abi == null) {
75
77
  return resp;
76
78
  }
77
- let outputs = abi.outputs;
79
+ let returnABI = abi.outputs;
80
+
81
+ if (resp != null && typeof resp === 'object' && 'error' in resp) {
82
+ let defaults = null;
83
+ try {
84
+ const defaultHex = $abiCoder.encode(returnABI, [null]);
85
+ defaults = utils.deserializeOutput(defaultHex, returnABI);
86
+ } catch (error) {}
87
+ return {
88
+ defaults,
89
+ ...resp
90
+ };
91
+ }
78
92
  let hex = typeof resp === 'string' ? resp : resp.data;
79
- let result = utils.deserializeOutput(hex, outputs);
93
+ let result = utils.deserializeOutput(hex, returnABI);
80
94
  return result;
81
95
  });
82
96