Skip to content

Commit 3446180

Browse files
khaidarkairbektmmautofix-ci[bot]
authored
fix: address payable parsing (#275)
* add address payable solidity type parsing and tests * test: add `payable address` case * address payable type parsing fixed * nits * nits * ci: apply automated fixes * chore: tweaks * chore: up --------- Co-authored-by: Tom Meagher <tom@meagher.co> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 445bd39 commit 3446180

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"check": "biome check --write",
1212
"check:repo": "sherif",
1313
"check:types": "pnpm run --r --parallel check:types && tsc --noEmit",
14-
"check:types:propertyTypes": "pnpm run --r --parallel typecheck --exactOptionalPropertyTypes false && tsc --noEmit --exactOptionalPropertyTypes false",
14+
"check:types:propertyTypes": "pnpm run --r --parallel check:types --exactOptionalPropertyTypes false && tsc --noEmit --exactOptionalPropertyTypes false",
1515
"check:unused": "pnpm clean && knip",
1616
"clean": "pnpm run --r --parallel clean && rm -rf packages/**/*.json.tmp",
1717
"deps": "pnpx taze -r",

packages/abitype/src/human-readable/runtime/utils.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ test.each([
5656
stateMutability: 'view',
5757
},
5858
},
59+
{
60+
signature: 'function foo(address payable to) external',
61+
expected: {
62+
...baseFunctionExpected,
63+
inputs: [{ type: 'address', name: 'to' }],
64+
stateMutability: 'nonpayable',
65+
},
66+
},
5967
{
6068
signature: 'function foo(string) public view returns (string)',
6169
expected: {

packages/abitype/src/human-readable/runtime/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export function parseFallbackSignature(signature: string) {
182182
}
183183

184184
const abiParameterWithoutTupleRegex =
185-
/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/
185+
/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*(?:\spayable)?)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/
186186
const abiParameterWithTupleRegex =
187187
/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/
188188
const dynamicIntegerRegex = /^u?int$/
@@ -238,6 +238,8 @@ export function parseAbiParameter(param: string, options?: ParseOptions) {
238238
components = { components: structs[match.type] }
239239
} else if (dynamicIntegerRegex.test(match.type)) {
240240
type = `${match.type}256`
241+
} else if (match.type === 'address payable') {
242+
type = 'address'
241243
} else {
242244
type = match.type
243245
if (!(options?.type === 'struct') && !isSolidityType(type))

packages/abitype/src/human-readable/types/signatures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ export type Signatures<signatures extends readonly string[]> = {
113113
[key in keyof signatures]: Signature<signatures[key], key>
114114
}
115115

116-
export type Modifier = 'calldata' | 'indexed' | 'memory' | 'storage'
116+
export type Modifier = 'calldata' | 'indexed' | 'memory' | 'payable' | 'storage'
117117
export type FunctionModifier = Extract<
118118
Modifier,
119-
'calldata' | 'memory' | 'storage'
119+
'calldata' | 'memory' | 'payable' | 'storage'
120120
>
121121
export type EventModifier = Extract<Modifier, 'indexed'>
122122

packages/abitype/src/human-readable/types/utils.test-d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ test('ParseSignature', () => {
209209
inputs: [{ type: 'string' }],
210210
outputs: [],
211211
})
212+
assertType<ParseSignature<'function foo(address payable to) external'>>({
213+
name: 'foo',
214+
type: 'function',
215+
stateMutability: 'nonpayable',
216+
inputs: [{ type: 'address', name: 'to' }],
217+
outputs: [],
218+
})
212219

213220
assertType<ParseSignature<'function foo(string indexed)'>>({
214221
name: 'foo',

0 commit comments

Comments
 (0)