Skip to content

Commit 16b0819

Browse files
authored
fix: getAbiItem for tuple with additional tuples (#4194)
fix: tuple with additional tuples
1 parent e168a31 commit 16b0819

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

.changeset/few-bugs-unite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"viem": patch
3+
---
4+
5+
Fixed `getAbiItem` for overloaded tuples with additional child tuple components beyond the number of args

src/utils/abi/getAbiItem.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,46 @@ test('overloads: tuple', () => {
449449
stateMutability: 'nonpayable',
450450
type: 'function',
451451
},
452+
{
453+
inputs: [
454+
{ name: 'foo', type: 'uint256' },
455+
{
456+
name: 'bar',
457+
type: 'tuple',
458+
components: [
459+
{ name: 'a', type: 'string' },
460+
{
461+
name: 'b',
462+
type: 'tuple',
463+
components: [
464+
{ name: 'merp', type: 'string' },
465+
{ name: 'meep', type: 'string' },
466+
],
467+
},
468+
{
469+
name: 'c',
470+
type: 'tuple',
471+
components: [
472+
{ name: 'merp', type: 'string' },
473+
{ name: 'meep', type: 'string' },
474+
],
475+
},
476+
{
477+
name: 'd',
478+
type: 'tuple',
479+
components: [
480+
{ name: 'merp', type: 'string' },
481+
{ name: 'meep', type: 'string' },
482+
],
483+
},
484+
],
485+
},
486+
],
487+
name: 'foo',
488+
outputs: [],
489+
stateMutability: 'nonpayable',
490+
type: 'function',
491+
},
452492
],
453493
name: 'foo',
454494
args: [

src/utils/abi/getAbiItem.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ export function isArgOfType(arg: unknown, abiParameter: AbiParameter): boolean {
171171
if (abiParameterType === 'tuple' && 'components' in abiParameter)
172172
return Object.values(abiParameter.components).every(
173173
(component, index) => {
174-
return isArgOfType(
175-
Object.values(arg as unknown[] | Record<string, unknown>)[index],
176-
component as AbiParameter,
174+
return (
175+
argType === 'object' &&
176+
isArgOfType(
177+
Object.values(arg as unknown[] | Record<string, unknown>)[
178+
index
179+
],
180+
component as AbiParameter,
181+
)
177182
)
178183
},
179184
)

0 commit comments

Comments
 (0)