@@ -18,13 +18,13 @@ import {
1818 type AbiParameter ,
1919 type AbiParameterToPrimitiveType ,
2020 BaseError ,
21+ boolToHex ,
22+ concat ,
2123 type Hex ,
2224 IntegerOutOfRangeError ,
2325 InvalidAbiEncodingTypeError ,
2426 InvalidAddressError ,
2527 InvalidArrayError ,
26- boolToHex ,
27- concat ,
2828 isAddress ,
2929 numberToHex ,
3030 padHex ,
@@ -42,7 +42,10 @@ import {
4242} from './types' ;
4343import { isRuntimeComposableValue } from './utils' ;
4444
45- type PreparedParam = { dynamic : boolean ; data : ( Hex | RuntimeValue ) [ ] } ;
45+ interface PreparedParam {
46+ dynamic : boolean ;
47+ data : ( Hex | RuntimeValue ) [ ] ;
48+ }
4649type TupleAbiParameter = AbiParameter & { components : readonly AbiParameter [ ] } ;
4750type Tuple = AbiParameterToPrimitiveType < TupleAbiParameter > ;
4851
@@ -120,9 +123,9 @@ const encodeBytes = <const param extends AbiParameter>(
120123 }
121124
122125 // Check for param size which is extracted from type with actual byte size
123- if ( bytesSize !== Number . parseInt ( paramSize ) )
126+ if ( bytesSize !== Number . parseInt ( paramSize , 10 ) )
124127 throw new AbiEncodingBytesSizeMismatchError ( {
125- expectedSize : Number . parseInt ( paramSize ) ,
128+ expectedSize : Number . parseInt ( paramSize , 10 ) ,
126129 value : value ,
127130 } ) ;
128131
@@ -203,7 +206,7 @@ const encodeArray = <const param extends AbiParameter>(
203206 // If there is a length specified, the static array length is validated with its elements count
204207 if ( ! dynamic && value . length !== length )
205208 throw new AbiEncodingArrayLengthMismatchError ( {
206- expectedLength : length ! ,
209+ expectedLength : length as number ,
207210 givenLength : value . length ,
208211 type : `${ param . type } [${ length } ]` ,
209212 } ) ;
@@ -264,11 +267,11 @@ const encodeTuple = <const param extends AbiParameter & { components: readonly A
264267
265268 for ( let i = 0 ; i < param . components . length ; i ++ ) {
266269 const param_ = param . components [ i ] ;
267- const index = Array . isArray ( value ) ? i : param_ . name ;
270+ const index = Array . isArray ( value ) ? i : ( param_ . name ?? i ) ;
268271 // The internal elements will be encoded based on its data type. It will handle the nested data type encoding as well
269272 const preparedParam = prepareParam ( {
270273 param : param_ ,
271- value : ( value as AnyData ) [ index ! ] as readonly unknown [ ] ,
274+ value : ( value as AnyData ) [ index ] as readonly unknown [ ] ,
272275 } ) ;
273276 preparedParams . push ( preparedParam ) ;
274277 // If any of the internal element of a tuple is dynamic ? The entire tuple is treated as dynamic tuple
@@ -382,7 +385,7 @@ const prepareParams = <const params extends readonly AbiParameter[]>({
382385 values,
383386} : {
384387 params : params ;
385- values : Array < AnyData > ;
388+ values : AnyData [ ] ;
386389} ) : PreparedParam [ ] => {
387390 const preparedParams : PreparedParam [ ] = [ ] ;
388391 for ( let i = 0 ; i < params . length ; i ++ ) {
@@ -465,7 +468,7 @@ const prepareParam = <const param extends AbiParameter>({
465468 } ) ;
466469} ;
467470
468- export const encodeRuntimeFunctionData = ( inputs : AbiParameter [ ] , args : Array < AnyData > ) => {
471+ export const encodeRuntimeFunctionData = ( inputs : AbiParameter [ ] , args : AnyData [ ] ) => {
469472 // If there is no arguments to the function, no need for encoding at all.
470473 if ( ! inputs || inputs . length === 0 ) {
471474 return [ '0x' as Hex ] ;
@@ -482,7 +485,7 @@ export const encodeRuntimeFunctionData = (inputs: AbiParameter[], args: Array<An
482485 // Prepare the encoding
483486 const preparedParams = prepareParams ( {
484487 params : inputs ,
485- values : args as Array < AnyData > ,
488+ values : args as AnyData [ ] ,
486489 } ) ;
487490
488491 // Encoding the prepared data types based on static and dynamic natrue
0 commit comments