@@ -17,67 +17,78 @@ function parseStarknetResult(rawResult: string[], functionAbi: any): any {
17
17
return rawResult ;
18
18
}
19
19
20
- const output = functionAbi . outputs [ 0 ] ;
21
- const rawValue = rawResult [ 0 ] ;
20
+ // Parse each output according to its type
21
+ const outputs = functionAbi . outputs ;
22
+ const results : any [ ] = [ ] ;
23
+ let rawIndex = 0 ; // Track position in rawResult array
22
24
23
25
try {
24
- switch ( output . type ) {
25
- case 'core::felt252' :
26
- // Try to decode as shortString (for name, symbol)
27
- try {
28
- return shortString . decodeShortString ( rawValue ) ;
29
- } catch {
30
- // If shortString decode fails, return as hex
31
- return rawValue ;
32
- }
33
-
34
- // Unsigned integers
35
- case 'core::integer::u8' :
36
- case 'core::integer::u16' :
37
- case 'core::integer::u32' :
38
- case 'core::integer::u64' :
39
- return parseInt ( rawValue , 16 ) ;
40
-
41
- case 'core::integer::u128' :
42
- case 'core::integer::usize' :
43
- return BigInt ( rawValue ) . toString ( ) ;
44
-
45
- case 'core::integer::u256' :
46
- return uint256 . uint256ToBN ( {
47
- low : rawValue ,
48
- high : rawResult [ 1 ] || '0x0'
49
- } ) ;
50
-
51
- // Signed integers
52
- case 'core::integer::i8' :
53
- case 'core::integer::i16' :
54
- case 'core::integer::i32' :
55
- case 'core::integer::i64' :
56
- return parseInt ( rawValue , 16 ) ;
57
-
58
- case 'core::integer::i128' :
59
- return BigInt ( rawValue ) . toString ( ) ;
60
-
61
- // Boolean type
62
- case 'core::bool' :
63
- return rawValue === '0x1' || rawValue === '0x01' ;
64
-
65
- // Address types
66
- case 'core::starknet::contract_address::ContractAddress' :
67
- case 'core::starknet::class_hash::ClassHash' :
68
- case 'core::starknet::storage_access::StorageAddress' :
69
- return rawValue ;
70
-
71
- // Byte array
72
- case 'core::bytes_31::bytes31' :
73
- return rawValue ;
74
-
75
- default :
76
- // Return raw value for unknown types
77
- return rawValue ;
26
+ for ( let outputIndex = 0 ; outputIndex < outputs . length ; outputIndex ++ ) {
27
+ const output = outputs [ outputIndex ] ;
28
+ const rawValue = rawResult [ rawIndex ] ;
29
+
30
+ switch ( output . type ) {
31
+ case 'core::felt252' :
32
+ try {
33
+ results . push ( shortString . decodeShortString ( rawValue ) ) ;
34
+ } catch {
35
+ results . push ( rawValue ) ;
36
+ }
37
+ rawIndex ++ ;
38
+ break ;
39
+ case 'core::integer::u8' :
40
+ case 'core::integer::u16' :
41
+ case 'core::integer::u32' :
42
+ case 'core::integer::u64' :
43
+ results . push ( parseInt ( rawValue , 16 ) ) ;
44
+ rawIndex ++ ;
45
+ break ;
46
+ case 'core::integer::u128' :
47
+ case 'core::integer::usize' :
48
+ results . push ( BigInt ( rawValue ) . toString ( ) ) ;
49
+ rawIndex ++ ;
50
+ break ;
51
+ case 'core::integer::u256' :
52
+ results . push (
53
+ uint256 . uint256ToBN ( {
54
+ low : rawValue ,
55
+ high : rawResult [ rawIndex + 1 ] || '0x0'
56
+ } )
57
+ ) ;
58
+ rawIndex += 2 ; // u256 uses two slots
59
+ break ;
60
+ case 'core::integer::i8' :
61
+ case 'core::integer::i16' :
62
+ case 'core::integer::i32' :
63
+ case 'core::integer::i64' :
64
+ results . push ( parseInt ( rawValue , 16 ) ) ;
65
+ rawIndex ++ ;
66
+ break ;
67
+ case 'core::integer::i128' :
68
+ results . push ( BigInt ( rawValue ) . toString ( ) ) ;
69
+ rawIndex ++ ;
70
+ break ;
71
+ case 'core::bool' :
72
+ results . push ( rawValue === '0x1' || rawValue === '0x01' ) ;
73
+ rawIndex ++ ;
74
+ break ;
75
+ case 'core::starknet::contract_address::ContractAddress' :
76
+ case 'core::starknet::class_hash::ClassHash' :
77
+ case 'core::starknet::storage_access::StorageAddress' :
78
+ results . push ( rawValue ) ;
79
+ rawIndex ++ ;
80
+ break ;
81
+ case 'core::bytes_31::bytes31' :
82
+ results . push ( rawValue ) ;
83
+ rawIndex ++ ;
84
+ break ;
85
+ default :
86
+ results . push ( rawValue ) ;
87
+ rawIndex ++ ;
88
+ }
78
89
}
90
+ return results ;
79
91
} catch {
80
- // Fallback to raw result if parsing fails
81
92
return rawResult ;
82
93
}
83
94
}
@@ -149,6 +160,7 @@ export default async function multicall(
149
160
const [ , functionName ] = calls [ index ] ;
150
161
const functionAbi = abi . find ( ( item ) => item . name === functionName ) ;
151
162
152
- return [ parseStarknetResult ( result , functionAbi ) ] ;
163
+ const parsedResult = parseStarknetResult ( result , functionAbi ) ;
164
+ return parsedResult ;
153
165
} ) ;
154
166
}
0 commit comments