@volga-sh/evm-ghostcall 0.0.3 → 0.0.5
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.
- package/README.md +62 -29
- package/dist/sdk/abi.d.ts +39 -0
- package/dist/sdk/abi.d.ts.map +1 -0
- package/dist/sdk/abi.js +20 -0
- package/dist/sdk/abi.js.map +1 -0
- package/dist/sdk/index.d.ts +56 -289
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +71 -312
- package/dist/sdk/index.js.map +1 -1
- package/package.json +15 -13
- package/src/Ghostcall.yul +15 -96
package/dist/sdk/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { validate as isAddress } from "ox/Address";
|
|
2
|
+
import { size as hexSize, validate as isHex } from "ox/Hex";
|
|
3
|
+
import { prepareAbiCall, } from "./abi.js";
|
|
1
4
|
import { ghostcallInitcode } from "./generated/initcode.js";
|
|
2
|
-
/**
|
|
3
|
-
* Error thrown when a strict Ghostcall batch encounters a failed subcall.
|
|
4
|
-
*/
|
|
5
|
+
/** A disallowed failure, with its zero-based index, executed call, and revert data. */
|
|
5
6
|
class GhostcallSubcallError extends Error {
|
|
6
7
|
index;
|
|
7
8
|
call;
|
|
@@ -12,139 +13,60 @@ class GhostcallSubcallError extends Error {
|
|
|
12
13
|
this.index = index;
|
|
13
14
|
this.call = call;
|
|
14
15
|
this.result = result;
|
|
15
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const encodedCallHeaderSize = 22;
|
|
19
19
|
const encodedHeaderHexLength = 4;
|
|
20
20
|
const maxCalldataSize = 0xffff;
|
|
21
|
-
const encodedCallHeaderSize = 0x16;
|
|
22
21
|
const defaultMaxCreateInitcodeSize = 0xc000;
|
|
23
22
|
const successFlagMask = 0x8000;
|
|
24
23
|
const returnDataLengthMask = 0x7fff;
|
|
25
|
-
const bundledInitcodeSize =
|
|
24
|
+
const bundledInitcodeSize = hexSize(ghostcallInitcode);
|
|
26
25
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* The returned hex string already includes the bundled Ghostcall initcode followed
|
|
31
|
-
* by the compact binary payload for each subcall, so callers can pass it directly
|
|
32
|
-
* as the `data` field of an `eth_call` request without supplying a `to` address.
|
|
33
|
-
* Each encoded subcall entry uses the compact layout `[len(2)][target(20)][data]`.
|
|
34
|
-
* The bundled initcode assumes appended bytes follow this exact shape; this
|
|
35
|
-
* function is the supported boundary for producing well-formed Ghostcall payloads.
|
|
36
|
-
*
|
|
37
|
-
* @param calls - Ordered list of subcalls to execute. Each entry becomes one
|
|
38
|
-
* Ghostcall payload segment in the same order it appears here.
|
|
39
|
-
* @param options - Optional encoding controls.
|
|
40
|
-
*
|
|
41
|
-
* @returns Full CREATE payload consisting of the bundled Ghostcall initcode plus
|
|
42
|
-
* the encoded call list.
|
|
43
|
-
*
|
|
44
|
-
* @throws {TypeError} If any call address or calldata value is not valid hex.
|
|
45
|
-
* @throws {RangeError} If any call data exceeds the protocol `uint16` length limit
|
|
46
|
-
* or if the full encoded CREATE payload would exceed the
|
|
47
|
-
* configured initcode size limit.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* const data = encodeCalls([
|
|
51
|
-
* {
|
|
52
|
-
* // USDC on Ethereum mainnet: balanceOf(Binance 14)
|
|
53
|
-
* to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
54
|
-
* data: "0x70a0823100000000000000000000000028c6c06298d514db089934071355e5743bf21d60",
|
|
55
|
-
* },
|
|
56
|
-
* {
|
|
57
|
-
* // WETH9 on Ethereum mainnet: totalSupply()
|
|
58
|
-
* to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
59
|
-
* data: "0x18160ddd",
|
|
60
|
-
* },
|
|
61
|
-
* ]);
|
|
62
|
-
*
|
|
63
|
-
* // Later:
|
|
64
|
-
* // provider.request({ method: "eth_call", params: [{ data }, "latest"] })
|
|
26
|
+
* Build CREATE-style eth_call data: initcode followed by [length (2)][target (20)][data].
|
|
27
|
+
* Send without a `to` address. Invalid inputs throw TypeError; size limits throw RangeError.
|
|
65
28
|
*/
|
|
66
|
-
function encodeCalls(calls,
|
|
29
|
+
function encodeCalls(calls, { maxInitcodeBytes = defaultMaxCreateInitcodeSize, } = {}) {
|
|
30
|
+
if (!Number.isSafeInteger(maxInitcodeBytes) || maxInitcodeBytes < 0) {
|
|
31
|
+
throw new TypeError("options.maxInitcodeBytes must be a non-negative safe integer");
|
|
32
|
+
}
|
|
67
33
|
const encodedParts = [ghostcallInitcode.slice(2)];
|
|
68
|
-
const maxInitcodeBytes = resolveMaxInitcodeBytes(options.maxInitcodeBytes);
|
|
69
34
|
let totalEncodedSize = bundledInitcodeSize;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
35
|
+
const sizeError = `encoded Ghostcall initcode exceeds the ${maxInitcodeBytes}-byte CREATE initcode limit`;
|
|
36
|
+
if (totalEncodedSize > maxInitcodeBytes)
|
|
37
|
+
throw new RangeError(sizeError);
|
|
73
38
|
for (const [index, call] of calls.entries()) {
|
|
74
39
|
assertAddress(call.to, `calls[${index}].to`);
|
|
75
40
|
const calldata = assertHex(call.data, `calls[${index}].data`);
|
|
76
|
-
const calldataSize =
|
|
41
|
+
const calldataSize = hexSize(calldata);
|
|
77
42
|
if (calldataSize > maxCalldataSize) {
|
|
78
43
|
throw new RangeError(`calls[${index}].data exceeds the ${maxCalldataSize}-byte calldata limit`);
|
|
79
44
|
}
|
|
80
45
|
totalEncodedSize += encodedCallHeaderSize + calldataSize;
|
|
81
|
-
if (totalEncodedSize > maxInitcodeBytes)
|
|
82
|
-
throw new RangeError(
|
|
83
|
-
|
|
84
|
-
encodedParts.push(calldataSize.toString(16).padStart(4, "0"));
|
|
85
|
-
encodedParts.push(call.to.slice(2));
|
|
86
|
-
encodedParts.push(calldata.slice(2));
|
|
46
|
+
if (totalEncodedSize > maxInitcodeBytes)
|
|
47
|
+
throw new RangeError(sizeError);
|
|
48
|
+
encodedParts.push(calldataSize.toString(16).padStart(4, "0"), call.to.slice(2), calldata.slice(2));
|
|
87
49
|
}
|
|
88
50
|
return `0x${encodedParts.join("")}`;
|
|
89
51
|
}
|
|
90
52
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* This is the provider-facing counterpart to {@link encodeCalls} and
|
|
94
|
-
* {@link decodeResults}. It sends the bundled Ghostcall initcode as the `data`
|
|
95
|
-
* field of `eth_call` without a `to` address, then returns raw result entries
|
|
96
|
-
* in the same order as the input calls. Request bytes are built through
|
|
97
|
-
* {@link encodeCalls}, so SDK callers get the supported payload validation before
|
|
98
|
-
* the RPC request is sent.
|
|
99
|
-
*
|
|
100
|
-
* By default, any failed subcall makes this method reject. Set
|
|
101
|
-
* `allowFailure: true` on a call to receive that failed entry in the returned
|
|
102
|
-
* results instead. Use {@link aggregateDecodedCalls} when you want a strict batch
|
|
103
|
-
* that returns decoded values directly. Use `options.ethCall` to forward `from`,
|
|
104
|
-
* `gas`, or `blockTag` to the outer `eth_call`.
|
|
105
|
-
*
|
|
106
|
-
* @param provider - EIP-1193-compatible provider with a `request` method.
|
|
107
|
-
* @param calls - Ordered list of subcalls to execute.
|
|
108
|
-
* @param options - Optional outer call and initcode controls.
|
|
109
|
-
*
|
|
110
|
-
* @returns Ordered Ghostcall result entries.
|
|
111
|
-
*
|
|
112
|
-
* @throws {TypeError} If inputs are not valid Ghostcall call entries or if the
|
|
113
|
-
* provider returns a non-hex `eth_call` result.
|
|
114
|
-
* @throws {RangeError} If the encoded CREATE payload exceeds protocol or the
|
|
115
|
-
* configured CREATE initcode ceiling.
|
|
116
|
-
* @throws {GhostcallSubcallError} If a subcall fails without `allowFailure: true`.
|
|
117
|
-
* @throws {Error} If the response entry count does not match the request entry count.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* const results = await aggregateCalls(provider, [
|
|
121
|
-
* {
|
|
122
|
-
* // USDC on Ethereum mainnet: balanceOf(Binance 14)
|
|
123
|
-
* to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
124
|
-
* data: "0x70a0823100000000000000000000000028c6c06298d514db089934071355e5743bf21d60",
|
|
125
|
-
* },
|
|
126
|
-
* {
|
|
127
|
-
* // WETH9 on Ethereum mainnet: totalSupply()
|
|
128
|
-
* to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
129
|
-
* data: "0x18160ddd",
|
|
130
|
-
* },
|
|
131
|
-
* ]);
|
|
53
|
+
* Execute a raw batch in order. Failed calls throw GhostcallSubcallError unless
|
|
54
|
+
* their entry sets allowFailure. Provider errors pass through unchanged.
|
|
132
55
|
*/
|
|
133
56
|
async function aggregateCalls(provider, calls, options) {
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
assertAddress(
|
|
140
|
-
ethCall.from =
|
|
141
|
-
}
|
|
142
|
-
if (
|
|
143
|
-
ethCall.gas = assertHexQuantity(
|
|
144
|
-
}
|
|
57
|
+
const { from, gas, blockTag } = options?.ethCall ?? {};
|
|
58
|
+
const ethCall = {
|
|
59
|
+
data: encodeCalls(calls, options ?? {}),
|
|
60
|
+
};
|
|
61
|
+
if (from !== undefined) {
|
|
62
|
+
assertAddress(from, "options.ethCall.from");
|
|
63
|
+
ethCall.from = from;
|
|
64
|
+
}
|
|
65
|
+
if (gas !== undefined)
|
|
66
|
+
ethCall.gas = assertHexQuantity(gas, "options.ethCall.gas");
|
|
145
67
|
const result = await provider.request({
|
|
146
68
|
method: "eth_call",
|
|
147
|
-
params: [ethCall, blockTag],
|
|
69
|
+
params: [ethCall, normalizeBlockTag(blockTag ?? "latest")],
|
|
148
70
|
});
|
|
149
71
|
const entries = decodeResults(assertHex(result, "eth_call result"));
|
|
150
72
|
if (entries.length !== calls.length) {
|
|
@@ -159,243 +81,80 @@ async function aggregateCalls(provider, calls, options) {
|
|
|
159
81
|
return entries;
|
|
160
82
|
}
|
|
161
83
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* Ghostcall initcode as the `data` field of `eth_call` without a `to` address,
|
|
166
|
-
* then runs each call's `decodeResult` callback over the successful return data in
|
|
167
|
-
* the same order as the input calls.
|
|
168
|
-
*
|
|
169
|
-
* `aggregateDecodedCalls` is always strict. Its TypeScript input shape requires a
|
|
170
|
-
* `decodeResult` callback on every call and does not accept `allowFailure`.
|
|
171
|
-
* Any failed subcall rejects with {@link GhostcallSubcallError}. Use
|
|
172
|
-
* {@link aggregateCalls} if you need raw failed entries. Use `options.ethCall`
|
|
173
|
-
* to forward `from`, `gas`, or `blockTag` to the outer `eth_call`.
|
|
174
|
-
*
|
|
175
|
-
* @param provider - EIP-1193-compatible provider with a `request` method.
|
|
176
|
-
* @param calls - Ordered list of strict decoded subcalls to execute.
|
|
177
|
-
* @param options - Optional outer call and initcode controls.
|
|
178
|
-
*
|
|
179
|
-
* @returns Ordered list of decoded values.
|
|
180
|
-
*
|
|
181
|
-
* @throws {TypeError} If inputs are not valid Ghostcall call entries or if the
|
|
182
|
-
* provider returns a non-hex `eth_call` result.
|
|
183
|
-
* @throws {RangeError} If the encoded CREATE payload exceeds protocol or the
|
|
184
|
-
* configured CREATE initcode ceiling.
|
|
185
|
-
* @throws {GhostcallSubcallError} If any subcall fails.
|
|
186
|
-
* @throws {Error} If the response entry count does not match the request entry count.
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* const erc20Abi = parseAbi([
|
|
190
|
-
* "function balanceOf(address account) view returns (uint256)",
|
|
191
|
-
* ]);
|
|
192
|
-
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
193
|
-
* const owner = "0x28C6c06298d514Db089934071355E5743bf21d60";
|
|
194
|
-
*
|
|
195
|
-
* const [balance] = await aggregateDecodedCalls(provider, [
|
|
196
|
-
* {
|
|
197
|
-
* to: usdc,
|
|
198
|
-
* data: "0x70a0823100000000000000000000000028c6c06298d514db089934071355e5743bf21d60",
|
|
199
|
-
* decodeResult: (returnData) => decodeFunctionResult({
|
|
200
|
-
* abi: erc20Abi,
|
|
201
|
-
* functionName: "balanceOf",
|
|
202
|
-
* data: returnData,
|
|
203
|
-
* }),
|
|
204
|
-
* },
|
|
205
|
-
* ]);
|
|
84
|
+
* Execute ABI-described calls or raw calls with custom decoders. Each tuple position
|
|
85
|
+
* retains its result type. Any failed call throws; encoding/decoding errors pass through.
|
|
86
|
+
* ABI-decoded addresses are checksummed, including addresses nested in tuples or arrays.
|
|
206
87
|
*/
|
|
207
88
|
async function aggregateDecodedCalls(provider, calls, options) {
|
|
208
|
-
const
|
|
89
|
+
const preparedCalls = calls.map((call) => call.abi === undefined ? call : prepareAbiCall(call));
|
|
90
|
+
const entries = await aggregateCalls(provider, preparedCalls, options);
|
|
209
91
|
return entries.map((entry, index) => {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
92
|
+
// aggregateCalls has checked the count. Hidden allowFailure fields still cannot
|
|
93
|
+
// bypass this guard and send failed returndata to a success-only decoder.
|
|
94
|
+
const call = preparedCalls[index];
|
|
95
|
+
if (!entry.success)
|
|
96
|
+
throw new GhostcallSubcallError(index, call, entry);
|
|
97
|
+
return call.decodeResult(entry.returnData, entry, index);
|
|
213
98
|
});
|
|
214
99
|
}
|
|
215
|
-
/**
|
|
216
|
-
* Decodes the packed result blob returned by Ghostcall.
|
|
217
|
-
*
|
|
218
|
-
* Each decoded entry corresponds to exactly one subcall in the original batch and
|
|
219
|
-
* preserves the original ordering. The SDK intentionally returns raw result bytes
|
|
220
|
-
* rather than ABI-decoding them so higher-level callers can apply their own
|
|
221
|
-
* decoding and failure policy.
|
|
222
|
-
*
|
|
223
|
-
* @param data - Raw bytes returned by Ghostcall, typically the direct result of a
|
|
224
|
-
* CREATE-style `eth_call`.
|
|
225
|
-
*
|
|
226
|
-
* @returns Ordered list of decoded Ghostcall result entries. Returns an empty
|
|
227
|
-
* array for `0x`.
|
|
228
|
-
*
|
|
229
|
-
* @throws {TypeError} If the provided data is not valid hex, if a result header is
|
|
230
|
-
* truncated, or if an entry body is shorter than advertised.
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* const results = decodeResults("0x8002cafe0004deadbeef");
|
|
234
|
-
*
|
|
235
|
-
* console.log(results);
|
|
236
|
-
* // [
|
|
237
|
-
* // { success: true, returnData: "0xcafe" },
|
|
238
|
-
* // { success: false, returnData: "0xdeadbeef" }
|
|
239
|
-
* // ]
|
|
240
|
-
*/
|
|
100
|
+
/** Decode ordered [success bit | uint15 length][returndata] entries. Reject malformed data. */
|
|
241
101
|
function decodeResults(data) {
|
|
242
|
-
const
|
|
243
|
-
if (normalizedData === "0x") {
|
|
244
|
-
return [];
|
|
245
|
-
}
|
|
102
|
+
const encodedData = assertHex(data, "data").slice(2);
|
|
246
103
|
const results = [];
|
|
247
|
-
const encodedData = normalizedData.slice(2);
|
|
248
104
|
let cursor = 0;
|
|
249
105
|
while (cursor < encodedData.length) {
|
|
250
106
|
if (cursor + encodedHeaderHexLength > encodedData.length) {
|
|
251
107
|
throw new TypeError("Truncated Ghostcall response header");
|
|
252
108
|
}
|
|
253
109
|
const header = Number.parseInt(encodedData.slice(cursor, cursor + encodedHeaderHexLength), 16);
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
const nextCursor = cursor + encodedHeaderHexLength;
|
|
257
|
-
const returnDataEnd = nextCursor + returnDataSize * 2;
|
|
110
|
+
cursor += encodedHeaderHexLength;
|
|
111
|
+
const returnDataEnd = cursor + (header & returnDataLengthMask) * 2;
|
|
258
112
|
if (returnDataEnd > encodedData.length) {
|
|
259
113
|
throw new TypeError("Truncated Ghostcall response body");
|
|
260
114
|
}
|
|
261
115
|
results.push({
|
|
262
|
-
success,
|
|
263
|
-
returnData: `0x${encodedData.slice(
|
|
116
|
+
success: (header & successFlagMask) !== 0,
|
|
117
|
+
returnData: `0x${encodedData.slice(cursor, returnDataEnd)}`,
|
|
264
118
|
});
|
|
265
119
|
cursor = returnDataEnd;
|
|
266
120
|
}
|
|
267
121
|
return results;
|
|
268
122
|
}
|
|
269
|
-
/**
|
|
270
|
-
* Validates that a value is a canonical 20-byte hex address.
|
|
271
|
-
*
|
|
272
|
-
* @param value - Unknown input to validate.
|
|
273
|
-
* @param label - Field name used in thrown error messages.
|
|
274
|
-
*
|
|
275
|
-
* @throws {TypeError} If the value is not valid `0x`-prefixed hex or is not
|
|
276
|
-
* exactly 20 bytes long.
|
|
277
|
-
*
|
|
278
|
-
* @internal
|
|
279
|
-
*/
|
|
280
123
|
function assertAddress(value, label) {
|
|
281
|
-
|
|
282
|
-
if (normalizedValue.length !== addressHexLength + 2) {
|
|
124
|
+
if (typeof value !== "string" || !isAddress(value, { strict: false })) {
|
|
283
125
|
throw new TypeError(`${label} must be a 20-byte hex string`);
|
|
284
126
|
}
|
|
285
127
|
}
|
|
286
|
-
/**
|
|
287
|
-
* Validates that a value is an even-length `0x`-prefixed hex string.
|
|
288
|
-
*
|
|
289
|
-
* @param value - Unknown input to validate.
|
|
290
|
-
* @param label - Field name used in thrown error messages.
|
|
291
|
-
*
|
|
292
|
-
* @returns The validated value narrowed to {@link Hex}.
|
|
293
|
-
*
|
|
294
|
-
* @throws {TypeError} If the value is not a string, lacks the `0x` prefix, has an
|
|
295
|
-
* odd number of hex characters, or contains non-hex digits.
|
|
296
|
-
*
|
|
297
|
-
* @internal
|
|
298
|
-
*/
|
|
299
128
|
function assertHex(value, label) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (!value.startsWith("0x")) {
|
|
304
|
-
throw new TypeError(`${label} must start with 0x`);
|
|
305
|
-
}
|
|
306
|
-
const rawValue = value.slice(2);
|
|
307
|
-
if (rawValue.length % 2 !== 0) {
|
|
308
|
-
throw new TypeError(`${label} must have an even number of hex characters`);
|
|
309
|
-
}
|
|
310
|
-
if (!/^[0-9a-fA-F]*$/.test(rawValue)) {
|
|
311
|
-
throw new TypeError(`${label} must contain only hexadecimal characters`);
|
|
129
|
+
// ox checks prefix/digits; the wire format additionally requires whole bytes.
|
|
130
|
+
if (!isHex(value, { strict: true }) || value.length % 2 !== 0) {
|
|
131
|
+
throw new TypeError(`${label} must be an even-length 0x-prefixed hex string`);
|
|
312
132
|
}
|
|
313
133
|
return value;
|
|
314
134
|
}
|
|
315
|
-
/**
|
|
316
|
-
* Validates that a value is an RPC hex quantity.
|
|
317
|
-
*
|
|
318
|
-
* @param value - Unknown input to validate.
|
|
319
|
-
* @param label - Field name used in thrown error messages.
|
|
320
|
-
* @returns The validated value narrowed to {@link HexQuantity}.
|
|
321
|
-
* @throws {TypeError} If the value is not a valid `0x`-prefixed quantity.
|
|
322
|
-
*
|
|
323
|
-
* @internal
|
|
324
|
-
*/
|
|
325
135
|
function assertHexQuantity(value, label) {
|
|
326
|
-
if (typeof value !== "string"
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
if (!/^0x(?:0|[1-9a-fA-F][0-9a-fA-F]*)$/.test(value)) {
|
|
136
|
+
if (typeof value !== "string" ||
|
|
137
|
+
!/^0x(?:0|[1-9a-fA-F][0-9a-fA-F]*)$/.test(value)) {
|
|
330
138
|
throw new TypeError(`${label} must be a 0x-prefixed hex quantity`);
|
|
331
139
|
}
|
|
332
140
|
return value;
|
|
333
141
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
if (typeof value === "bigint") {
|
|
352
|
-
if (value < 0n) {
|
|
353
|
-
throw new TypeError(`${label} must be a non-negative safe integer, bigint, or non-empty string`);
|
|
354
|
-
}
|
|
355
|
-
return `0x${value.toString(16)}`;
|
|
356
|
-
}
|
|
357
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
358
|
-
throw new TypeError(`${label} must be a non-negative safe integer, bigint, or non-empty string`);
|
|
359
|
-
}
|
|
360
|
-
if (/^-?[0-9]+$/.test(value)) {
|
|
361
|
-
if (value.startsWith("-")) {
|
|
362
|
-
throw new TypeError(`${label} must be a non-negative safe integer, bigint, or non-empty string`);
|
|
363
|
-
}
|
|
364
|
-
return `0x${BigInt(value).toString(16)}`;
|
|
365
|
-
}
|
|
366
|
-
if (value.startsWith("0x") || value.startsWith("0X")) {
|
|
367
|
-
return assertHexQuantity(`0x${value.slice(2)}`, label);
|
|
368
|
-
}
|
|
369
|
-
return value;
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Resolves the active CREATE initcode ceiling.
|
|
373
|
-
*
|
|
374
|
-
* @param value - Optional caller override.
|
|
375
|
-
* @returns Active initcode ceiling in bytes.
|
|
376
|
-
* @throws {TypeError} If the override is not a non-negative safe integer.
|
|
377
|
-
*
|
|
378
|
-
* @internal
|
|
379
|
-
*/
|
|
380
|
-
function resolveMaxInitcodeBytes(value) {
|
|
381
|
-
if (value === undefined) {
|
|
382
|
-
return defaultMaxCreateInitcodeSize;
|
|
383
|
-
}
|
|
384
|
-
if (!Number.isSafeInteger(value) || value < 0) {
|
|
385
|
-
throw new TypeError("options.maxInitcodeBytes must be a non-negative safe integer");
|
|
386
|
-
}
|
|
387
|
-
return value;
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Returns the byte length of a validated hex string.
|
|
391
|
-
*
|
|
392
|
-
* @param value - Validated hex string.
|
|
393
|
-
* @returns Number of bytes represented by {@link value}.
|
|
394
|
-
*
|
|
395
|
-
* @internal
|
|
396
|
-
*/
|
|
397
|
-
function byteLength(value) {
|
|
398
|
-
return (value.length - 2) / 2;
|
|
142
|
+
function normalizeBlockTag(value) {
|
|
143
|
+
if (typeof value === "bigint" ||
|
|
144
|
+
(typeof value === "number" && Number.isSafeInteger(value))) {
|
|
145
|
+
if (value >= 0)
|
|
146
|
+
return `0x${value.toString(16)}`;
|
|
147
|
+
}
|
|
148
|
+
else if (typeof value === "string" &&
|
|
149
|
+
value.length > 0 &&
|
|
150
|
+
!/^-\d+$/.test(value)) {
|
|
151
|
+
if (/^\d+$/.test(value))
|
|
152
|
+
return `0x${BigInt(value).toString(16)}`;
|
|
153
|
+
return /^0x/i.test(value)
|
|
154
|
+
? assertHexQuantity(`0x${value.slice(2)}`, "options.ethCall.blockTag")
|
|
155
|
+
: value;
|
|
156
|
+
}
|
|
157
|
+
throw new TypeError("options.ethCall.blockTag must be a non-negative safe integer, bigint, or non-empty string");
|
|
399
158
|
}
|
|
400
159
|
export { aggregateCalls, aggregateDecodedCalls, decodeResults, encodeCalls, GhostcallSubcallError, };
|
|
401
160
|
//# sourceMappingURL=index.js.map
|
package/dist/sdk/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,QAAQ,IAAI,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE5D,OAAO,EAGN,cAAc,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AA2E5D,uFAAuF;AACvF,MAAM,qBAAsB,SAAQ,KAAK;IAC/B,KAAK,CAAS;IACd,IAAI,CAAgB;IACpB,MAAM,CAAwB;IAEvC,YACC,KAAa,EACb,IAAmB,EACnB,MAA6B;QAE7B,KA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zB,KAAK,CAAC,MAAM,GAAG,CAAC;QAChB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EACpB,CAAC;QACF,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QAClE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;YACxB,CAAC,CAAC,iBAAiB,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,0BAA0B,CAAC;YACtE,CAAC,CAAC,KAAK,CAAC;IACV,CAAC;IACD,MAAM,IAAI,SAAS,CAClB,2FAA2F,CAC3F,CAAC;AACH,CAAC;AAWD,OAAO,EACN,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,qBAAqB,GACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volga-sh/evm-ghostcall",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Batch EVM
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "Batch EVM contract reads without deploying a Multicall contract.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"packageManager": "npm@12.1.0",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "git+https://github.com/volga-sh/ghostcall.git"
|
|
@@ -29,14 +30,14 @@
|
|
|
29
30
|
"access": "public"
|
|
30
31
|
},
|
|
31
32
|
"scripts": {
|
|
32
|
-
"benchmark:limits": "node
|
|
33
|
+
"benchmark:limits": "node scripts/benchmark-limits.ts",
|
|
33
34
|
"build:contracts": "forge build && npm run generate:sdk:initcode",
|
|
34
35
|
"build:sdk": "npm run build:contracts && tsc --project tsconfig.build.json",
|
|
35
36
|
"check": "biome check .",
|
|
36
37
|
"check:fix": "biome check --write .",
|
|
37
|
-
"docs:build": "npm run build --prefix docs",
|
|
38
|
-
"docs:dev": "npm run dev --prefix docs",
|
|
39
|
-
"docs:preview": "npm run preview --prefix docs",
|
|
38
|
+
"docs:build": "npm run build --prefix docs --",
|
|
39
|
+
"docs:dev": "npm run dev --prefix docs --",
|
|
40
|
+
"docs:preview": "npm run preview --prefix docs --",
|
|
40
41
|
"check:sdk:initcode": "git diff --exit-code -- src/sdk/generated/initcode.ts",
|
|
41
42
|
"format": "biome format --write .",
|
|
42
43
|
"format:check": "biome format .",
|
|
@@ -44,16 +45,17 @@
|
|
|
44
45
|
"lint": "biome lint .",
|
|
45
46
|
"lint:fix": "npm run check:fix",
|
|
46
47
|
"prepack": "npm run build:sdk",
|
|
47
|
-
"test": "npm run build:contracts && node --
|
|
48
|
-
"test:watch": "node --
|
|
48
|
+
"test": "npm run build:contracts && node --test test/*.test.ts",
|
|
49
|
+
"test:watch": "node --test --watch test/*.test.ts",
|
|
49
50
|
"typecheck": "tsc --project tsconfig.json"
|
|
50
51
|
},
|
|
51
|
-
"dependencies": {
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"ox": "1.8.3"
|
|
54
|
+
},
|
|
52
55
|
"devDependencies": {
|
|
53
|
-
"@biomejs/biome": "2.
|
|
56
|
+
"@biomejs/biome": "2.5.14",
|
|
54
57
|
"@safe-global/mock-contract": "4.1.0",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"typescript": "5.9.2"
|
|
58
|
+
"@types/node": "26.6.3",
|
|
59
|
+
"typescript": "7.0.2"
|
|
58
60
|
}
|
|
59
61
|
}
|