Skip to content

Commit d186346

Browse files
committed
chore: perf tweaks
1 parent 0e9db23 commit d186346

8 files changed

Lines changed: 248 additions & 32 deletions

File tree

.github/workflows/verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
timeout-minutes: 5
5151
strategy:
5252
matrix:
53-
version: ['5.0.4', '5.1.6', '5.2.2', '5.3.3', '5.4.5', '5.5.4', '5.6.3', '5.7.3', '5.8.3', '5.9.3', 'latest']
53+
version: ['5.0.4', '5.2.2', '5.3.3', '5.4.5', '5.5.4', '5.6.3', '5.7.3', '5.8.3', '5.9.3', 'latest']
5454

5555
steps:
5656
- name: Clone repository

packages/abitype/src/abi.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export type TypedData = Pretty<
248248

249249
////////////////////////////////////////////////////////////////////////////////////////////////////
250250

251+
// update lookup with `pnpm node scripts/genAbiParameterNameLookup.ts`
251252
// biome-ignore format: no formatting
252253
export interface AbiParameterTupleNameLookup<type> extends Record<string, [type]> {
253254
_data: [_data: type]
@@ -262,62 +263,88 @@ export interface AbiParameterTupleNameLookup<type> extends Record<string, [type]
262263
amount: [amount: type]
263264
approved: [approved: type]
264265
approver: [approver: type]
266+
ask: [ask: type]
267+
asset: [asset: type]
265268
assets: [assets: type]
266269
authority: [authority: type]
267270
available: [available: type]
268271
b: [b: type]
269272
balance: [balance: type]
273+
bid: [bid: type]
274+
buffer: [buffer: type]
270275
c: [c: type]
276+
call: [call: type]
271277
callData: [callData: type]
272278
caller: [caller: type]
273279
calls: [calls: type]
280+
clone: [clone: type]
274281
coinType: [coinType: type]
275282
count: [count: type]
276283
currency: [currency: type]
277284
d: [d: type]
278285
data: [data: type]
279286
deadline: [deadline: type]
287+
decimals: [decimals: type]
288+
dest: [dest: type]
289+
divisor: [divisor: type]
280290
dns: [dns: type]
281291
dst: [dst: type]
282292
e: [e: type]
293+
endTime: [endTime: type]
283294
ens: [ens: type]
284295
errorData: [errorData: type]
285296
f: [f: type]
286297
failures: [failures: type]
287298
from: [from: type]
288299
funder: [funder: type]
289300
g: [g: type]
301+
gateway: [gateway: type]
290302
gateways: [gateways: type]
291303
guy: [guy: type]
292304
h: [h: type]
293305
hash: [hash: type]
306+
hashes: [hashes: type]
294307
i: [i: type]
295308
id: [id: type]
296309
ids: [ids: type]
297310
idsLength: [idsLength: type]
311+
implementation: [implementation: type]
312+
index: [index: type]
298313
interfaceId: [interfaceId: type]
299314
j: [j: type]
300315
k: [k: type]
301316
key: [key: type]
302317
l: [l: type]
303318
label: [label: type]
319+
length: [length: type]
320+
limit: [limit: type]
304321
m: [m: type]
322+
market: [market: type]
305323
memo: [memo: type]
306324
message: [message: type]
307325
n: [n: type]
308326
name: [name: type]
309327
needed: [needed: type]
328+
new: [new: type]
329+
next: [next: type]
330+
nextOwner: [nextOwner: type]
310331
node: [node: type]
311332
nonce: [nonce: type]
312333
nonceKey: [nonceKey: type]
334+
numerator: [numerator: type]
313335
o: [o: type]
336+
offerer: [offerer: type]
337+
old: [old: type]
314338
operator: [operator: type]
315339
order: [order: type]
316340
orders: [orders: type]
317341
owner: [owner: type]
318342
p: [p: type]
319343
policyId: [policyId: type]
320344
policyType: [policyType: type]
345+
previous: [previous: type]
346+
previousOwner: [previousOwner: type]
347+
price: [price: type]
321348
primary: [primary: type]
322349
proposer: [proposer: type]
323350
q: [q: type]
@@ -342,7 +369,9 @@ export interface AbiParameterTupleNameLookup<type> extends Record<string, [type]
342369
shares: [shares: type]
343370
signature: [signature: type]
344371
signer: [signer: type]
372+
source: [source: type]
345373
src: [src: type]
374+
startTime: [startTime: type]
346375
status: [status: type]
347376
success: [success: type]
348377
symbol: [symbol: type]
@@ -363,7 +392,9 @@ export interface AbiParameterTupleNameLookup<type> extends Record<string, [type]
363392
version: [version: type]
364393
w: [w: type]
365394
wad: [wad: type]
395+
weth: [weth: type]
366396
x: [x: type]
367397
y: [y: type]
368398
z: [z: type]
399+
zone: [zone: type]
369400
}

packages/abitype/src/utils.bench-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ type transferFrom = ExtractAbiFunction<
274274
>['inputs']
275275
test('basic without named tuple', () => {
276276
const res = {} as AbiParametersToPrimitiveTypes<transferFrom, 'inputs', false>
277-
attest.instantiations([917, 'instantiations'])
277+
attest.instantiations([906, 'instantiations'])
278278
attest<
279279
readonly [sender: `0x${string}`, recipient: `0x${string}`, amount: bigint]
280280
>(res)
281281
})
282282
test('basic with named tuple', () => {
283283
const res = {} as AbiParametersToPrimitiveTypes<transferFrom, 'inputs', true>
284-
attest.instantiations([1172, 'instantiations'])
284+
attest.instantiations([1131, 'instantiations'])
285285
attest<
286286
readonly [sender: `0x${string}`, recipient: `0x${string}`, amount: bigint]
287287
>(res)
@@ -311,9 +311,9 @@ type parameters = readonly [
311311
]
312312
test('without named tuples', () => {
313313
;({}) as AbiParametersToPrimitiveTypes<parameters, 'inputs', false>
314-
attest.instantiations([1286, 'instantiations'])
314+
attest.instantiations([1276, 'instantiations'])
315315
})
316316
test('with named tuples', () => {
317317
;({}) as AbiParametersToPrimitiveTypes<parameters, 'inputs', true>
318-
attest.instantiations([3800, 'instantiations'])
318+
attest.instantiations([1998, 'instantiations'])
319319
})

packages/abitype/src/utils.test-d.ts

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assertType, describe, expectTypeOf, test } from 'vitest'
22

3-
import type { Abi } from './abi.js'
3+
import type { Abi, AbiParameterKind } from './abi.js'
44
import type {
55
customSolidityErrorsAbi,
66
ensRegistryWithFallbackAbi,
@@ -424,36 +424,63 @@ describe('AbiParameterToPrimitiveType', () => {
424424

425425
describe('AbiParametersToPrimitiveTypes', () => {
426426
test('no parameters', () => {
427-
type Result = AbiParametersToPrimitiveTypes<[]>
428-
assertType<Result>([])
427+
type r1 = AbiParametersToPrimitiveTypes<[]>
428+
assertType<r1>([])
429+
type r2 = AbiParametersToPrimitiveTypes<[], AbiParameterKind, true>
430+
assertType<r2>([])
429431
})
430432

431433
test('single parameter', () => {
432-
type Result = AbiParametersToPrimitiveTypes<
434+
type r1 = AbiParametersToPrimitiveTypes<
433435
[
434436
{
435437
name: 'tokenId'
436438
type: 'uint8[2]'
437439
},
438440
]
439441
>
440-
assertType<Result>([[1, 1]])
442+
assertType<r1>([[1, 1]])
441443
// ^?
444+
type r2 = AbiParametersToPrimitiveTypes<
445+
[
446+
{
447+
name: 'tokenId'
448+
type: 'uint8[2]'
449+
},
450+
],
451+
AbiParameterKind,
452+
true
453+
>
454+
expectTypeOf<r2>().toEqualTypeOf<
455+
readonly [tokenId: readonly [number, number]]
456+
>()
442457
})
443458

444459
test('multiple parameters', () => {
445-
type Result = AbiParametersToPrimitiveTypes<
460+
type r1 = AbiParametersToPrimitiveTypes<
446461
[
447462
{ name: 'to'; type: 'address' },
448463
{ name: 'tokenId'; type: 'uint256' },
449464
{ name: 'trait'; type: 'string[]' },
450465
]
451466
>
452-
assertType<Result>([zeroAddress, 1n, ['foo']])
467+
assertType<r1>([zeroAddress, 1n, ['foo']])
468+
type r2 = AbiParametersToPrimitiveTypes<
469+
[
470+
{ name: 'to'; type: 'address' },
471+
{ name: 'tokenId'; type: 'uint256' },
472+
{ name: 'trait'; type: 'string[]' },
473+
],
474+
AbiParameterKind,
475+
true
476+
>
477+
expectTypeOf<r2>().toEqualTypeOf<
478+
readonly [to: `0x${string}`, tokenId: bigint, readonly string[]]
479+
>()
453480
})
454481

455482
test('deeply nested parameters', () => {
456-
type Result = AbiParametersToPrimitiveTypes<
483+
type r1 = AbiParametersToPrimitiveTypes<
457484
[
458485
{
459486
name: 's'
@@ -490,7 +517,55 @@ describe('AbiParametersToPrimitiveTypes', () => {
490517
},
491518
]
492519
>
493-
assertType<Result>([
520+
assertType<r1>([
521+
{ a: 1, b: [2], c: [{ x: 1, y: 1 }] },
522+
{ x: 1, y: 1 },
523+
1,
524+
[
525+
{ x: 1n, y: 1n },
526+
{ x: 1n, y: 1n },
527+
],
528+
])
529+
type r2 = AbiParametersToPrimitiveTypes<
530+
[
531+
{
532+
name: 's'
533+
type: 'tuple'
534+
components: [
535+
{ name: 'a'; type: 'uint8' },
536+
{ name: 'b'; type: 'uint8[]' },
537+
{
538+
name: 'c'
539+
type: 'tuple[]'
540+
components: [
541+
{ name: 'x'; type: 'uint8' },
542+
{ name: 'y'; type: 'uint8' },
543+
]
544+
},
545+
]
546+
},
547+
{
548+
name: 't'
549+
type: 'tuple'
550+
components: [
551+
{ name: 'x'; type: 'uint8' },
552+
{ name: 'y'; type: 'uint8' },
553+
]
554+
},
555+
{ name: 'a'; type: 'uint8' },
556+
{
557+
name: 't'
558+
type: 'tuple[2]'
559+
components: [
560+
{ name: 'x'; type: 'uint256' },
561+
{ name: 'y'; type: 'uint256' },
562+
]
563+
},
564+
],
565+
AbiParameterKind,
566+
true
567+
>
568+
assertType<r2>([
494569
{ a: 1, b: [2], c: [{ x: 1, y: 1 }] },
495570
{ x: 1, y: 1 },
496571
1,
@@ -514,14 +589,20 @@ describe('AbiParametersToPrimitiveTypes', () => {
514589
assertType<AbiParametersToPrimitiveTypes<typeof parameters, 'outputs'>>([
515590
'0xfoo',
516591
])
517-
assertType<AbiParametersToPrimitiveTypes<typeof parameters, 'outputs'>>([
518-
'0xfoo',
519-
])
592+
assertType<
593+
AbiParametersToPrimitiveTypes<typeof parameters, 'inputs', true>
594+
>(['0xfoo'])
595+
assertType<
596+
AbiParametersToPrimitiveTypes<typeof parameters, 'outputs', true>
597+
>(['0xfoo'])
520598
})
521599

522600
test('named parameters', () => {
523601
type Result = AbiParametersToPrimitiveTypes<
524-
ExtractAbiFunction<typeof erc20Abi, 'transferFrom'>['inputs']
602+
// ^?
603+
ExtractAbiFunction<typeof erc20Abi, 'transferFrom'>['inputs'],
604+
'inputs',
605+
true
525606
>
526607
expectTypeOf<Result>().toEqualTypeOf<
527608
readonly [sender: `0x${string}`, recipient: `0x${string}`, amount: bigint]

0 commit comments

Comments
 (0)