Skip to content

Commit ae36887

Browse files
committed
fix lint errors
1 parent 6ff71ed commit ae36887

10 files changed

Lines changed: 49 additions & 46 deletions

File tree

src/core/contract/contract.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { describe, expect, it } from 'vitest';
21
import { getAddress } from 'viem';
3-
import { contract } from './contract';
2+
import { describe, expect, it } from 'vitest';
43
import { publicClient } from '../../test/utils';
4+
import { contract } from './contract';
55

66
// Uniswap V3 Factory on Base Sepolia
77
const UNISWAP_V3_FACTORY = getAddress('0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24');

src/core/encoding/encoding.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ import {
33
encodeFunctionData,
44
encodePacked,
55
erc20Abi,
6+
type Hex,
67
isAddress,
78
isHex,
89
zeroAddress,
9-
type Hex,
1010
} from 'viem';
1111
import type { AnyData } from '../types';
1212
import {
13-
ConstraintType,
14-
InputParamFetcherType,
15-
OutputParamFetcherType,
1613
type Constraint,
1714
type ConstraintField,
15+
ConstraintType,
1816
type InputParam,
17+
InputParamFetcherType,
1918
type OutputParam,
19+
type OutputParamFetcherType,
2020
type RuntimeBalanceOfParams,
21-
type runtimeERC20AllowanceOfParams,
2221
type RuntimeNativeBalanceOfParams,
2322
type RuntimeParamViaCustomStaticCallParams,
2423
type RuntimeValue,
24+
type runtimeERC20AllowanceOfParams,
2525
} from './types';
2626
import { toBytes32 } from './utils';
2727

src/core/encoding/runtimeAbiEncoding.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
4343
import { isRuntimeComposableValue } from './utils';
4444

45-
type PreparedParam = { dynamic: boolean; data: (Hex | RuntimeValue)[] };
45+
interface PreparedParam {
46+
dynamic: boolean;
47+
data: (Hex | RuntimeValue)[];
48+
}
4649
type TupleAbiParameter = AbiParameter & { components: readonly AbiParameter[] };
4750
type 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

src/core/encoding/types.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import type { AnyData } from '../types';
88
* paramType: The type of the param. This field is optional and it is introduced in the composability version 1.1.0
99
* If earlier versions are used, this field may not not present.
1010
*/
11-
export type InputParam = {
11+
export interface InputParam {
1212
paramType?: InputParamType;
1313
fetcherType: InputParamFetcherType;
1414
paramData: string;
1515
constraints: Constraint[];
16-
};
16+
}
1717

18-
export type OutputParam = {
18+
export interface OutputParam {
1919
fetcherType: OutputParamFetcherType;
2020
paramData: string;
21-
};
21+
}
2222

2323
/**
2424
* paramType: The type of the param.
@@ -66,10 +66,10 @@ export type OutputParamFetcherType =
6666
export type ConstraintType = (typeof ConstraintType)[keyof typeof ConstraintType];
6767
export type InputParamType = (typeof InputParamType)[keyof typeof InputParamType];
6868

69-
export type Constraint = {
69+
export interface Constraint {
7070
constraintType: ConstraintType;
7171
referenceData: string;
72-
};
72+
}
7373

7474
/**
7575
* Base composable call type
@@ -81,52 +81,52 @@ export type Constraint = {
8181
* Since Composability version 1.1.0, to and value are not required
8282
* as they are replaced by the input params with according types (TARGET, VALUE)
8383
*/
84-
export type BaseComposableCall = {
84+
export interface BaseComposableCall {
8585
to?: Address;
8686
value?: bigint;
8787
functionSig: string;
8888
inputParams: InputParam[];
8989
outputParams: OutputParam[];
90-
};
90+
}
9191

92-
export type ConstraintField = {
92+
export interface ConstraintField {
9393
type: ConstraintType;
9494
value: AnyData; // type any is being implicitly used. The appropriate value validation happens in the runtime function
95-
};
95+
}
9696

97-
export type RuntimeParamViaCustomStaticCallParams = {
97+
export interface RuntimeParamViaCustomStaticCallParams {
9898
targetContractAddress: Address;
9999
functionAbi: Abi;
100-
args: Array<AnyData>;
100+
args: AnyData[];
101101
functionName?: string;
102102
constraints?: ConstraintField[];
103-
};
103+
}
104104

105-
export type runtimeERC20AllowanceOfParams = {
105+
export interface runtimeERC20AllowanceOfParams {
106106
owner: Address;
107107
spender: Address;
108108
tokenAddress: Address;
109109
constraints?: ConstraintField[];
110-
};
110+
}
111111

112-
export type RuntimeBalanceOfParams = {
112+
export interface RuntimeBalanceOfParams {
113113
targetAddress: Address;
114114
tokenAddress: Address;
115115
constraints?: ConstraintField[];
116-
};
116+
}
117117

118118
export type RuntimeNativeBalanceOfParams = Omit<RuntimeBalanceOfParams, 'tokenAddress'>;
119119

120-
export type FunctionContext = {
120+
export interface FunctionContext {
121121
inputs: readonly AbiParameter[];
122122
outputs: readonly AbiParameter[];
123123
name: string;
124124
functionType: 'read' | 'write';
125125
functionSig: string;
126-
};
126+
}
127127

128-
export type RuntimeValue = {
128+
export interface RuntimeValue {
129129
isRuntime: boolean;
130130
inputParams: InputParam[];
131131
outputParams: OutputParam[];
132-
};
132+
}

src/core/encoding/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isAddress, isHex, padHex, toHex, type Address, type Hex } from 'viem';
1+
import { type Address, type Hex, isAddress, isHex, padHex, toHex } from 'viem';
22
import type { AnyData } from '../types';
33

44
export const toBytes32 = (value: bigint | boolean | Address | Hex | number): Hex => {

src/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './token';
21
export * from './contract';
32
export * from './encoding';
3+
export * from './token';
44
export * from './types';

src/core/token/token.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { describe, expect, it } from 'vitest';
21
import { getAddress } from 'viem';
3-
import { ERC20Token, NativeToken } from './token';
2+
import { describe, expect, it } from 'vitest';
43
import { publicClient } from '../../test/utils';
4+
import { ERC20Token, NativeToken } from './token';
55

66
// Well-known Base Sepolia token addresses
77
const USDC_ADDRESS = getAddress('0x036CbD53842c5426634e7929541eC2318f3dCF7e');

src/core/token/token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { erc20Abi } from 'viem';
21
import type { Address, Chain, PublicClient, Transport } from 'viem';
2+
import { erc20Abi } from 'viem';
33
import type { ERC20TokenInstance, NativeTokenInstance } from './types';
44

55
export function ERC20Token<

src/core/token/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { erc20Abi } from 'viem';
21
import type {
32
Address,
43
ContractFunctionArgs,
54
ContractFunctionName,
65
ContractFunctionReturnType,
6+
erc20Abi,
77
} from 'viem';
88

99
export type ERC20Abi = typeof erc20Abi;

src/core/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
1+
// biome-ignore lint/suspicious/noExplicitAny: intentional escape hatch for ABI-encoded runtime values where types are unknown at compile time
22
export type AnyData = any;

0 commit comments

Comments
 (0)