diff --git a/biome.json b/biome.json index cdf4b896..1e9b8b46 100644 --- a/biome.json +++ b/biome.json @@ -22,7 +22,7 @@ "enabled": true, "formatWithErrors": false, "indentStyle": "space", - "indentWidth": 2, + "indentSize": 2, "lineWidth": 80 }, "linter": { @@ -36,23 +36,20 @@ "noUnusedVariables": "error" }, "complexity": { - "noForEach": "off", - "noBannedTypes": "off" + "noForEach": "off" }, "performance": { "noDelete": "off" }, "style": { "noNonNullAssertion": "off", - "useShorthandArrayType": "error", - "noUselessElse": "off" + "useShorthandArrayType": "error" }, "suspicious": { "noArrayIndexKey": "off", "noAssignInExpressions": "off", "noExplicitAny": "off", - "noRedeclare": "off", - "noConfusingVoidType": "off" + "noRedeclare": "off" } } }, diff --git a/src/accounts/utils/signTransaction.ts b/src/accounts/utils/signTransaction.ts index be12fde2..dd73e824 100644 --- a/src/accounts/utils/signTransaction.ts +++ b/src/accounts/utils/signTransaction.ts @@ -17,8 +17,7 @@ import { import { type SignErrorType, sign } from './sign.js' export type SignTransactionParameters< - TTransactionSerializable extends - TransactionSerializable = TransactionSerializable, + TTransactionSerializable extends TransactionSerializable = TransactionSerializable, > = { privateKey: Hex transaction: TTransactionSerializable @@ -28,8 +27,7 @@ export type SignTransactionParameters< } export type SignTransactionReturnType< - TTransactionSerializable extends - TransactionSerializable = TransactionSerializable, + TTransactionSerializable extends TransactionSerializable = TransactionSerializable, > = TransactionSerialized> export type SignTransactionErrorType = diff --git a/src/actions/public/createContractEventFilter.ts b/src/actions/public/createContractEventFilter.ts index 6bb96792..c0522514 100644 --- a/src/actions/public/createContractEventFilter.ts +++ b/src/actions/public/createContractEventFilter.ts @@ -48,17 +48,15 @@ export type CreateContractEventFilterParameters< args?: never } : MaybeExtractEventArgsFromAbi< - TAbi, - TEventName - > extends infer TEventFilterArgs - ? { - args?: - | TEventFilterArgs - | (TArgs extends TEventFilterArgs ? TArgs : never) - } - : { - args?: never - }) + TAbi, + TEventName + > extends infer TEventFilterArgs + ? { + args?: TEventFilterArgs | (TArgs extends TEventFilterArgs ? TArgs : never) + } + : { + args?: never + }) export type CreateContractEventFilterReturnType< TAbi extends Abi | readonly unknown[] = Abi, diff --git a/src/chains/suave/types.ts b/src/chains/suave/types.ts index cb866cfe..5a45e8c9 100644 --- a/src/chains/suave/types.ts +++ b/src/chains/suave/types.ts @@ -29,10 +29,9 @@ const AllSuaveTypes = { } // syntactical sugar to allow inline string literals -export type SuaveTxType = - `${(typeof AllSuaveTypes)[keyof typeof AllSuaveTypes]}` +export type SuaveTxType = `${typeof AllSuaveTypes[keyof typeof AllSuaveTypes]}` export type SuaveTxRequestType = - `${(typeof SuaveTxRequestTypes)[keyof typeof SuaveTxRequestTypes]}` + `${typeof SuaveTxRequestTypes[keyof typeof SuaveTxRequestTypes]}` type ConfidentialOverrides = { kettleAddress?: Address diff --git a/src/errors/base.ts b/src/errors/base.ts index 8bef6530..d22c6d23 100644 --- a/src/errors/base.ts +++ b/src/errors/base.ts @@ -32,8 +32,8 @@ export class BaseError extends Error { args.cause instanceof BaseError ? args.cause.details : args.cause?.message - ? args.cause.message - : args.details! + ? args.cause.message + : args.details! const docsPath = args.cause instanceof BaseError ? args.cause.docsPath || args.docsPath diff --git a/src/types/contract.ts b/src/types/contract.ts index cddd66f8..ea764bea 100644 --- a/src/types/contract.ts +++ b/src/types/contract.ts @@ -58,10 +58,10 @@ export type ContractFunctionResult< > = true extends FailedToParseArgs ? unknown : TArgs extends readonly [] - ? void - : TArgs extends readonly [infer Arg] - ? Arg - : TArgs + ? void + : TArgs extends readonly [infer Arg] + ? Arg + : TArgs export type GetValue< TAbi extends Abi | readonly unknown[], @@ -75,8 +75,8 @@ export type GetValue< ? TAbiFunction['stateMutability'] extends 'payable' ? { value?: NoUndefined } : TAbiFunction['payable'] extends true - ? { value?: NoUndefined } - : { value?: never } + ? { value?: NoUndefined } + : { value?: never } : { value?: TValueType } export type MaybeAbiEventName = @@ -170,10 +170,10 @@ export type GetFunctionArgs< args?: readonly unknown[] } : TArgs extends readonly [] - ? { args?: never } - : { - /** Arguments to pass contract method */ args: TArgs - } + ? { args?: never } + : { + /** Arguments to pass contract method */ args: TArgs + } export type GetConstructorArgs< TAbi extends Abi | readonly unknown[], @@ -194,10 +194,10 @@ export type GetConstructorArgs< args?: readonly unknown[] } : TArgs extends readonly [] - ? { args?: never } - : { - /** Arguments to pass contract constructor */ args: TArgs - } + ? { args?: never } + : { + /** Arguments to pass contract constructor */ args: TArgs + } export type GetErrorArgs< TAbi extends Abi | readonly unknown[], @@ -219,10 +219,10 @@ export type GetErrorArgs< args?: readonly unknown[] } : TArgs extends readonly [] - ? { args?: never } - : { - /** Arguments to pass contract method */ args: TArgs - } + ? { args?: never } + : { + /** Arguments to pass contract method */ args: TArgs + } export type GetEventArgs< TAbi extends Abi | readonly unknown[], @@ -296,10 +296,10 @@ export type LogTopicType< > = TTopic extends Hex ? TPrimitiveType : TTopic extends Hex[] - ? TPrimitiveType[] - : TTopic extends null - ? null - : never + ? TPrimitiveType[] + : TTopic extends null + ? null + : never /** * @internal @@ -328,45 +328,46 @@ export type AbiEventParametersToPrimitiveTypes< > = TAbiParameters extends readonly [] ? readonly [] : Filter< - TAbiParameters, - Options['IndexedOnly'] extends true ? { indexed: true } : object - > extends infer Filtered extends readonly AbiParameter[] - ? _HasUnnamedAbiParameter extends true - ? // Has unnamed tuple parameters so return as array - | readonly [ - ...{ - [K in keyof Filtered]: AbiEventParameterToPrimitiveType< - Filtered[K], - Options - > - }, - ] - // Distribute over tuple to represent optional parameters - | (Options['Required'] extends true - ? never - : // Distribute over tuple to represent optional parameters - Filtered extends readonly [ - ...infer Head extends readonly AbiParameter[], - infer _, - ] - ? AbiEventParametersToPrimitiveTypes< - readonly [...{ [K in keyof Head]: Omit }], - Options - > - : never) - : // All tuple parameters are named so return as object - { - [Parameter in Filtered[number] as Parameter extends { - name: infer Name extends string - } - ? Name - : never]?: AbiEventParameterToPrimitiveType - } extends infer Mapped - ? Prettify< - MaybeRequired< - Mapped, - Options['Required'] extends boolean ? Options['Required'] : false - > - > - : never + TAbiParameters, + Options['IndexedOnly'] extends true ? { indexed: true } : object + > extends infer Filtered extends readonly AbiParameter[] + ? _HasUnnamedAbiParameter extends true + ? // Has unnamed tuple parameters so return as array + | readonly [ + ...{ + [K in keyof Filtered]: AbiEventParameterToPrimitiveType< + Filtered[K], + Options + > + }, + ] + // Distribute over tuple to represent optional parameters + | (Options['Required'] extends true + ? never + : // Distribute over tuple to represent optional parameters + Filtered extends readonly [ + ...infer Head extends readonly AbiParameter[], + infer _, + ] + ? AbiEventParametersToPrimitiveTypes< + readonly [...{ [K in keyof Head]: Omit }], + Options + > + : never) + : // All tuple parameters are named so return as object + { + [Parameter in + Filtered[number] as Parameter extends { + name: infer Name extends string + } + ? Name + : never]?: AbiEventParameterToPrimitiveType + } extends infer Mapped + ? Prettify< + MaybeRequired< + Mapped, + Options['Required'] extends boolean ? Options['Required'] : false + > + > : never + : never diff --git a/src/types/filter.ts b/src/types/filter.ts index d449b86c..7de37177 100644 --- a/src/types/filter.ts +++ b/src/types/filter.ts @@ -42,18 +42,18 @@ export type Filter< strict: TStrict } : TArgs extends MaybeExtractEventArgsFromAbi - ? { - abi: TAbi - args: TArgs - eventName: TEventName - strict: TStrict - } - : { - abi: TAbi - args?: never - eventName: TEventName - strict: TStrict - } + ? { + abi: TAbi + args: TArgs + eventName: TEventName + strict: TStrict + } + : { + abi: TAbi + args?: never + eventName: TEventName + strict: TStrict + } : { abi?: never args?: never diff --git a/src/types/log.ts b/src/types/log.ts index 17a336b6..f0b4170c 100644 --- a/src/types/log.ts +++ b/src/types/log.ts @@ -75,10 +75,10 @@ type GetTopics< > = true extends _FailedToParseArgs ? [Hex, ...Hex[]] | [] : TAbiEvent extends AbiEvent - ? Topics - : _AbiEvent extends AbiEvent - ? Topics<_AbiEvent['inputs']> - : [Hex, ...Hex[]] | [] + ? Topics + : _AbiEvent extends AbiEvent + ? Topics<_AbiEvent['inputs']> + : [Hex, ...Hex[]] | [] type GetInferredLogValues< TAbiEvent extends AbiEvent | undefined = undefined, diff --git a/src/types/multicall.ts b/src/types/multicall.ts index 8f5842f2..954f7667 100644 --- a/src/types/multicall.ts +++ b/src/types/multicall.ts @@ -23,37 +23,32 @@ export type MulticallContracts< > = Depth['length'] extends MAXIMUM_DEPTH ? (ContractFunctionConfig & TProperties)[] : TContracts extends [] - ? [] - : TContracts extends [infer Head extends MulticallContract] - ? [ - ...Result, - ContractFunctionConfig & - TProperties, - ] - : TContracts extends [ - infer Head extends MulticallContract, - ...infer Tail extends readonly MulticallContract[], - ] - ? MulticallContracts< - [...Tail], - TProperties, - [ - ...Result, - ContractFunctionConfig & - TProperties, - ], - [...Depth, 1] - > - : unknown[] extends TContracts - ? TContracts - : // If `TContracts` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type! - // use this to infer the param types in the case of Array.map() argument - TContracts extends ContractFunctionConfig< - infer TAbi, - infer TFunctionName - >[] - ? (ContractFunctionConfig & TProperties)[] - : (ContractFunctionConfig & TProperties)[] + ? [] + : TContracts extends [infer Head extends MulticallContract] + ? [ + ...Result, + ContractFunctionConfig & TProperties, + ] + : TContracts extends [ + infer Head extends MulticallContract, + ...infer Tail extends readonly MulticallContract[], + ] + ? MulticallContracts< + [...Tail], + TProperties, + [ + ...Result, + ContractFunctionConfig & TProperties, + ], + [...Depth, 1] + > + : unknown[] extends TContracts + ? TContracts + : // If `TContracts` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type! + // use this to infer the param types in the case of Array.map() argument + TContracts extends ContractFunctionConfig[] + ? (ContractFunctionConfig & TProperties)[] + : (ContractFunctionConfig & TProperties)[] export type MulticallResult< Result, @@ -80,37 +75,34 @@ export type MulticallResults< > = Depth['length'] extends MAXIMUM_DEPTH ? MulticallResult[] : TContracts extends [] - ? [] - : TContracts extends [infer Head extends MulticallContract] - ? [ - ...Result, - MulticallResult< - ContractFunctionResult, - TAllowFailure - >, - ] - : TContracts extends [ - infer Head extends MulticallContract, - ...infer Tail extends readonly MulticallContract[], - ] - ? MulticallResults< - [...Tail], - TAllowFailure, - [ - ...Result, - MulticallResult< - ContractFunctionResult, - TAllowFailure - >, - ], - [...Depth, 1] - > - : TContracts extends ContractFunctionConfig< - infer TAbi, - infer TFunctionName - >[] - ? MulticallResult< - ContractFunctionResult, - TAllowFailure - >[] - : MulticallResult[] + ? [] + : TContracts extends [infer Head extends MulticallContract] + ? [ + ...Result, + MulticallResult< + ContractFunctionResult, + TAllowFailure + >, + ] + : TContracts extends [ + infer Head extends MulticallContract, + ...infer Tail extends readonly MulticallContract[], + ] + ? MulticallResults< + [...Tail], + TAllowFailure, + [ + ...Result, + MulticallResult< + ContractFunctionResult, + TAllowFailure + >, + ], + [...Depth, 1] + > + : TContracts extends ContractFunctionConfig[] + ? MulticallResult< + ContractFunctionResult, + TAllowFailure + >[] + : MulticallResult[] diff --git a/src/types/transaction.ts b/src/types/transaction.ts index 4a562289..f5e4f66a 100644 --- a/src/types/transaction.ts +++ b/src/types/transaction.ts @@ -177,10 +177,10 @@ export type TransactionSerialized = TType extends 'eip1559' ? TransactionSerializedEIP1559 : TType extends 'eip2930' - ? TransactionSerializedEIP2930 - : TType extends 'legacy' - ? TransactionSerializedLegacy - : TransactionSerializedGeneric + ? TransactionSerializedEIP2930 + : TType extends 'legacy' + ? TransactionSerializedLegacy + : TransactionSerializedGeneric export type TransactionSerializableBase< TQuantity = bigint, diff --git a/src/types/typedData.ts b/src/types/typedData.ts index 9bad85f5..917d5e52 100644 --- a/src/types/typedData.ts +++ b/src/types/typedData.ts @@ -42,18 +42,18 @@ export type GetTypedDataMessage< > = TPrimaryType extends 'EIP712Domain' ? {} : { [key_3: string]: any } extends TMessage // Check if we were able to infer the shape of typed data - ? { - /** - * Data to sign - * - * Use a [const assertion](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) on {@link types} for type inference. - */ - message: { [key_4: string]: unknown } - } - : { - /** Data to sign */ - message: TMessage - } + ? { + /** + * Data to sign + * + * Use a [const assertion](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) on {@link types} for type inference. + */ + message: { [key_4: string]: unknown } + } + : { + /** Data to sign */ + message: TMessage + } export type GetTypedDataPrimaryType< TTypedData extends TypedData | { [key: string]: unknown } = TypedData, diff --git a/src/types/utils.ts b/src/types/utils.ts index 251e072f..fb8cb779 100644 --- a/src/types/utils.ts +++ b/src/types/utils.ts @@ -125,11 +125,12 @@ export type MaybeUndefined< * @private Helper for `Assign`. This is a workaround for tsc generating errorneous type definitions. */ export type Assign_ = { - [K in keyof T as K extends keyof U - ? U[K] extends void - ? never - : K - : K]: K extends keyof U ? U[K] : T[K] + [K in + keyof T as K extends keyof U + ? U[K] extends void + ? never + : K + : K]: K extends keyof U ? U[K] : T[K] } /** diff --git a/src/utils/abi/decodeFunctionResult.ts b/src/utils/abi/decodeFunctionResult.ts index a6f3990c..0add028f 100644 --- a/src/utils/abi/decodeFunctionResult.ts +++ b/src/utils/abi/decodeFunctionResult.ts @@ -37,8 +37,8 @@ export type DecodeFunctionResultParameters< } & (TFunctionName extends string ? { abi: TAbi } & Partial> : _FunctionName extends string - ? { abi: [TAbi[number]] } & Partial> - : never) + ? { abi: [TAbi[number]] } & Partial> + : never) export type DecodeFunctionResultReturnType< TAbi extends Abi | readonly unknown[] = Abi, diff --git a/src/utils/abi/encodeErrorResult.ts b/src/utils/abi/encodeErrorResult.ts index 66c7283a..3b2c9a0c 100644 --- a/src/utils/abi/encodeErrorResult.ts +++ b/src/utils/abi/encodeErrorResult.ts @@ -39,8 +39,8 @@ export type EncodeErrorResultParameters< } & (TErrorName extends string ? { abi: TAbi } & GetErrorArgs : _ErrorName extends string - ? { abi: [TAbi[number]] } & GetErrorArgs - : never) + ? { abi: [TAbi[number]] } & GetErrorArgs + : never) export type EncodeErrorResultErrorType = | GetAbiItemErrorType diff --git a/src/utils/abi/encodeEventTopics.ts b/src/utils/abi/encodeEventTopics.ts index 06599edb..fe774172 100644 --- a/src/utils/abi/encodeEventTopics.ts +++ b/src/utils/abi/encodeEventTopics.ts @@ -39,8 +39,8 @@ export type EncodeEventTopicsParameters< } & (TEventName extends string ? { abi: TAbi; args?: GetEventArgs } : _EventName extends string - ? { abi: [TAbi[number]]; args?: GetEventArgs } - : never) + ? { abi: [TAbi[number]]; args?: GetEventArgs } + : never) export type EncodeEventTopicsErrorType = | AbiEventNotFoundErrorType @@ -82,8 +82,8 @@ export function encodeEventTopics< const args_ = Array.isArray(args) ? args : Object.values(args).length > 0 - ? indexedInputs?.map((x: any) => (args as any)[x.name]) ?? [] - : [] + ? indexedInputs?.map((x: any) => (args as any)[x.name]) ?? [] + : [] if (args_.length > 0) { topics = @@ -93,8 +93,8 @@ export function encodeEventTopics< encodeArg({ param, value: args_[i][j] }), ) : args_[i] - ? encodeArg({ param, value: args_[i] }) - : null, + ? encodeArg({ param, value: args_[i] }) + : null, ) ?? [] } } diff --git a/src/utils/abi/encodeFunctionData.ts b/src/utils/abi/encodeFunctionData.ts index c610966f..58812e8e 100644 --- a/src/utils/abi/encodeFunctionData.ts +++ b/src/utils/abi/encodeFunctionData.ts @@ -36,8 +36,8 @@ export type EncodeFunctionDataParameters< } & (TFunctionName extends string ? { abi: TAbi } & GetFunctionArgs : _FunctionName extends string - ? { abi: [TAbi[number]] } & GetFunctionArgs - : never) + ? { abi: [TAbi[number]] } & GetFunctionArgs + : never) export type EncodeFunctionDataErrorType = | AbiFunctionNotFoundErrorType diff --git a/src/utils/abi/encodeFunctionResult.ts b/src/utils/abi/encodeFunctionResult.ts index acc1da76..e48deddd 100644 --- a/src/utils/abi/encodeFunctionResult.ts +++ b/src/utils/abi/encodeFunctionResult.ts @@ -32,11 +32,11 @@ export type EncodeFunctionResultParameters< } & (TFunctionName extends string ? { abi: TAbi; result?: ContractFunctionResult } : _FunctionName extends string - ? { - abi: [TAbi[number]] - result?: ContractFunctionResult - } - : never) + ? { + abi: [TAbi[number]] + result?: ContractFunctionResult + } + : never) export type EncodeFunctionResultErrorType = | AbiFunctionOutputsNotFoundError diff --git a/src/utils/encoding/fromBytes.ts b/src/utils/encoding/fromBytes.ts index 2731798c..b4e0bc84 100644 --- a/src/utils/encoding/fromBytes.ts +++ b/src/utils/encoding/fromBytes.ts @@ -27,14 +27,14 @@ export type FromBytesParameters< export type FromBytesReturnType = TTo extends 'string' ? string : TTo extends 'hex' - ? Hex - : TTo extends 'bigint' - ? bigint - : TTo extends 'number' - ? number - : TTo extends 'boolean' - ? boolean - : never + ? Hex + : TTo extends 'bigint' + ? bigint + : TTo extends 'number' + ? number + : TTo extends 'boolean' + ? boolean + : never export type FromBytesErrorType = | BytesToHexErrorType diff --git a/src/utils/encoding/fromHex.ts b/src/utils/encoding/fromHex.ts index 7eb9a17a..2feeeef7 100644 --- a/src/utils/encoding/fromHex.ts +++ b/src/utils/encoding/fromHex.ts @@ -41,14 +41,14 @@ export type FromHexParameters< export type FromHexReturnType = TTo extends 'string' ? string : TTo extends 'bigint' - ? bigint - : TTo extends 'number' - ? number - : TTo extends 'bytes' - ? ByteArray - : TTo extends 'boolean' - ? boolean - : never + ? bigint + : TTo extends 'number' + ? number + : TTo extends 'bytes' + ? ByteArray + : TTo extends 'boolean' + ? boolean + : never export type FromHexErrorType = | HexToNumberErrorType diff --git a/src/utils/errors/getContractError.ts b/src/utils/errors/getContractError.ts index 9c3f7ae3..4237ffec 100644 --- a/src/utils/errors/getContractError.ts +++ b/src/utils/errors/getContractError.ts @@ -48,8 +48,8 @@ export function getContractError>( err instanceof RawContractError ? err : err instanceof BaseError - ? err.walk((err) => 'data' in (err as Error)) || err.walk() - : {} + ? err.walk((err) => 'data' in (err as Error)) || err.walk() + : {} ) as RawContractError const cause = (() => { diff --git a/src/utils/transaction/getSerializedTransactionType.ts b/src/utils/transaction/getSerializedTransactionType.ts index 67424155..e6cf627b 100644 --- a/src/utils/transaction/getSerializedTransactionType.ts +++ b/src/utils/transaction/getSerializedTransactionType.ts @@ -16,8 +16,8 @@ export type GetSerializedTransactionType< > = TTransactionSerialized extends TransactionSerializedEIP1559 ? 'eip1559' : TTransactionSerialized extends TransactionSerializedEIP2930 - ? 'eip2930' - : 'legacy' + ? 'eip2930' + : 'legacy' export type GetSerializedTransactionTypeErrorType = | HexToNumberErrorType diff --git a/src/utils/transaction/getTransactionType.ts b/src/utils/transaction/getTransactionType.ts index 5bfd74a2..c9a15640 100644 --- a/src/utils/transaction/getTransactionType.ts +++ b/src/utils/transaction/getTransactionType.ts @@ -12,8 +12,7 @@ import type { } from '../../types/transaction.js' export type GetTransactionType< - TTransactionSerializable extends - TransactionSerializable = TransactionSerializable, + TTransactionSerializable extends TransactionSerializable = TransactionSerializable, > = | (TTransactionSerializable extends TransactionSerializableLegacy ? 'legacy' diff --git a/src/utils/transaction/serializeTransaction.ts b/src/utils/transaction/serializeTransaction.ts index 76eeec88..82d0dd8b 100644 --- a/src/utils/transaction/serializeTransaction.ts +++ b/src/utils/transaction/serializeTransaction.ts @@ -39,15 +39,12 @@ import { } from './serializeAccessList.js' export type SerializedTransactionReturnType< - TTransactionSerializable extends - TransactionSerializable = TransactionSerializable, - TTransactionType extends - TransactionType = GetTransactionType, + TTransactionSerializable extends TransactionSerializable = TransactionSerializable, + TTransactionType extends TransactionType = GetTransactionType, > = TransactionSerialized export type SerializeTransactionFn< - TTransactionSerializable extends - TransactionSerializable = TransactionSerializable, + TTransactionSerializable extends TransactionSerializable = TransactionSerializable, > = typeof serializeTransaction export type SerializeTransactionErrorType = diff --git a/test/src/utils.ts b/test/src/utils.ts index 6a90340b..d6ab87f1 100644 --- a/test/src/utils.ts +++ b/test/src/utils.ts @@ -195,8 +195,8 @@ export function createHttpServer( export async function deploy( args: DeployContractParameters< TAbi, - (typeof walletClientWithAccount)['chain'], - (typeof walletClientWithAccount)['account'] + typeof walletClientWithAccount['chain'], + typeof walletClientWithAccount['account'] >, ) { const hash = await deployContract(walletClientWithAccount, args)