@gibs/common 1.10.1 → 1.13.0

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,88 @@
1
+ /**
2
+ * Holds outgoing JSON-RPC requests back so no method crosses the endpoint's
3
+ * per-second ceiling.
4
+ *
5
+ * WHY BATCH SIZE WAS NOT ENOUGH, WHICH IS THE WHOLE POINT OF THIS FILE. The
6
+ * transport already caps a single post at the ceiling, and that stops one post
7
+ * being refused for being too big. It says nothing about how many posts leave
8
+ * per second. Measured on one page load: nine `eth_call` inside a single rolling
9
+ * second, spread across four posts of which none was individually too large, and
10
+ * the fourth came back `429`.
11
+ *
12
+ * A ROLLING WINDOW, NOT A BUCKET. The first measurement of this counted calls
13
+ * into whole seconds aligned to the page load and reported nothing over the
14
+ * ceiling while a refusal sat in the same run — six calls at 1.9 seconds and
15
+ * seven at 2.1 fall in different buckets and land 200 milliseconds apart. A rate
16
+ * limiter does not know when our page started, so neither does this.
17
+ *
18
+ * ONE LIMITER FOR THE WHOLE APPLICATION, not one per client — but keyed on the
19
+ * HOST as well as the method.
20
+ *
21
+ * The budget is the host's, and it is shared across chains: six
22
+ * `eth_blockNumber` on PulseChain plus six on Ethereum were answered exactly
23
+ * eight times, the same as twelve on one chain. So a limiter per client would
24
+ * let two chains spend one budget twice and neither would know.
25
+ *
26
+ * But two DIFFERENT hosts have two different budgets, and counting them
27
+ * together would throttle a spare endpoint for traffic it never received —
28
+ * which is exactly backwards once requests are spread across hosts on purpose.
29
+ */
30
+ /**
31
+ * The most calls of ONE method the proxy answers in one second. MEASURED.
32
+ *
33
+ * `one.valve.city` refuses past this with HTTP 429 and the body
34
+ * `Rate limit exceeded (per method, per second)`. Probed 2026-09-12 at
35
+ * concurrency 1, 2, 3, 4, 6, 8, 12, 16 and 24: every request up to eight was
36
+ * answered and everything past eight was refused, with no variance across
37
+ * twenty rounds. The budget is shared across CHAINS — six calls on chain 369
38
+ * plus six on chain 1 were answered exactly eight times, the same as twelve on
39
+ * one chain — so it is keyed on the method, not the chain.
40
+ *
41
+ * A BATCH THAT CROSSES THE CEILING IS REFUSED WHOLE, which is why this bounds
42
+ * the batch size. One post carrying sixteen `eth_blockNumber` calls came back
43
+ * with all sixteen refused; the same sixteen sent as separate posts had eight
44
+ * answered. Coalescing past the ceiling therefore converts a partial refusal
45
+ * into a total one, and viem's default of thirty-two calls per post is four
46
+ * times over it.
47
+ */
48
+ export declare const MAX_SAME_METHOD_CALLS_PER_SECOND = 8;
49
+ /** How the pacer reads the clock and waits, so a test can supply its own. */
50
+ export interface PacerClock {
51
+ /** Milliseconds, monotonic enough for a one-second window. */
52
+ now: () => number;
53
+ /** Resolves after roughly `ms`. */
54
+ sleep: (ms: number) => Promise<void>;
55
+ }
56
+ /** A paced sender. */
57
+ export interface RpcPacer {
58
+ /**
59
+ * Waits until `counts` can be spent without crossing the ceiling, then
60
+ * records them as spent.
61
+ *
62
+ * @param counts - how many calls of each method this request carries.
63
+ */
64
+ reserve: (host: string, counts: ReadonlyMap<string, number>) => Promise<void>;
65
+ /** How many calls of a method are inside the window for a host. Testing aid. */
66
+ spent: (host: string, method: string) => number;
67
+ }
68
+ /**
69
+ * Builds a pacer.
70
+ *
71
+ * @param options - the ceiling, and optionally a clock to drive it.
72
+ * @returns a pacer.
73
+ */
74
+ export declare const createRpcPacer: ({ ceiling, clock, }: {
75
+ ceiling: number;
76
+ clock?: PacerClock;
77
+ }) => RpcPacer;
78
+ /**
79
+ * Counts the calls per method in a JSON-RPC body.
80
+ *
81
+ * A batch is an ARRAY and a single call is an object; both arrive here, and a
82
+ * body that cannot be read at all counts as nothing rather than throwing —
83
+ * pacing is an optimisation and must never be the reason a request fails.
84
+ *
85
+ * @param body - the request body, as text.
86
+ * @returns method to how many calls of it the body carries.
87
+ */
88
+ export declare const countMethods: (body: string | null | undefined) => Map<string, number>;
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Holds outgoing JSON-RPC requests back so no method crosses the endpoint's
3
+ * per-second ceiling.
4
+ *
5
+ * WHY BATCH SIZE WAS NOT ENOUGH, WHICH IS THE WHOLE POINT OF THIS FILE. The
6
+ * transport already caps a single post at the ceiling, and that stops one post
7
+ * being refused for being too big. It says nothing about how many posts leave
8
+ * per second. Measured on one page load: nine `eth_call` inside a single rolling
9
+ * second, spread across four posts of which none was individually too large, and
10
+ * the fourth came back `429`.
11
+ *
12
+ * A ROLLING WINDOW, NOT A BUCKET. The first measurement of this counted calls
13
+ * into whole seconds aligned to the page load and reported nothing over the
14
+ * ceiling while a refusal sat in the same run — six calls at 1.9 seconds and
15
+ * seven at 2.1 fall in different buckets and land 200 milliseconds apart. A rate
16
+ * limiter does not know when our page started, so neither does this.
17
+ *
18
+ * ONE LIMITER FOR THE WHOLE APPLICATION, not one per client — but keyed on the
19
+ * HOST as well as the method.
20
+ *
21
+ * The budget is the host's, and it is shared across chains: six
22
+ * `eth_blockNumber` on PulseChain plus six on Ethereum were answered exactly
23
+ * eight times, the same as twelve on one chain. So a limiter per client would
24
+ * let two chains spend one budget twice and neither would know.
25
+ *
26
+ * But two DIFFERENT hosts have two different budgets, and counting them
27
+ * together would throttle a spare endpoint for traffic it never received —
28
+ * which is exactly backwards once requests are spread across hosts on purpose.
29
+ */
30
+ /**
31
+ * The most calls of ONE method the proxy answers in one second. MEASURED.
32
+ *
33
+ * `one.valve.city` refuses past this with HTTP 429 and the body
34
+ * `Rate limit exceeded (per method, per second)`. Probed 2026-09-12 at
35
+ * concurrency 1, 2, 3, 4, 6, 8, 12, 16 and 24: every request up to eight was
36
+ * answered and everything past eight was refused, with no variance across
37
+ * twenty rounds. The budget is shared across CHAINS — six calls on chain 369
38
+ * plus six on chain 1 were answered exactly eight times, the same as twelve on
39
+ * one chain — so it is keyed on the method, not the chain.
40
+ *
41
+ * A BATCH THAT CROSSES THE CEILING IS REFUSED WHOLE, which is why this bounds
42
+ * the batch size. One post carrying sixteen `eth_blockNumber` calls came back
43
+ * with all sixteen refused; the same sixteen sent as separate posts had eight
44
+ * answered. Coalescing past the ceiling therefore converts a partial refusal
45
+ * into a total one, and viem's default of thirty-two calls per post is four
46
+ * times over it.
47
+ */
48
+ export const MAX_SAME_METHOD_CALLS_PER_SECOND = 8;
49
+ const systemClock = {
50
+ now: () => Date.now(),
51
+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
52
+ };
53
+ /** The window the ceiling is counted over. */
54
+ const WINDOW_MS = 1_000;
55
+ /**
56
+ * Builds a pacer.
57
+ *
58
+ * @param options - the ceiling, and optionally a clock to drive it.
59
+ * @returns a pacer.
60
+ */
61
+ export const createRpcPacer = ({ ceiling, clock = systemClock, }) => {
62
+ /** When each still-counting call was sent, per host-and-method, oldest first. */
63
+ const sent = new Map();
64
+ /**
65
+ * Reservations run ONE AT A TIME, chained. Two callers checking the window
66
+ * concurrently both see room and both take it — the classic check-then-act
67
+ * race, and the reason a limiter that looks right can still emit bursts. The
68
+ * chain makes "is there room" and "take it" a single step.
69
+ */
70
+ let queue = Promise.resolve();
71
+ const forget = (method, now) => {
72
+ const times = sent.get(method);
73
+ if (!times)
74
+ return [];
75
+ // Times are appended in order, so everything expired is a prefix.
76
+ let keep = 0;
77
+ while (keep < times.length && now - times[keep] >= WINDOW_MS)
78
+ keep += 1;
79
+ const live = keep === 0 ? times : times.slice(keep);
80
+ sent.set(method, live);
81
+ return live;
82
+ };
83
+ const reserveOne = async (key, count) => {
84
+ // A request carrying MORE than the ceiling of one method cannot ever fit,
85
+ // and waiting for room that will never exist would hang the page forever.
86
+ // The transport caps a post at the ceiling, so this is a guard against a
87
+ // caller that bypassed it rather than an expected path: spend what there is
88
+ // and let the endpoint answer for the rest.
89
+ const want = Math.min(count, ceiling);
90
+ for (;;) {
91
+ const now = clock.now();
92
+ const live = forget(key, now);
93
+ if (live.length + want <= ceiling) {
94
+ for (let i = 0; i < count; i += 1)
95
+ live.push(now);
96
+ sent.set(key, live);
97
+ return;
98
+ }
99
+ // Wait exactly until the oldest call leaves the window — not a fixed
100
+ // retry interval, which would either spin or overshoot. The `+ 1` is so
101
+ // the comparison above is past the boundary rather than on it.
102
+ const oldest = live[0];
103
+ await clock.sleep(Math.max(1, oldest + WINDOW_MS - now + 1));
104
+ }
105
+ };
106
+ return {
107
+ reserve: (host, counts) => {
108
+ const run = queue.then(async () => {
109
+ // Ordered so the same body always reserves its methods in the same
110
+ // sequence; two bodies reserving the same pair in opposite orders is
111
+ // how a queue deadlocks itself.
112
+ for (const method of [...counts.keys()].sort()) {
113
+ await reserveOne(`${host}|${method}`, counts.get(method) ?? 0);
114
+ }
115
+ });
116
+ // The queue must continue even when a reservation throws, or one failure
117
+ // stops every later request on the page.
118
+ queue = run.catch(() => undefined);
119
+ return run;
120
+ },
121
+ spent: (host, method) => forget(`${host}|${method}`, clock.now()).length,
122
+ };
123
+ };
124
+ /**
125
+ * Counts the calls per method in a JSON-RPC body.
126
+ *
127
+ * A batch is an ARRAY and a single call is an object; both arrive here, and a
128
+ * body that cannot be read at all counts as nothing rather than throwing —
129
+ * pacing is an optimisation and must never be the reason a request fails.
130
+ *
131
+ * @param body - the request body, as text.
132
+ * @returns method to how many calls of it the body carries.
133
+ */
134
+ export const countMethods = (body) => {
135
+ const counts = new Map();
136
+ if (!body)
137
+ return counts;
138
+ let parsed;
139
+ try {
140
+ parsed = JSON.parse(body);
141
+ }
142
+ catch {
143
+ return counts;
144
+ }
145
+ const entries = Array.isArray(parsed) ? parsed : [parsed];
146
+ for (const entry of entries) {
147
+ const method = entry?.method;
148
+ if (typeof method !== 'string')
149
+ continue;
150
+ counts.set(method, (counts.get(method) ?? 0) + 1);
151
+ }
152
+ return counts;
153
+ };
@@ -4,9 +4,16 @@ type SerializedBigInt = {
4
4
  value: string;
5
5
  };
6
6
  /** The json any stringify for the given key and value */
7
- export declare const jsonAnyStringify: (key: string, value: unknown) => unknown;
7
+ export declare const jsonAnyStringify: (_key: string, value: unknown) => unknown;
8
8
  /** The is serialized big int for the given value */
9
9
  export declare const isSerializedBigInt: (value: unknown) => value is SerializedBigInt;
10
- /** The json any parse for the given key and value */
10
+ /**
11
+ * The json any parse for the given key and value.
12
+ *
13
+ * Throws on a corrupt encoded value rather than returning a number for it. Every
14
+ * caller reads from local storage inside a try/catch and falls back to a
15
+ * default, so a throw discards one unusable record; a silent zero would survive
16
+ * into the arithmetic.
17
+ */
11
18
  export declare const jsonAnyParse: (_key: string, value: unknown) => unknown;
12
19
  export {};
@@ -0,0 +1,42 @@
1
+ const BIGINT_TYPE = 'bigint';
2
+ /** The json any stringify for the given key and value */
3
+ export const jsonAnyStringify = (_key, value) => {
4
+ if (typeof value === BIGINT_TYPE) {
5
+ return {
6
+ __type__: BIGINT_TYPE,
7
+ value: value.toString(),
8
+ };
9
+ }
10
+ return value;
11
+ };
12
+ /** The is serialized big int for the given value */
13
+ export const isSerializedBigInt = (value) => {
14
+ return (!!value && typeof value === 'object' && value.__type__ === BIGINT_TYPE);
15
+ };
16
+ /**
17
+ * The only strings `jsonAnyStringify` ever writes: what `bigint.toString()`
18
+ * produces, which is an optional minus sign followed by decimal digits.
19
+ *
20
+ * Anything else in the `value` field means the record is corrupt, and `BigInt`
21
+ * is too permissive to notice. `BigInt('')` is 0n and `BigInt('0x10')` is 16n,
22
+ * so a truncated or garbled record parses into a plausible-looking balance
23
+ * instead of an error — and a wrong balance is spent, displayed and believed.
24
+ */
25
+ const DECIMAL_BIG_INT = /^-?\d+$/;
26
+ /**
27
+ * The json any parse for the given key and value.
28
+ *
29
+ * Throws on a corrupt encoded value rather than returning a number for it. Every
30
+ * caller reads from local storage inside a try/catch and falls back to a
31
+ * default, so a throw discards one unusable record; a silent zero would survive
32
+ * into the arithmetic.
33
+ */
34
+ export const jsonAnyParse = (_key, value) => {
35
+ if (isSerializedBigInt(value)) {
36
+ if (typeof value.value !== 'string' || !DECIMAL_BIG_INT.test(value.value)) {
37
+ throw new TypeError(`corrupt stored big integer: ${JSON.stringify(value.value)} is not a decimal integer`);
38
+ }
39
+ return BigInt(value.value);
40
+ }
41
+ return value;
42
+ };
@@ -1,4 +1,4 @@
1
- import type { Abi, Hex } from "viem";
1
+ import type { Abi, Hex } from 'viem';
2
2
  /** The inputs for a multicall read */
3
3
  export type Call = {
4
4
  allowFailure?: boolean;
package/package.json CHANGED
@@ -1,31 +1,101 @@
1
1
  {
2
2
  "name": "@gibs/common",
3
- "version": "1.10.1",
4
- "main": "index.js",
5
- "access": "public",
3
+ "version": "1.13.0",
4
+ "description": "Low-level blockchain helpers shared across the Gibs Finance packages: caching, multicall, and serialization.",
5
+ "keywords": [
6
+ "ethereum",
7
+ "pulsechain",
8
+ "viem",
9
+ "multicall",
10
+ "cache"
11
+ ],
12
+ "license": "ISC",
13
+ "author": "Gibs Finance",
14
+ "homepage": "https://gibs.finance",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/gibsfinance/bridge.git",
18
+ "directory": "packages/common"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/gibsfinance/bridge/issues"
22
+ },
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
6
26
  "type": "module",
27
+ "sideEffects": false,
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
7
30
  "exports": {
8
- ".": "./src/index.ts",
9
- "./erc20": "./src/erc20.ts",
10
- "./cache": "./src/cache.ts",
11
- "./serialize": "./src/serialize.ts",
12
- "./types": "./src/types.ts",
13
- "./multicall": "./src/multicall.ts",
14
- "./client": "./src/client.ts"
31
+ ".": {
32
+ "gibs-source": "./src/index.ts",
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./erc20": {
37
+ "gibs-source": "./src/erc20.ts",
38
+ "types": "./dist/erc20.d.ts",
39
+ "default": "./dist/erc20.js"
40
+ },
41
+ "./cache": {
42
+ "gibs-source": "./src/cache.ts",
43
+ "types": "./dist/cache.d.ts",
44
+ "default": "./dist/cache.js"
45
+ },
46
+ "./serialize": {
47
+ "gibs-source": "./src/serialize.ts",
48
+ "types": "./dist/serialize.d.ts",
49
+ "default": "./dist/serialize.js"
50
+ },
51
+ "./types": {
52
+ "gibs-source": "./src/types.ts",
53
+ "types": "./dist/types.d.ts",
54
+ "default": "./dist/types.js"
55
+ },
56
+ "./multicall": {
57
+ "gibs-source": "./src/multicall.ts",
58
+ "types": "./dist/multicall.d.ts",
59
+ "default": "./dist/multicall.js"
60
+ },
61
+ "./client": {
62
+ "gibs-source": "./src/client.ts",
63
+ "types": "./dist/client.d.ts",
64
+ "default": "./dist/client.js"
65
+ },
66
+ "./test-utils/fuzz": {
67
+ "gibs-source": "./src/test-utils/fuzz.ts",
68
+ "default": "./src/test-utils/fuzz.ts"
69
+ }
15
70
  },
71
+ "files": [
72
+ "dist",
73
+ "!dist/tsconfig.tsbuildinfo",
74
+ "!dist/**/*.test-d.*",
75
+ "!dist/test-utils",
76
+ "LICENSE"
77
+ ],
16
78
  "scripts": {
17
- "build": "npx tsc"
79
+ "prepublishOnly": "npx tsc",
80
+ "build": "npx tsc",
81
+ "test": "vitest run",
82
+ "test:watch": "vitest",
83
+ "test:coverage": "vitest run --coverage"
84
+ },
85
+ "dependencies": {
86
+ "lodash-es": "^4.17.21"
87
+ },
88
+ "peerDependencies": {
89
+ "viem": ">=2.37.0 <3"
18
90
  },
19
- "keywords": [],
20
- "author": "",
21
- "license": "ISC",
22
- "description": "",
23
91
  "devDependencies": {
24
- "@types/node": "^22.12.0",
25
- "typescript": "~5.7.2"
92
+ "@types/node": "^24",
93
+ "@vitest/coverage-v8": "^3.1.1",
94
+ "typescript": "~5.7.2",
95
+ "viem": "^2.46.3",
96
+ "vitest": "^3.1.1"
26
97
  },
27
- "dependencies": {
28
- "lodash": "^4.17.21",
29
- "viem": "^2.37.8"
98
+ "publishConfig": {
99
+ "access": "public"
30
100
  }
31
101
  }
@@ -1,30 +0,0 @@
1
- import { type Chain, type PublicClient } from "viem";
2
- /** The default batch config for the client */
3
- export declare const defaultBatchConfig: {
4
- batch: {
5
- wait: number;
6
- batchSize: number;
7
- };
8
- };
9
- /**
10
- * Returns the chain key for the given chain id and urls
11
- * @param chainId - the chain id
12
- * @param urls - the urls
13
- * @returns the chain key
14
- */
15
- export declare const chainKey: (chainId: number, urls: string[]) => string;
16
- /** The client cache for the given chain id */
17
- export declare const clientCache: Map<number, {
18
- key: string;
19
- client: PublicClient;
20
- }>;
21
- /**
22
- * Returns the client for the given chain and urls
23
- * @param chain - the chain
24
- * @param urls - the urls
25
- * @returns the client
26
- */
27
- export declare const clientFromChain: ({ chain, urls, }: {
28
- chain: Chain;
29
- urls: string[];
30
- }) => PublicClient;
@@ -1,55 +0,0 @@
1
- import { createPublicClient, fallback, http, webSocket } from "viem";
2
- /** The default batch config for the client */
3
- export const defaultBatchConfig = {
4
- batch: {
5
- wait: 10,
6
- batchSize: 32,
7
- },
8
- };
9
- /**
10
- * Returns the chain key for the given chain id and urls
11
- * @param chainId - the chain id
12
- * @param urls - the urls
13
- * @returns the chain key
14
- */
15
- export const chainKey = (chainId, urls) => {
16
- return `${chainId},${urls.join(',')}`.toLowerCase();
17
- };
18
- /** The client cache for the given chain id */
19
- export const clientCache = new Map();
20
- /**
21
- * Returns the client for the given chain and urls
22
- * @param chain - the chain
23
- * @param urls - the urls
24
- * @returns the client
25
- */
26
- export const clientFromChain = ({ chain, urls, }) => {
27
- const key = chainKey(chain.id, urls);
28
- const existing = clientCache.get(chain.id);
29
- if (existing && existing.key === key) {
30
- return existing.client;
31
- }
32
- const transport = !urls?.length
33
- ? http()
34
- : fallback(urls.map((rpc) => rpc.startsWith('http')
35
- ? http(rpc, {
36
- ...defaultBatchConfig,
37
- })
38
- : webSocket(rpc, {
39
- keepAlive: true,
40
- reconnect: true,
41
- retryDelay: 250,
42
- retryCount: 10,
43
- timeout: 4_000,
44
- ...defaultBatchConfig,
45
- })), { rank: true });
46
- const client = createPublicClient({
47
- chain,
48
- transport,
49
- });
50
- clientCache.set(chain.id, {
51
- key,
52
- client,
53
- });
54
- return client;
55
- };
@@ -1,13 +0,0 @@
1
- import { type Chain, type PublicClient, type Hex } from 'viem';
2
- import _ from 'lodash';
3
- import type { Erc20Metadata } from './types.js';
4
- /** The erc20 metadata calls */
5
- export declare const erc20MetadataCalls: {
6
- functionName: string;
7
- }[];
8
- /** The multicall for the erc20 metadata */
9
- export declare const multicallErc20: (({ client, target, chain }: {
10
- client: PublicClient;
11
- target: Hex;
12
- chain: Chain;
13
- }) => Promise<Erc20Metadata>) & _.MemoizedFunction;
@@ -1,10 +0,0 @@
1
- import { type Chain, type PublicClient, type Hex, type Abi } from 'viem';
2
- import type { Call } from './types.js';
3
- /** The multicall for the given chain, client, abi, calls, and target */
4
- export declare const multicallRead: <T>({ chain, client, abi, calls, target, }: {
5
- chain: Chain;
6
- client: PublicClient;
7
- abi: Abi;
8
- calls: Call[];
9
- target?: Hex;
10
- }) => Promise<T>;
@@ -1,44 +0,0 @@
1
- import { getContract, encodeFunctionData, decodeFunctionResult, multicall3Abi, } from 'viem';
2
- /** The multicall for the given chain, client, abi, calls, and target */
3
- export const multicallRead = async ({ chain, client, abi, calls, target, }) => {
4
- const multicall = getContract({
5
- abi: multicall3Abi,
6
- address: chain.contracts.multicall3.address,
7
- // this seems like a bug in viem, it should be able to infer the type of the client
8
- client: client,
9
- });
10
- const arg = calls.map((call) => ({
11
- callData: encodeFunctionData({
12
- abi: call.abi || abi,
13
- functionName: call.functionName,
14
- // this seems like a bug in viem, it should be able to infer the type of the args
15
- args: (call.args || []),
16
- }),
17
- allowFailure: call.allowFailure || false,
18
- target: (call.target || target),
19
- }));
20
- let reads = null;
21
- try {
22
- reads = await multicall.read.aggregate3([arg]);
23
- if (!reads)
24
- throw reads;
25
- const r = reads;
26
- return calls.map((call, i) => call.allowFailure
27
- ? r[i].success
28
- ? decodeFunctionResult({
29
- abi: call.abi || abi,
30
- functionName: call.functionName,
31
- data: r[i].returnData,
32
- })
33
- : r[i].returnData
34
- : decodeFunctionResult({
35
- abi: call.abi || abi,
36
- functionName: call.functionName,
37
- data: r[i].returnData,
38
- }));
39
- }
40
- catch (err) {
41
- console.error(client.chain?.id, target, calls, reads);
42
- throw err;
43
- }
44
- };
@@ -1,22 +0,0 @@
1
- const BIGINT_TYPE = 'bigint';
2
- /** The json any stringify for the given key and value */
3
- export const jsonAnyStringify = (key, value) => {
4
- if (typeof value === BIGINT_TYPE) {
5
- return {
6
- __type__: BIGINT_TYPE,
7
- value: value.toString(),
8
- };
9
- }
10
- return value;
11
- };
12
- /** The is serialized big int for the given value */
13
- export const isSerializedBigInt = (value) => {
14
- return (!!value && typeof value === 'object' && value.__type__ === BIGINT_TYPE);
15
- };
16
- /** The json any parse for the given key and value */
17
- export const jsonAnyParse = (_key, value) => {
18
- if (isSerializedBigInt(value)) {
19
- return BigInt(value.value);
20
- }
21
- return value;
22
- };