From 6c371be7b4ae88ad467cf9863d6d3a3aff8c6910 Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Tue, 22 Aug 2023 11:43:38 +1000 Subject: [PATCH] wip --- chains/package.json | 8 +- chains/src/celo/formatters.test-d.ts | 2 +- chains/src/celo/formatters.test.ts | 2 +- chains/src/celo/formatters.ts | 11 +- chains/src/errors.ts | 68 -- chains/src/index.ts | 3 + chains/src/optimism/formatters.test-d.ts | 2 +- chains/src/optimism/formatters.test.ts | 2 +- chains/src/optimism/formatters.ts | 8 +- chains/src/types.ts | 14 +- chains/src/utils.ts | 109 ++- chains/tsconfig.base.json | 45 + chains/tsconfig.json | 11 +- package.json | 77 +- playgrounds/bun/index.ts | 2 +- pnpm-lock.yaml | 43 +- src/_test/utils.ts | 4 +- src/actions/ens/getEnsAddress.test.ts | 2 +- src/actions/ens/getEnsAddress.ts | 2 +- src/actions/ens/getEnsAvatar.ts | 2 +- src/actions/ens/getEnsName.test.ts | 2 +- src/actions/ens/getEnsName.ts | 2 +- src/actions/ens/getEnsResolver.test.ts | 2 +- src/actions/ens/getEnsResolver.ts | 2 +- src/actions/ens/getEnsText.test.ts | 2 +- src/actions/ens/getEnsText.ts | 2 +- src/actions/getContract.test-d.ts | 2 +- src/actions/getContract.ts | 2 +- src/actions/public/call.test.ts | 2 +- src/actions/public/call.ts | 2 +- src/actions/public/createBlockFilter.ts | 2 +- .../public/createContractEventFilter.ts | 2 +- src/actions/public/createEventFilter.ts | 2 +- .../public/createPendingTransactionFilter.ts | 2 +- src/actions/public/estimateContractGas.ts | 2 +- src/actions/public/estimateFeesPerGas.test.ts | 2 +- src/actions/public/estimateFeesPerGas.ts | 10 +- src/actions/public/estimateGas.ts | 2 +- .../estimateMaxPriorityFeePerGas.test.ts | 2 +- .../public/estimateMaxPriorityFeePerGas.ts | 2 +- src/actions/public/getBalance.ts | 2 +- src/actions/public/getBlock.test-d.ts | 2 +- src/actions/public/getBlock.test.ts | 2 +- src/actions/public/getBlock.ts | 2 +- src/actions/public/getBlockNumber.ts | 2 +- .../public/getBlockTransactionCount.ts | 2 +- src/actions/public/getBytecode.ts | 2 +- src/actions/public/getChainId.ts | 2 +- src/actions/public/getFeeHistory.ts | 2 +- src/actions/public/getFilterChanges.ts | 2 +- src/actions/public/getFilterLogs.ts | 2 +- src/actions/public/getGasPrice.ts | 2 +- src/actions/public/getLogs.ts | 2 +- src/actions/public/getStorageAt.ts | 2 +- src/actions/public/getTransaction.test-d.ts | 2 +- src/actions/public/getTransaction.test.ts | 2 +- src/actions/public/getTransaction.ts | 2 +- .../public/getTransactionConfirmations.ts | 2 +- src/actions/public/getTransactionCount.ts | 2 +- .../public/getTransactionReceipt.test.ts | 2 +- src/actions/public/getTransactionReceipt.ts | 2 +- src/actions/public/multicall.test.ts | 2 +- src/actions/public/multicall.ts | 2 +- src/actions/public/readContract.ts | 2 +- src/actions/public/simulateContract.ts | 2 +- src/actions/public/uninstallFilter.ts | 2 +- src/actions/public/verifyHash.ts | 2 +- src/actions/public/verifyMessage.ts | 2 +- src/actions/public/verifyTypedData.ts | 2 +- .../public/waitForTransactionReceipt.ts | 2 +- src/actions/public/watchBlockNumber.test.ts | 2 +- src/actions/public/watchBlockNumber.ts | 2 +- src/actions/public/watchBlocks.test.ts | 2 +- src/actions/public/watchBlocks.ts | 2 +- src/actions/public/watchContractEvent.ts | 2 +- src/actions/public/watchEvent.ts | 2 +- .../public/watchPendingTransactions.ts | 2 +- src/actions/test/dropTransaction.ts | 2 +- src/actions/test/getAutomine.ts | 2 +- src/actions/test/getTxpoolContent.ts | 2 +- src/actions/test/getTxpoolStatus.ts | 2 +- src/actions/test/impersonateAccount.ts | 2 +- src/actions/test/increaseTime.ts | 2 +- src/actions/test/inspectTxpool.ts | 2 +- src/actions/test/mine.ts | 2 +- .../test/removeBlockTimestampInterval.ts | 2 +- src/actions/test/reset.ts | 2 +- src/actions/test/revert.ts | 2 +- .../test/sendUnsignedTransaction.test.ts | 2 +- src/actions/test/sendUnsignedTransaction.ts | 2 +- src/actions/test/setAutomine.ts | 2 +- src/actions/test/setBalance.ts | 2 +- src/actions/test/setBlockGasLimit.ts | 2 +- src/actions/test/setBlockTimestampInterval.ts | 2 +- src/actions/test/setCode.ts | 2 +- src/actions/test/setCoinbase.ts | 2 +- src/actions/test/setIntervalMining.ts | 2 +- src/actions/test/setLoggingEnabled.ts | 2 +- src/actions/test/setMinGasPrice.ts | 2 +- src/actions/test/setNextBlockBaseFeePerGas.ts | 2 +- src/actions/test/setNextBlockTimestamp.ts | 2 +- src/actions/test/setNonce.ts | 2 +- src/actions/test/setRpcUrl.ts | 2 +- src/actions/test/setStorageAt.ts | 2 +- src/actions/test/snapshot.ts | 2 +- src/actions/test/stopImpersonatingAccount.ts | 2 +- src/actions/wallet/addChain.test.ts | 2 +- src/actions/wallet/addChain.ts | 2 +- src/actions/wallet/deployContract.ts | 2 +- src/actions/wallet/getAddresses.ts | 2 +- src/actions/wallet/getPermissions.ts | 2 +- src/actions/wallet/requestAddresses.ts | 2 +- src/actions/wallet/requestPermissions.ts | 2 +- src/actions/wallet/sendTransaction.test-d.ts | 2 +- src/actions/wallet/sendTransaction.test.ts | 2 +- src/actions/wallet/sendTransaction.ts | 2 +- src/actions/wallet/signMessage.ts | 2 +- src/actions/wallet/signTypedData.ts | 2 +- src/actions/wallet/switchChain.test.ts | 2 +- src/actions/wallet/switchChain.ts | 2 +- src/actions/wallet/watchAsset.ts | 2 +- src/actions/wallet/writeContract.test.ts | 2 +- src/actions/wallet/writeContract.ts | 2 +- src/chains/celo/formatters.test-d.ts | 312 ------- src/chains/celo/formatters.test.ts | 810 ------------------ src/chains/celo/formatters.ts | 85 -- src/chains/celo/parsers.test.ts | 222 ----- src/chains/celo/parsers.ts | 123 --- src/chains/celo/serializers.test.ts | 342 -------- src/chains/celo/serializers.ts | 169 ---- src/chains/celo/types.ts | 143 ---- src/chains/index.test.ts | 107 --- src/chains/index.ts | 279 +++--- src/chains/optimism/fees.ts | 5 - src/chains/optimism/formatters.test-d.ts | 119 --- src/chains/optimism/formatters.test.ts | 685 --------------- src/chains/optimism/formatters.ts | 74 -- src/chains/optimism/types.ts | 102 --- src/chains/types.ts | 165 ---- src/chains/utils.test.ts | 14 - src/chains/utils.ts | 80 +- src/clients/createClient.test-d.ts | 2 +- src/clients/createClient.test.ts | 2 +- src/clients/createClient.ts | 2 +- src/clients/createPublicClient.test-d.ts | 2 +- src/clients/createPublicClient.test.ts | 2 +- src/clients/createPublicClient.ts | 3 +- src/clients/createTestClient.test-d.ts | 2 +- src/clients/createTestClient.test.ts | 2 +- src/clients/createTestClient.ts | 2 +- src/clients/createWalletClient.test-d.ts | 2 +- src/clients/createWalletClient.test.ts | 2 +- src/clients/createWalletClient.ts | 2 +- src/clients/decorators/public.ts | 2 +- src/clients/decorators/test.ts | 2 +- src/clients/decorators/wallet.test.ts | 2 +- src/clients/decorators/wallet.ts | 2 +- src/clients/transports/createTransport.ts | 2 +- src/clients/transports/fallback.test.ts | 2 +- src/clients/transports/fallback.ts | 2 +- src/clients/transports/http.test.ts | 2 +- src/clients/transports/webSocket.test.ts | 2 +- src/errors/chain.test.ts | 2 +- src/errors/chain.ts | 2 +- src/errors/contract.test.ts | 2 +- src/errors/contract.ts | 2 +- src/errors/estimateGas.test.ts | 2 +- src/errors/estimateGas.ts | 2 +- src/errors/transaction.test.ts | 2 +- src/errors/transaction.ts | 2 +- src/index.ts | 58 +- src/internal.ts | 2 +- src/types/chain.ts | 2 +- src/utils/ccip.ts | 2 +- src/utils/chain.test.ts | 2 +- src/utils/chain.ts | 12 +- src/utils/ens/avatar/parseAvatarRecord.ts | 2 +- src/utils/ens/avatar/utils.ts | 2 +- src/utils/errors/getCallError.ts | 2 +- src/utils/errors/getEstimateGasError.ts | 2 +- src/utils/errors/getTransactionError.ts | 2 +- src/utils/filters/createFilterRequestScope.ts | 2 +- src/utils/formatters/block.ts | 13 +- src/utils/formatters/extract.ts | 2 +- src/utils/formatters/formatter.ts | 37 - src/utils/formatters/transaction.ts | 16 +- src/utils/formatters/transactionReceipt.ts | 11 +- src/utils/formatters/transactionRequest.ts | 11 +- src/utils/index.ts | 9 +- src/utils/transaction/assertRequest.ts | 2 +- src/utils/transaction/prepareRequest.ts | 2 +- tsconfig.base.json | 10 +- tsconfig.build.json | 2 +- tsconfig.json | 2 +- 194 files changed, 548 insertions(+), 4185 deletions(-) delete mode 100644 chains/src/errors.ts create mode 100644 chains/tsconfig.base.json delete mode 100644 src/chains/celo/formatters.test-d.ts delete mode 100644 src/chains/celo/formatters.test.ts delete mode 100644 src/chains/celo/formatters.ts delete mode 100644 src/chains/celo/parsers.test.ts delete mode 100644 src/chains/celo/parsers.ts delete mode 100644 src/chains/celo/serializers.test.ts delete mode 100644 src/chains/celo/serializers.ts delete mode 100644 src/chains/celo/types.ts delete mode 100644 src/chains/index.test.ts delete mode 100644 src/chains/optimism/fees.ts delete mode 100644 src/chains/optimism/formatters.test-d.ts delete mode 100644 src/chains/optimism/formatters.test.ts delete mode 100644 src/chains/optimism/formatters.ts delete mode 100644 src/chains/optimism/types.ts delete mode 100644 src/chains/types.ts delete mode 100644 src/chains/utils.test.ts delete mode 100644 src/utils/formatters/formatter.ts diff --git a/chains/package.json b/chains/package.json index c7feb39370..99f95ca32d 100644 --- a/chains/package.json +++ b/chains/package.json @@ -5,9 +5,10 @@ "scripts": { "build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types", "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'", + "build:esm": "tsc --project tsconfig.build.json --module es2020 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'", "build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap", - "clean": "rimraf dist" + "clean": "rimraf dist", + "typecheck": "tsc --noEmit" }, "type": "module", "main": "./dist/cjs/index.js", @@ -37,6 +38,9 @@ "optional": true } }, + "dependencies": { + "@wagmi/chains": "1.7.0" + }, "devDependencies": { "viem": "workspace:*" }, diff --git a/chains/src/celo/formatters.test-d.ts b/chains/src/celo/formatters.test-d.ts index 1752d9feba..e0b3641acf 100644 --- a/chains/src/celo/formatters.test-d.ts +++ b/chains/src/celo/formatters.test-d.ts @@ -1,5 +1,4 @@ import { - http, type Hash, type RpcBlock, type RpcTransaction, @@ -7,6 +6,7 @@ import { type TransactionRequest, createPublicClient, createWalletClient, + http, } from 'viem' import { getBlock, diff --git a/chains/src/celo/formatters.test.ts b/chains/src/celo/formatters.test.ts index a47e2450e3..e4fe153aa8 100644 --- a/chains/src/celo/formatters.test.ts +++ b/chains/src/celo/formatters.test.ts @@ -1,4 +1,4 @@ -import { http, createPublicClient } from 'viem' +import { createPublicClient, http } from 'viem' import { getBlock, getTransaction, getTransactionReceipt } from 'viem/actions' import { describe, expect, test } from 'vitest' diff --git a/chains/src/celo/formatters.ts b/chains/src/celo/formatters.ts index 2ad270b525..56421a8527 100644 --- a/chains/src/celo/formatters.ts +++ b/chains/src/celo/formatters.ts @@ -1,14 +1,12 @@ +import { type Hash, formatTransaction, hexToBigInt, numberToHex } from 'viem' + +import type { ChainFormatters } from '../types.js' import { defineBlock, - formatTransaction, - hexToBigInt, - type Hash, defineTransaction, defineTransactionReceipt, defineTransactionRequest, - numberToHex, -} from 'viem' - +} from '../utils.js' import type { CeloBlockOverrides, CeloRpcTransaction, @@ -20,7 +18,6 @@ import type { CeloTransactionReceiptOverrides, CeloTransactionRequestOverrides, } from './types.js' -import type { ChainFormatters } from '../types.js' export const formattersCelo = { block: /*#__PURE__*/ defineBlock({ diff --git a/chains/src/errors.ts b/chains/src/errors.ts deleted file mode 100644 index 903bd5990c..0000000000 --- a/chains/src/errors.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { BaseError } from 'viem' -import { type Chain } from './types.js' - -export class ChainDoesNotSupportContract extends BaseError { - override name = 'ChainDoesNotSupportContract' - constructor({ - blockNumber, - chain, - contract, - }: { - blockNumber?: bigint - chain: Chain - contract: { name: string; blockCreated?: number } - }) { - super( - `Chain "${chain.name}" does not support contract "${contract.name}".`, - { - metaMessages: [ - 'This could be due to any of the following:', - ...(blockNumber && - contract.blockCreated && - contract.blockCreated > blockNumber - ? [ - `- The contract "${contract.name}" was not deployed until block ${contract.blockCreated} (current block ${blockNumber}).`, - ] - : [ - `- The chain does not have the contract "${contract.name}" configured.`, - ]), - ], - }, - ) - } -} - -export class ChainMismatchError extends BaseError { - override name = 'ChainMismatchError' - - constructor({ - chain, - currentChainId, - }: { - chain: Chain - currentChainId: number - }) { - super( - `The current chain of the wallet (id: ${currentChainId}) does not match the target chain for the transaction (id: ${chain.id} – ${chain.name}).`, - { - metaMessages: [ - `Current Chain ID: ${currentChainId}`, - `Expected Chain ID: ${chain.id} – ${chain.name}`, - ], - }, - ) - } -} - -export class ChainNotFoundError extends BaseError { - override name = 'ChainNotFoundError' - - constructor() { - super( - [ - 'No chain was provided to the request.', - 'Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient.', - ].join('\n'), - ) - } -} diff --git a/chains/src/index.ts b/chains/src/index.ts index 2f52944a41..d56f1b4022 100644 --- a/chains/src/index.ts +++ b/chains/src/index.ts @@ -158,7 +158,10 @@ export const zoraTestnet = /*#__PURE__*/ defineChain(chains.zoraTestnet, { export type { Chain, ChainContract, + ChainConfig, + ChainEstimateFeesPerGasFnParameters, ChainFees, + ChainFeesFnParameters, ChainFormatter, ChainFormatters, ChainSerializers, diff --git a/chains/src/optimism/formatters.test-d.ts b/chains/src/optimism/formatters.test-d.ts index 0e7552b834..c586f0dd95 100644 --- a/chains/src/optimism/formatters.test-d.ts +++ b/chains/src/optimism/formatters.test-d.ts @@ -1,4 +1,4 @@ -import { http, type Hash, type RpcBlock, createPublicClient } from 'viem' +import { type Hash, type RpcBlock, createPublicClient, http } from 'viem' import { getBlock, getTransaction, getTransactionReceipt } from 'viem/actions' import type { Assign } from 'viem/internal' import { describe, expectTypeOf, test } from 'vitest' diff --git a/chains/src/optimism/formatters.test.ts b/chains/src/optimism/formatters.test.ts index 055a1db365..b2d52dfecb 100644 --- a/chains/src/optimism/formatters.test.ts +++ b/chains/src/optimism/formatters.test.ts @@ -1,4 +1,4 @@ -import { http, createPublicClient } from 'viem' +import { createPublicClient, http } from 'viem' import { getBlock, getTransaction, getTransactionReceipt } from 'viem/actions' import { describe, expect, test } from 'vitest' diff --git a/chains/src/optimism/formatters.ts b/chains/src/optimism/formatters.ts index 4c5900d049..2ce23c42bc 100644 --- a/chains/src/optimism/formatters.ts +++ b/chains/src/optimism/formatters.ts @@ -1,14 +1,16 @@ import { type Hash, type RpcTransaction, - defineBlock, - defineTransaction, - defineTransactionReceipt, formatTransaction, hexToBigInt, } from 'viem' import type { ChainFormatters } from '../types.js' +import { + defineBlock, + defineTransaction, + defineTransactionReceipt, +} from '../utils.js' import type { OptimismBlockOverrides, OptimismRpcBlockOverrides, diff --git a/chains/src/types.ts b/chains/src/types.ts index 7ec073800a..0ec8ca2334 100644 --- a/chains/src/types.ts +++ b/chains/src/types.ts @@ -1,5 +1,17 @@ import type { Address } from 'abitype' -import type { EstimateFeesPerGasReturnType } from 'viem' +import type { + Account, + Client, + EstimateFeesPerGasReturnType, + FeeValuesType, + FormattedBlock, + PrepareRequestParameters, + SerializeTransactionFn, + TransactionSerializable, + TransactionSerializableGeneric, + Transport, +} from 'viem' +import type { Prettify } from 'viem/internal' export type Chain< formatters extends ChainFormatters | undefined = ChainFormatters | undefined, diff --git a/chains/src/utils.ts b/chains/src/utils.ts index 1df042d80a..eed1db411a 100644 --- a/chains/src/utils.ts +++ b/chains/src/utils.ts @@ -1,30 +1,12 @@ -import type { Assign } from 'viem/internal' - -import type { - Chain, - ChainConfig, - ChainContract, - ChainFormatters, -} from './types.js' import { - ChainDoesNotSupportContract, - ChainMismatchError, - ChainNotFoundError, -} from './errors.js' - -export type AssertCurrentChainParameters = { - chain?: Chain - currentChainId: number -} + formatBlock, + formatTransaction, + formatTransactionReceipt, + formatTransactionRequest, +} from 'viem' +import type { Assign, Prettify } from 'viem/internal' -export function assertCurrentChain({ - chain, - currentChainId, -}: AssertCurrentChainParameters): void { - if (!chain) throw new ChainNotFoundError() - if (currentChainId !== chain.id) - throw new ChainMismatchError({ chain, currentChainId }) -} +import type { Chain, ChainConfig, ChainFormatters } from './types.js' export function defineChain< chain extends Chain, @@ -46,39 +28,56 @@ export function defineChain< } as unknown as Assign> } -export function getChainContractAddress({ - blockNumber, - chain, - contract: name, -}: { - blockNumber?: bigint - chain: Chain - contract: string -}) { - const contract = (chain?.contracts as Record)?.[name] - if (!contract) - throw new ChainDoesNotSupportContract({ - chain, - contract: { name }, - }) - - if ( - blockNumber && - contract.blockCreated && - contract.blockCreated > blockNumber - ) - throw new ChainDoesNotSupportContract({ - blockNumber, - chain, - contract: { - name, - blockCreated: contract.blockCreated, +export function defineFormatter( + type: TType, + format: (_: TParameters) => TReturnType, +) { + return < + TOverrideParameters, + TOverrideReturnType, + TExclude extends (keyof TParameters)[] = [], + >({ + exclude, + format: overrides, + }: { + exclude?: TExclude + format: (_: TOverrideParameters) => TOverrideReturnType + }) => { + return { + exclude, + format: (args: Assign) => { + const formatted = format(args as any) + if (exclude) { + for (const key of exclude) { + delete (formatted as any)[key] + } + } + return { + ...formatted, + ...overrides(args), + } as Prettify> & { + [K in TExclude[number]]: never + } }, - }) - - return contract.address + type, + } + } } +export const defineBlock = /*#__PURE__*/ defineFormatter('block', formatBlock) +export const defineTransaction = /*#__PURE__*/ defineFormatter( + 'transaction', + formatTransaction, +) +export const defineTransactionReceipt = /*#__PURE__*/ defineFormatter( + 'transactionReceipt', + formatTransactionReceipt, +) +export const defineTransactionRequest = /*#__PURE__*/ defineFormatter( + 'transactionRequest', + formatTransactionRequest, +) + /////////////////////////////////////////////////////////////// // Exports diff --git a/chains/tsconfig.base.json b/chains/tsconfig.base.json new file mode 100644 index 0000000000..9e3351f97e --- /dev/null +++ b/chains/tsconfig.base.json @@ -0,0 +1,45 @@ +{ + // This tsconfig file contains the shared config for the build (tsconfig.build.json) and type checking (tsconfig.json) config. + "include": [], + "compilerOptions": { + // Incremental builds + // NOTE: Enabling incremental builds speeds up `tsc`. Keep in mind though that it does not reliably bust the cache when the `tsconfig.json` file changes. + "incremental": true, + + // Type checking + "strict": true, + "useDefineForClassFields": true, // Not enabled by default in `strict` mode unless we bump `target` to ES2022. + "noFallthroughCasesInSwitch": true, // Not enabled by default in `strict` mode. + "noImplicitReturns": true, // Not enabled by default in `strict` mode. + "useUnknownInCatchVariables": true, // TODO: This would normally be enabled in `strict` mode but would require some adjustments to the codebase. + "noImplicitOverride": true, // Not enabled by default in `strict` mode. + "noUnusedLocals": true, // Not enabled by default in `strict` mode. + "noUnusedParameters": true, // Not enabled by default in `strict` mode. + // TODO: The following options are also not enabled by default in `strict` mode and would be nice to have but would require some adjustments to the codebase. + // "exactOptionalPropertyTypes": true, + // "noUncheckedIndexedAccess": true, + + // JavaScript support + "allowJs": false, + "checkJs": false, + + // Interop constraints + "esModuleInterop": false, + "allowSyntheticDefaultImports": false, + "forceConsistentCasingInFileNames": true, + "verbatimModuleSyntax": true, + "importHelpers": true, // This is only used for build validation. Since we do not have `tslib` installed, this will fail if we accidentally make use of anything that'd require injection of helpers. + + // Language and environment + "moduleResolution": "NodeNext", + "module": "ESNext", + "target": "ES2021", // Setting this to `ES2021` enables native support for `Node v16+`: https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping. + "lib": [ + "ES2022", // By using ES2022 we get access to the `.cause` property on `Error` instances. + "DOM" // We are adding `DOM` here to get the `fetch`, etc. types. This should be removed once these types are available via DefinitelyTyped. + ], + + // Skip type checking for node modules + "skipLibCheck": true + } +} diff --git a/chains/tsconfig.json b/chains/tsconfig.json index 36228dbda1..db0c876d2f 100644 --- a/chains/tsconfig.json +++ b/chains/tsconfig.json @@ -1,13 +1,6 @@ { // This configuration is used for local development and type checking. - "extends": "../tsconfig.base.json", + "extends": "./tsconfig.base.json", "include": ["src"], - "exclude": [], - "compilerOptions": { - "baseUrl": ".", - "paths": { - "viem": ["../src/index.ts"], - "viem/*": ["../src/*.ts", "../src/*/index.ts"], - } - } + "exclude": [] } diff --git a/package.json b/package.json index f7dfe9da42..863f3c7183 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "bench:ci": "CI=true vitest bench", "build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types", "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'", + "build:esm": "tsc --project tsconfig.build.json --module es2020 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'", "build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap", "changeset": "changeset", "changeset:release": "pnpm build && changeset publish", @@ -68,9 +68,9 @@ "default": "./dist/cjs/actions/index.js" }, "./chains": { - "types": "./dist/types/chains/index.d.ts", - "import": "./dist/esm/chains/index.js", - "default": "./dist/cjs/chains/index.js" + "types": "./dist/types/chains.d.ts", + "import": "./dist/esm/chains.js", + "default": "./dist/cjs/chains.js" }, "./chains/utils": { "types": "./dist/types/chains/utils.d.ts", @@ -121,42 +121,18 @@ }, "typesVersions": { "*": { - "abi": [ - "./dist/types/abi.d.ts" - ], - "accounts": [ - "./dist/types/accounts/index.d.ts" - ], - "actions": [ - "./dist/types/actions/index.d.ts" - ], - "chains": [ - "./dist/types/chains.d.ts" - ], - "contract": [ - "./dist/types/contract.d.ts" - ], - "ens": [ - "./dist/types/ens.d.ts" - ], - "internal": [ - "./dist/types/internal.d.ts" - ], - "public": [ - "./dist/types/public.d.ts" - ], - "test": [ - "./dist/types/test.d.ts" - ], - "utils": [ - "./dist/types/utils/index.d.ts" - ], - "wallet": [ - "./dist/types/wallet.d.ts" - ], - "window": [ - "./dist/types/window.d.ts" - ] + "abi": ["./dist/types/abi.d.ts"], + "accounts": ["./dist/types/accounts/index.d.ts"], + "actions": ["./dist/types/actions/index.d.ts"], + "chains": ["./dist/types/chains.d.ts"], + "contract": ["./dist/types/contract.d.ts"], + "ens": ["./dist/types/ens.d.ts"], + "internal": ["./dist/types/internal.d.ts"], + "public": ["./dist/types/public.d.ts"], + "test": ["./dist/types/test.d.ts"], + "utils": ["./dist/types/utils/index.d.ts"], + "wallet": ["./dist/types/wallet.d.ts"], + "window": ["./dist/types/window.d.ts"] } }, "peerDependencies": { @@ -174,7 +150,7 @@ "@scure/bip32": "1.3.0", "@scure/bip39": "1.2.0", "@types/ws": "^8.5.4", - "@wagmi/chains": "1.7.0", + "@viem/chains": "workspace:*", "abitype": "0.9.3", "isomorphic-ws": "5.0.0", "ws": "8.12.0" @@ -198,29 +174,20 @@ "rome": "12.1.3-nightly.4c8cf32", "simple-git-hooks": "^2.8.1", "size-limit": "^8.2.4", - "typescript": "5.0.4", + "typescript": "5.1.6", "vite": "^4.4.2", "vitest": "~0.30.1" }, "license": "MIT", "repository": "wagmi-dev/viem", - "authors": [ - "awkweb.eth", - "jxom.eth" - ], + "authors": ["awkweb.eth", "jxom.eth"], "funding": [ { "type": "github", "url": "https://github.com/sponsors/wagmi-dev" } ], - "keywords": [ - "eth", - "ethereum", - "dapps", - "wallet", - "web3" - ], + "keywords": ["eth", "ethereum", "dapps", "wallet", "web3"], "size-limit": [ { "name": "viem (cjs)", @@ -273,9 +240,7 @@ "viem": "workspace:*" }, "peerDependencyRules": { - "ignoreMissing": [ - "@algolia/client-search" - ] + "ignoreMissing": ["@algolia/client-search"] }, "patchedDependencies": { "vitepress@1.0.0-beta.4": "patches/vitepress@1.0.0-beta.4.patch" diff --git a/playgrounds/bun/index.ts b/playgrounds/bun/index.ts index 7ac64d02b3..ed63cb6c45 100644 --- a/playgrounds/bun/index.ts +++ b/playgrounds/bun/index.ts @@ -1,4 +1,4 @@ -import { http, createPublicClient } from 'viem' +import { createPublicClient, http } from 'viem' import { mainnet, polygon } from 'viem/chains' //////////////////////////////////////////////////////////////////// diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 86eca29c4a..4e5d948e16 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,12 +30,12 @@ importers: '@types/ws': specifier: ^8.5.4 version: 8.5.4 - '@wagmi/chains': - specifier: 1.7.0 - version: 1.7.0(typescript@5.0.4) + '@viem/chains': + specifier: workspace:* + version: link:chains abitype: specifier: 0.9.3 - version: 0.9.3(typescript@5.0.4) + version: 0.9.3(typescript@5.1.6) isomorphic-ws: specifier: 5.0.0 version: 5.0.0(ws@8.12.0) @@ -72,7 +72,7 @@ importers: version: 0.30.1 '@wagmi/cli': specifier: ^0.1.6 - version: 0.1.6(typescript@5.0.4) + version: 0.1.6(typescript@5.1.6) bun: specifier: ^0.5.9 version: 0.5.9 @@ -98,8 +98,8 @@ importers: specifier: ^8.2.4 version: 8.2.4 typescript: - specifier: 5.0.4 - version: 5.0.4 + specifier: 5.1.6 + version: 5.1.6 vite: specifier: ^4.4.2 version: 4.4.2(@types/node@18.16.3) @@ -109,6 +109,9 @@ importers: chains: dependencies: + '@wagmi/chains': + specifier: 1.7.0 + version: 1.7.0(typescript@5.0.4) typescript: specifier: '>=5.0.4' version: 5.0.4 @@ -2731,7 +2734,7 @@ packages: - vue dev: true - /@wagmi/chains@0.2.7(typescript@5.0.4): + /@wagmi/chains@0.2.7(typescript@5.1.6): resolution: {integrity: sha512-Oqnkl5n9MTBdMzgIwwdSKEDfm0Vdv2CYBaDyTa5SiTjFNaIfT6MRATLg7KbI3JydfxqJphsVFL+TZZqFvkte/g==} peerDependencies: typescript: '>=4.9.4' @@ -2739,7 +2742,7 @@ packages: typescript: optional: true dependencies: - typescript: 5.0.4 + typescript: 5.1.6 dev: true /@wagmi/chains@1.7.0(typescript@5.0.4): @@ -2753,7 +2756,7 @@ packages: typescript: 5.0.4 dev: false - /@wagmi/cli@0.1.6(typescript@5.0.4): + /@wagmi/cli@0.1.6(typescript@5.1.6): resolution: {integrity: sha512-4ri/QATYDnLNZKVbnulW1Skfu2K5Jc+O0joULoHC6Ag/8Z1QlMEHl9GRXhO+6q68tv382EnVxjIUm6VuzbWpqA==} engines: {node: '>=14'} hasBin: true @@ -2770,8 +2773,8 @@ packages: optional: true dependencies: '@ethersproject/address': 5.7.0 - '@wagmi/chains': 0.2.7(typescript@5.0.4) - abitype: 0.3.0(typescript@5.0.4)(zod@3.20.2) + '@wagmi/chains': 0.2.7(typescript@5.1.6) + abitype: 0.3.0(typescript@5.1.6)(zod@3.20.2) abort-controller: 3.0.0 bundle-require: 3.1.2(esbuild@0.15.13) cac: 6.7.14 @@ -2791,7 +2794,7 @@ packages: pathe: 1.1.0 picocolors: 1.0.0 prettier: 2.8.3 - typescript: 5.0.4 + typescript: 5.1.6 zod: 3.20.2 dev: true @@ -2909,7 +2912,7 @@ packages: resolution: {integrity: sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==} dev: true - /abitype@0.3.0(typescript@5.0.4)(zod@3.20.2): + /abitype@0.3.0(typescript@5.1.6)(zod@3.20.2): resolution: {integrity: sha512-0YokyAV4hKMcy97Pl+6QgZBlBdZJN2llslOs7kiFY+cu7kMlVXDBpxMExfv0krzBCQt2t7hNovpQ3y/zvEm18A==} engines: {pnpm: '>=7'} peerDependencies: @@ -2919,11 +2922,11 @@ packages: zod: optional: true dependencies: - typescript: 5.0.4 + typescript: 5.1.6 zod: 3.20.2 dev: true - /abitype@0.9.3(typescript@5.0.4): + /abitype@0.9.3(typescript@5.1.6): resolution: {integrity: sha512-dz4qCQLurx97FQhnb/EIYTk/ldQ+oafEDUqC0VVIeQS1Q48/YWt/9YNfMmp9SLFqN41ktxny3c8aYxHjmFIB/w==} peerDependencies: typescript: '>=5.0.4' @@ -2934,7 +2937,7 @@ packages: zod: optional: true dependencies: - typescript: 5.0.4 + typescript: 5.1.6 dev: false /abort-controller@3.0.0: @@ -6667,6 +6670,12 @@ packages: resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==} engines: {node: '>=12.20'} hasBin: true + dev: false + + /typescript@5.1.6: + resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==} + engines: {node: '>=14.17'} + hasBin: true /ufo@1.1.1: resolution: {integrity: sha512-MvlCc4GHrmZdAllBc0iUDowff36Q9Ndw/UzqmEKyrfSzokTd9ZCy1i+IIk5hrYKkjoYVQyNbrw7/F8XJ2rEwTg==} diff --git a/src/_test/utils.ts b/src/_test/utils.ts index 948b397de8..277927fb48 100644 --- a/src/_test/utils.ts +++ b/src/_test/utils.ts @@ -17,8 +17,6 @@ import { deployContract, } from '../actions/wallet/deployContract.js' import { writeContract } from '../actions/wallet/writeContract.js' -import { localhost, mainnet } from '../chains/index.js' -import type { Chain } from '../chains/types.js' import { createPublicClient } from '../clients/createPublicClient.js' import { createTestClient } from '../clients/createTestClient.js' import { createWalletClient } from '../clients/createWalletClient.js' @@ -30,6 +28,8 @@ import { type EIP1193Provider, ProviderRpcError } from '../types/eip1193.js' import type { Hex } from '../types/misc.js' import { namehash } from '../utils/ens/namehash.js' import { rpc } from '../utils/rpc.js' +import { localhost, mainnet } from '@viem/chains' +import type { Chain } from '@viem/chains' import { baycContractConfig, ensRegistryConfig } from './abis.js' import { diff --git a/src/actions/ens/getEnsAddress.test.ts b/src/actions/ens/getEnsAddress.test.ts index 8897a8f4ad..94cbc69787 100644 --- a/src/actions/ens/getEnsAddress.test.ts +++ b/src/actions/ens/getEnsAddress.test.ts @@ -6,9 +6,9 @@ import { setBlockNumber, setVitalikResolver, } from '../../_test/utils.js' -import { mainnet, optimism } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' +import { mainnet, optimism } from '@viem/chains' import { getEnsAddress } from './getEnsAddress.js' diff --git a/src/actions/ens/getEnsAddress.ts b/src/actions/ens/getEnsAddress.ts index 67461780a3..eaf0bf8eb5 100644 --- a/src/actions/ens/getEnsAddress.ts +++ b/src/actions/ens/getEnsAddress.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { @@ -20,6 +19,7 @@ import { type ReadContractParameters, readContract, } from '../public/readContract.js' +import type { Chain } from '@viem/chains' export type GetEnsAddressParameters = Prettify< Pick & { diff --git a/src/actions/ens/getEnsAvatar.ts b/src/actions/ens/getEnsAvatar.ts index 3431eb989e..9091ce670e 100644 --- a/src/actions/ens/getEnsAvatar.ts +++ b/src/actions/ens/getEnsAvatar.ts @@ -1,9 +1,9 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { AssetGatewayUrls } from '../../types/ens.js' import type { Prettify } from '../../types/utils.js' import { parseAvatarRecord } from '../../utils/ens/avatar/parseAvatarRecord.js' +import type { Chain } from '@viem/chains' import { type GetEnsTextParameters, getEnsText } from './getEnsText.js' diff --git a/src/actions/ens/getEnsName.test.ts b/src/actions/ens/getEnsName.test.ts index 69d7a069fa..fcbb9c519d 100644 --- a/src/actions/ens/getEnsName.test.ts +++ b/src/actions/ens/getEnsName.test.ts @@ -2,9 +2,9 @@ import { beforeAll, describe, expect, test } from 'vitest' import { address, localHttpUrl } from '../../_test/constants.js' import { publicClient, setBlockNumber } from '../../_test/utils.js' -import { optimism } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' +import { optimism } from '@viem/chains' import { getEnsName } from './getEnsName.js' diff --git a/src/actions/ens/getEnsName.ts b/src/actions/ens/getEnsName.ts index 5b34998c2c..6d6bda6d6a 100644 --- a/src/actions/ens/getEnsName.ts +++ b/src/actions/ens/getEnsName.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { universalResolverReverseAbi } from '../../constants/abis.js' @@ -13,6 +12,7 @@ import { type ReadContractParameters, readContract, } from '../public/readContract.js' +import type { Chain } from '@viem/chains' export type GetEnsNameParameters = Prettify< Pick & { diff --git a/src/actions/ens/getEnsResolver.test.ts b/src/actions/ens/getEnsResolver.test.ts index b1ddf2e1f9..52138fd5b5 100644 --- a/src/actions/ens/getEnsResolver.test.ts +++ b/src/actions/ens/getEnsResolver.test.ts @@ -2,9 +2,9 @@ import { beforeAll, expect, test } from 'vitest' import { localHttpUrl } from '../../_test/constants.js' import { publicClient, setBlockNumber } from '../../_test/utils.js' -import { optimism } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' +import { optimism } from '@viem/chains' import { getEnsResolver } from './getEnsResolver.js' diff --git a/src/actions/ens/getEnsResolver.ts b/src/actions/ens/getEnsResolver.ts index 19a50978a2..977e3a86a4 100644 --- a/src/actions/ens/getEnsResolver.ts +++ b/src/actions/ens/getEnsResolver.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Prettify } from '../../types/utils.js' @@ -11,6 +10,7 @@ import { type ReadContractParameters, readContract, } from '../public/readContract.js' +import type { Chain } from '@viem/chains' export type GetEnsResolverParameters = Prettify< Pick & { diff --git a/src/actions/ens/getEnsText.test.ts b/src/actions/ens/getEnsText.test.ts index 812de3c9b2..c7d178937d 100644 --- a/src/actions/ens/getEnsText.test.ts +++ b/src/actions/ens/getEnsText.test.ts @@ -6,9 +6,9 @@ import { setBlockNumber, setVitalikResolver, } from '../../_test/utils.js' -import { optimism } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' +import { optimism } from '@viem/chains' import { getEnsText } from './getEnsText.js' diff --git a/src/actions/ens/getEnsText.ts b/src/actions/ens/getEnsText.ts index d67b09e8b5..a09c6d97a0 100644 --- a/src/actions/ens/getEnsText.ts +++ b/src/actions/ens/getEnsText.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { @@ -19,6 +18,7 @@ import { type ReadContractParameters, readContract, } from '../public/readContract.js' +import type { Chain } from '@viem/chains' export type GetEnsTextParameters = Prettify< Pick & { diff --git a/src/actions/getContract.test-d.ts b/src/actions/getContract.test-d.ts index 7c056b090c..3d8d11a807 100644 --- a/src/actions/getContract.test-d.ts +++ b/src/actions/getContract.test-d.ts @@ -13,9 +13,9 @@ import { wagmiContractConfig } from '../_test/abis.js' import { localHttpUrl } from '../_test/constants.js' import { anvilChain, publicClient } from '../_test/utils.js' import type { Account } from '../accounts/types.js' -import type { Chain } from '../chains/types.js' import { createWalletClient } from '../clients/createWalletClient.js' import { http } from '../clients/transports/http.js' +import type { Chain } from '@viem/chains' import { getContract } from './getContract.js' diff --git a/src/actions/getContract.ts b/src/actions/getContract.ts index 3ee67ac40d..5adf84229c 100644 --- a/src/actions/getContract.ts +++ b/src/actions/getContract.ts @@ -11,7 +11,6 @@ import type { } from 'abitype' import type { Account } from '../accounts/types.js' -import type { Chain } from '../chains/types.js' import type { PublicClient } from '../clients/createPublicClient.js' import type { WalletClient } from '../clients/createWalletClient.js' import type { Transport } from '../clients/transports/createTransport.js' @@ -27,6 +26,7 @@ import type { Prettify, UnionOmit, } from '../types/utils.js' +import type { Chain } from '@viem/chains' import { type CreateContractEventFilterParameters, diff --git a/src/actions/public/call.test.ts b/src/actions/public/call.test.ts index 58772688ed..0f28a572fd 100644 --- a/src/actions/public/call.test.ts +++ b/src/actions/public/call.test.ts @@ -9,7 +9,6 @@ import { publicClient, publicClientMainnet, } from '../../_test/utils.js' -import { celo, mainnet } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' import { aggregate3Signature } from '../../constants/contract.js' @@ -20,6 +19,7 @@ import { trim } from '../../utils/data/trim.js' import { parseEther } from '../../utils/unit/parseEther.js' import { parseGwei } from '../../utils/unit/parseGwei.js' import { wait } from '../../utils/wait.js' +import { celo, mainnet } from '@viem/chains' import { call, getRevertErrorData } from './call.js' diff --git a/src/actions/public/call.ts b/src/actions/public/call.ts index 7111bb95a0..9c2c9422ca 100644 --- a/src/actions/public/call.ts +++ b/src/actions/public/call.ts @@ -2,7 +2,6 @@ import type { Address } from 'abitype' import type { Account } from '../../accounts/types.js' import { parseAccount } from '../../accounts/utils/parseAccount.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { multicall3Abi } from '../../constants/abis.js' @@ -31,6 +30,7 @@ import { import { createBatchScheduler } from '../../utils/promise/createBatchScheduler.js' import { assertRequest } from '../../utils/transaction/assertRequest.js' import type { AssertRequestParameters } from '../../utils/transaction/assertRequest.js' +import type { Chain } from '@viem/chains' export type FormattedCall< TChain extends Chain | undefined = Chain | undefined, diff --git a/src/actions/public/createBlockFilter.ts b/src/actions/public/createBlockFilter.ts index cb7b9ffbbb..fe7232aab2 100644 --- a/src/actions/public/createBlockFilter.ts +++ b/src/actions/public/createBlockFilter.ts @@ -1,8 +1,8 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Filter } from '../../types/filter.js' import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js' +import type { Chain } from '@viem/chains' export type CreateBlockFilterReturnType = Filter<'block'> diff --git a/src/actions/public/createContractEventFilter.ts b/src/actions/public/createContractEventFilter.ts index 46d2fcaf14..30c68d4017 100644 --- a/src/actions/public/createContractEventFilter.ts +++ b/src/actions/public/createContractEventFilter.ts @@ -1,6 +1,5 @@ import type { Abi, Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockNumber, BlockTag } from '../../types/block.js' @@ -16,6 +15,7 @@ import { } from '../../utils/abi/encodeEventTopics.js' import { numberToHex } from '../../utils/encoding/toHex.js' import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js' +import type { Chain } from '@viem/chains' export type CreateContractEventFilterParameters< TAbi extends Abi | readonly unknown[] = Abi, diff --git a/src/actions/public/createEventFilter.ts b/src/actions/public/createEventFilter.ts index a2759a6c94..dfd308be0a 100644 --- a/src/actions/public/createEventFilter.ts +++ b/src/actions/public/createEventFilter.ts @@ -1,6 +1,5 @@ import type { AbiEvent, Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockNumber, BlockTag } from '../../types/block.js' @@ -17,6 +16,7 @@ import { } from '../../utils/abi/encodeEventTopics.js' import { numberToHex } from '../../utils/encoding/toHex.js' import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js' +import type { Chain } from '@viem/chains' export type CreateEventFilterParameters< TAbiEvent extends AbiEvent | undefined = undefined, diff --git a/src/actions/public/createPendingTransactionFilter.ts b/src/actions/public/createPendingTransactionFilter.ts index 7402339a1a..3524d37e73 100644 --- a/src/actions/public/createPendingTransactionFilter.ts +++ b/src/actions/public/createPendingTransactionFilter.ts @@ -1,8 +1,8 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Filter } from '../../types/filter.js' import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js' +import type { Chain } from '@viem/chains' export type CreatePendingTransactionFilterReturnType = Filter<'transaction'> diff --git a/src/actions/public/estimateContractGas.ts b/src/actions/public/estimateContractGas.ts index 962030ab03..85e006a251 100644 --- a/src/actions/public/estimateContractGas.ts +++ b/src/actions/public/estimateContractGas.ts @@ -2,7 +2,6 @@ import type { Abi } from 'abitype' import type { Account } from '../../accounts/types.js' import { parseAccount } from '../../accounts/utils/parseAccount.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BaseError } from '../../errors/base.js' @@ -14,6 +13,7 @@ import { } from '../../utils/abi/encodeFunctionData.js' import { getContractError } from '../../utils/errors/getContractError.js' import { type EstimateGasParameters, estimateGas } from './estimateGas.js' +import type { Chain } from '@viem/chains' export type EstimateContractGasParameters< TAbi extends Abi | readonly unknown[] = Abi, diff --git a/src/actions/public/estimateFeesPerGas.test.ts b/src/actions/public/estimateFeesPerGas.test.ts index 1b24fd3327..2db2ef404e 100644 --- a/src/actions/public/estimateFeesPerGas.test.ts +++ b/src/actions/public/estimateFeesPerGas.test.ts @@ -1,9 +1,9 @@ import { describe, expect, test, vi } from 'vitest' import { anvilChain, publicClient } from '../../_test/utils.js' -import { mainnet } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' +import { mainnet } from '@viem/chains' import { localHttpUrl } from '../../_test/constants.js' import { diff --git a/src/actions/public/estimateFeesPerGas.ts b/src/actions/public/estimateFeesPerGas.ts index b332a367a2..5448f7bfb3 100644 --- a/src/actions/public/estimateFeesPerGas.ts +++ b/src/actions/public/estimateFeesPerGas.ts @@ -1,8 +1,3 @@ -import type { - Chain, - ChainEstimateFeesPerGasFnParameters, - ChainFeesFnParameters, -} from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { @@ -20,6 +15,11 @@ import type { PrepareRequestParameters } from '../../utils/transaction/prepareRe import { internal_estimateMaxPriorityFeePerGas } from './estimateMaxPriorityFeePerGas.js' import { getBlock } from './getBlock.js' import { getGasPrice } from './getGasPrice.js' +import type { + Chain, + ChainEstimateFeesPerGasFnParameters, + ChainFeesFnParameters, +} from '@viem/chains' export type EstimateFeesPerGasParameters< chain extends Chain | undefined = Chain | undefined, diff --git a/src/actions/public/estimateGas.ts b/src/actions/public/estimateGas.ts index 18401637fa..c9cd634ece 100644 --- a/src/actions/public/estimateGas.ts +++ b/src/actions/public/estimateGas.ts @@ -1,6 +1,5 @@ import type { Account } from '../../accounts/types.js' import { parseAccount } from '../../accounts/utils/parseAccount.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { AccountNotFoundError } from '../../errors/account.js' @@ -24,6 +23,7 @@ import { type PrepareRequestParameters, prepareRequest, } from '../../utils/transaction/prepareRequest.js' +import type { Chain } from '@viem/chains' export type FormattedEstimateGas< TChain extends Chain | undefined = Chain | undefined, diff --git a/src/actions/public/estimateMaxPriorityFeePerGas.test.ts b/src/actions/public/estimateMaxPriorityFeePerGas.test.ts index d4bb9355f4..5d024d03a2 100644 --- a/src/actions/public/estimateMaxPriorityFeePerGas.test.ts +++ b/src/actions/public/estimateMaxPriorityFeePerGas.test.ts @@ -2,13 +2,13 @@ import { describe, expect, test, vi } from 'vitest' import { localHttpUrl } from '../../_test/constants.js' import { anvilChain, publicClient } from '../../_test/utils.js' -import { mainnet } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' import { MethodNotSupportedRpcError } from '../../errors/rpc.js' import { buildRequest } from '../../utils/buildRequest.js' import { estimateMaxPriorityFeePerGas } from './estimateMaxPriorityFeePerGas.js' import * as getBlock from './getBlock.js' +import { mainnet } from '@viem/chains' test('default', async () => { expect(await estimateMaxPriorityFeePerGas(publicClient)).toBeDefined() diff --git a/src/actions/public/estimateMaxPriorityFeePerGas.ts b/src/actions/public/estimateMaxPriorityFeePerGas.ts index c0011e0de4..b8bde44d09 100644 --- a/src/actions/public/estimateMaxPriorityFeePerGas.ts +++ b/src/actions/public/estimateMaxPriorityFeePerGas.ts @@ -1,4 +1,3 @@ -import type { Chain, ChainFeesFnParameters } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { Eip1559FeesNotSupportedError } from '../../errors/fee.js' @@ -8,6 +7,7 @@ import { hexToBigInt } from '../../utils/encoding/fromHex.js' import type { PrepareRequestParameters } from '../../utils/transaction/prepareRequest.js' import { getBlock } from './getBlock.js' import { getGasPrice } from './getGasPrice.js' +import type { Chain, ChainFeesFnParameters } from '@viem/chains' export type EstimateMaxPriorityFeePerGasParameters< chain extends Chain | undefined = Chain | undefined, diff --git a/src/actions/public/getBalance.ts b/src/actions/public/getBalance.ts index f2c1a32280..8f1095823f 100644 --- a/src/actions/public/getBalance.ts +++ b/src/actions/public/getBalance.ts @@ -1,10 +1,10 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockTag } from '../../types/block.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type GetBalanceParameters = { /** The address of the account. */ diff --git a/src/actions/public/getBlock.test-d.ts b/src/actions/public/getBlock.test-d.ts index 61d01c9b47..e68dd50de3 100644 --- a/src/actions/public/getBlock.test-d.ts +++ b/src/actions/public/getBlock.test-d.ts @@ -1,11 +1,11 @@ import { describe, expectTypeOf, test } from 'vitest' import { publicClient } from '../../_test/utils.js' -import { optimism } from '../../chains/index.js' import { createPublicClient, http } from '../../index.js' import type { Hash, Hex } from '../../types/misc.js' import type { Transaction } from '../../types/transaction.js' import { getBlock } from './getBlock.js' +import { optimism } from '@viem/chains' test('includeTransactions = false', async () => { const block_1 = await getBlock(publicClient) diff --git a/src/actions/public/getBlock.test.ts b/src/actions/public/getBlock.test.ts index 594a2e3efe..ac45091d5f 100644 --- a/src/actions/public/getBlock.test.ts +++ b/src/actions/public/getBlock.test.ts @@ -3,13 +3,13 @@ import { assertType, describe, expect, test } from 'vitest' import { forkBlockNumber } from '../../_test/constants.js' import { publicClient } from '../../_test/utils.js' -import { celo } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' import type { Block } from '../../types/block.js' import type { Hash, Hex } from '../../types/misc.js' import type { Transaction } from '../../types/transaction.js' import { getBlock } from './getBlock.js' +import { celo } from '@viem/chains' test('gets latest block', async () => { const block = await getBlock(publicClient) diff --git a/src/actions/public/getBlock.ts b/src/actions/public/getBlock.ts index 18db578042..6e8baaf78c 100644 --- a/src/actions/public/getBlock.ts +++ b/src/actions/public/getBlock.ts @@ -1,5 +1,4 @@ import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { BlockNotFoundError } from '../../errors/block.js' @@ -11,6 +10,7 @@ import { type FormattedBlock, formatBlock, } from '../../utils/formatters/block.js' +import type { Chain } from '@viem/chains' export type GetBlockParameters< TIncludeTransactions extends boolean = false, diff --git a/src/actions/public/getBlockNumber.ts b/src/actions/public/getBlockNumber.ts index 0607566c3b..f74ffc3852 100644 --- a/src/actions/public/getBlockNumber.ts +++ b/src/actions/public/getBlockNumber.ts @@ -1,7 +1,7 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { getCache, withCache } from '../../utils/promise/withCache.js' +import type { Chain } from '@viem/chains' export type GetBlockNumberParameters = { /** Time (in ms) that cached block number will remain in memory. */ diff --git a/src/actions/public/getBlockTransactionCount.ts b/src/actions/public/getBlockTransactionCount.ts index 664deec180..6391003974 100644 --- a/src/actions/public/getBlockTransactionCount.ts +++ b/src/actions/public/getBlockTransactionCount.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockTag } from '../../types/block.js' @@ -6,6 +5,7 @@ import type { Hash } from '../../types/misc.js' import type { Quantity } from '../../types/rpc.js' import { hexToNumber } from '../../utils/encoding/fromHex.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type GetBlockTransactionCountParameters = | { diff --git a/src/actions/public/getBytecode.ts b/src/actions/public/getBytecode.ts index ef46701765..08d3f503eb 100644 --- a/src/actions/public/getBytecode.ts +++ b/src/actions/public/getBytecode.ts @@ -1,11 +1,11 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockTag } from '../../types/block.js' import type { Hex } from '../../types/misc.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type GetBytecodeParameters = { address: Address diff --git a/src/actions/public/getChainId.ts b/src/actions/public/getChainId.ts index a96fa35fcb..8aeb423fe7 100644 --- a/src/actions/public/getChainId.ts +++ b/src/actions/public/getChainId.ts @@ -1,8 +1,8 @@ import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { hexToNumber } from '../../utils/encoding/fromHex.js' +import type { Chain } from '@viem/chains' export type GetChainIdReturnType = number diff --git a/src/actions/public/getFeeHistory.ts b/src/actions/public/getFeeHistory.ts index 9a26922909..7bf2867fa7 100644 --- a/src/actions/public/getFeeHistory.ts +++ b/src/actions/public/getFeeHistory.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockTag } from '../../types/block.js' import type { FeeHistory } from '../../types/fee.js' import { numberToHex } from '../../utils/encoding/toHex.js' import { formatFeeHistory } from '../../utils/formatters/feeHistory.js' +import type { Chain } from '@viem/chains' export type GetFeeHistoryParameters = { /** diff --git a/src/actions/public/getFilterChanges.ts b/src/actions/public/getFilterChanges.ts index 942d34b605..8d1422c4e3 100644 --- a/src/actions/public/getFilterChanges.ts +++ b/src/actions/public/getFilterChanges.ts @@ -1,6 +1,5 @@ import type { Abi, AbiEvent, ExtractAbiEvent } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { @@ -13,6 +12,7 @@ import type { Log } from '../../types/log.js' import type { Hash } from '../../types/misc.js' import { decodeEventLog } from '../../utils/abi/decodeEventLog.js' import { formatLog } from '../../utils/formatters/log.js' +import type { Chain } from '@viem/chains' export type GetFilterChangesParameters< TFilterType extends FilterType = FilterType, diff --git a/src/actions/public/getFilterLogs.ts b/src/actions/public/getFilterLogs.ts index 300de1555f..ce145ab7c5 100644 --- a/src/actions/public/getFilterLogs.ts +++ b/src/actions/public/getFilterLogs.ts @@ -1,6 +1,5 @@ import type { Abi, AbiEvent, ExtractAbiEvent } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { @@ -12,6 +11,7 @@ import type { Filter } from '../../types/filter.js' import type { Log } from '../../types/log.js' import { decodeEventLog } from '../../utils/abi/decodeEventLog.js' import { formatLog } from '../../utils/formatters/log.js' +import type { Chain } from '@viem/chains' export type GetFilterLogsParameters< TAbi extends Abi | readonly unknown[] | undefined = undefined, diff --git a/src/actions/public/getGasPrice.ts b/src/actions/public/getGasPrice.ts index a5ba52f113..819cebdd41 100644 --- a/src/actions/public/getGasPrice.ts +++ b/src/actions/public/getGasPrice.ts @@ -1,7 +1,7 @@ import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' +import type { Chain } from '@viem/chains' export type GetGasPriceReturnType = bigint diff --git a/src/actions/public/getLogs.ts b/src/actions/public/getLogs.ts index 0a5a924039..0923dfeced 100644 --- a/src/actions/public/getLogs.ts +++ b/src/actions/public/getLogs.ts @@ -1,6 +1,5 @@ import type { Abi, AbiEvent, Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { @@ -22,6 +21,7 @@ import { } from '../../utils/abi/encodeEventTopics.js' import { numberToHex } from '../../utils/encoding/toHex.js' import { formatLog } from '../../utils/formatters/log.js' +import type { Chain } from '@viem/chains' export type GetLogsParameters< TAbiEvent extends AbiEvent | undefined = undefined, diff --git a/src/actions/public/getStorageAt.ts b/src/actions/public/getStorageAt.ts index f499a9fd59..e05c11826a 100644 --- a/src/actions/public/getStorageAt.ts +++ b/src/actions/public/getStorageAt.ts @@ -1,11 +1,11 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockTag } from '../../types/block.js' import type { Hex } from '../../types/misc.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type GetStorageAtParameters = { address: Address diff --git a/src/actions/public/getTransaction.test-d.ts b/src/actions/public/getTransaction.test-d.ts index 08c6d817a8..9c244fe45a 100644 --- a/src/actions/public/getTransaction.test-d.ts +++ b/src/actions/public/getTransaction.test-d.ts @@ -1,11 +1,11 @@ import { describe, expectTypeOf, test } from 'vitest' import { publicClient } from '../../_test/utils.js' -import { optimism } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' import type { Hex } from '../../types/misc.js' import { getTransaction } from './getTransaction.js' +import { optimism } from '@viem/chains' test('blockTag = "latest"', async () => { const transaction = await getTransaction(publicClient, { diff --git a/src/actions/public/getTransaction.test.ts b/src/actions/public/getTransaction.test.ts index 3073194f6e..62a0f926c6 100644 --- a/src/actions/public/getTransaction.test.ts +++ b/src/actions/public/getTransaction.test.ts @@ -4,7 +4,6 @@ import { assertType, describe, expect, test } from 'vitest' import { accounts, forkBlockNumber } from '../../_test/constants.js' import { publicClient, testClient, walletClient } from '../../_test/utils.js' -import { celo } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' import type { Transaction } from '../../types/transaction.js' @@ -12,6 +11,7 @@ import { parseEther } from '../../utils/unit/parseEther.js' import { mine } from '../test/mine.js' import { setBalance } from '../test/setBalance.js' import { sendTransaction } from '../wallet/sendTransaction.js' +import { celo } from '@viem/chains' import { getBlock } from './getBlock.js' import { getTransaction } from './getTransaction.js' diff --git a/src/actions/public/getTransaction.ts b/src/actions/public/getTransaction.ts index 5a78510513..929825a6ac 100644 --- a/src/actions/public/getTransaction.ts +++ b/src/actions/public/getTransaction.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { TransactionNotFoundError } from '../../errors/transaction.js' @@ -10,6 +9,7 @@ import { type FormattedTransaction, formatTransaction, } from '../../utils/formatters/transaction.js' +import type { Chain } from '@viem/chains' export type GetTransactionParameters = | { diff --git a/src/actions/public/getTransactionConfirmations.ts b/src/actions/public/getTransactionConfirmations.ts index a4ed9079c5..c435e19af5 100644 --- a/src/actions/public/getTransactionConfirmations.ts +++ b/src/actions/public/getTransactionConfirmations.ts @@ -1,8 +1,8 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Hash } from '../../types/misc.js' import type { FormattedTransactionReceipt } from '../../utils/formatters/transactionReceipt.js' +import type { Chain } from '@viem/chains' import { getBlockNumber } from './getBlockNumber.js' import { getTransaction } from './getTransaction.js' diff --git a/src/actions/public/getTransactionCount.ts b/src/actions/public/getTransactionCount.ts index 728579f9c1..dd40213e0c 100644 --- a/src/actions/public/getTransactionCount.ts +++ b/src/actions/public/getTransactionCount.ts @@ -1,12 +1,12 @@ import type { Address } from 'abitype' import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockTag } from '../../types/block.js' import { hexToNumber } from '../../utils/encoding/fromHex.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type GetTransactionCountParameters = { /** The account address. */ diff --git a/src/actions/public/getTransactionReceipt.test.ts b/src/actions/public/getTransactionReceipt.test.ts index f7c4f7c3e4..dd81810899 100644 --- a/src/actions/public/getTransactionReceipt.test.ts +++ b/src/actions/public/getTransactionReceipt.test.ts @@ -4,7 +4,6 @@ import { assertType, describe, expect, it, test } from 'vitest' import { accounts } from '../../_test/constants.js' import { publicClient, testClient, walletClient } from '../../_test/utils.js' -import { celo } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' import type { TransactionReceipt } from '../../types/transaction.js' @@ -12,6 +11,7 @@ import { parseEther } from '../../utils/unit/parseEther.js' import { parseGwei } from '../../utils/unit/parseGwei.js' import { mine } from '../test/mine.js' import { sendTransaction } from '../wallet/sendTransaction.js' +import { celo } from '@viem/chains' import { getBlock } from './getBlock.js' import { getTransaction } from './getTransaction.js' diff --git a/src/actions/public/getTransactionReceipt.ts b/src/actions/public/getTransactionReceipt.ts index 5a4c56d590..5efbcdd343 100644 --- a/src/actions/public/getTransactionReceipt.ts +++ b/src/actions/public/getTransactionReceipt.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { TransactionReceiptNotFoundError } from '../../errors/transaction.js' @@ -7,6 +6,7 @@ import { type FormattedTransactionReceipt, formatTransactionReceipt, } from '../../utils/formatters/transactionReceipt.js' +import type { Chain } from '@viem/chains' export type GetTransactionReceiptParameters = { /** The hash of the transaction. */ diff --git a/src/actions/public/multicall.test.ts b/src/actions/public/multicall.test.ts index 877245d8b3..1c9094d695 100644 --- a/src/actions/public/multicall.test.ts +++ b/src/actions/public/multicall.test.ts @@ -24,10 +24,10 @@ import { deployErrorExample, publicClient, } from '../../_test/utils.js' -import { mainnet } from '../../chains/index.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' import type { Hex } from '../../types/misc.js' +import { mainnet } from '@viem/chains' import { multicall } from './multicall.js' diff --git a/src/actions/public/multicall.ts b/src/actions/public/multicall.ts index 5cd8f2df21..4674c4578f 100644 --- a/src/actions/public/multicall.ts +++ b/src/actions/public/multicall.ts @@ -1,6 +1,5 @@ import type { Address, Narrow } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { multicall3Abi } from '../../constants/abis.js' @@ -20,6 +19,7 @@ import { } from '../../utils/abi/encodeFunctionData.js' import { getChainContractAddress } from '../../utils/chain.js' import { getContractError } from '../../utils/errors/getContractError.js' +import type { Chain } from '@viem/chains' import type { CallParameters } from './call.js' import { readContract } from './readContract.js' diff --git a/src/actions/public/readContract.ts b/src/actions/public/readContract.ts index b793b85fe6..3feb280fd9 100644 --- a/src/actions/public/readContract.ts +++ b/src/actions/public/readContract.ts @@ -1,6 +1,5 @@ import type { Abi } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BaseError } from '../../errors/base.js' @@ -17,6 +16,7 @@ import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js' import { getContractError } from '../../utils/errors/getContractError.js' +import type { Chain } from '@viem/chains' import { type CallParameters, call } from './call.js' diff --git a/src/actions/public/simulateContract.ts b/src/actions/public/simulateContract.ts index 46381698fc..ee520a9fd4 100644 --- a/src/actions/public/simulateContract.ts +++ b/src/actions/public/simulateContract.ts @@ -1,7 +1,6 @@ import type { Abi } from 'abitype' import { parseAccount } from '../../accounts/utils/parseAccount.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BaseError } from '../../errors/base.js' @@ -22,6 +21,7 @@ import { } from '../../utils/abi/encodeFunctionData.js' import { getContractError } from '../../utils/errors/getContractError.js' import type { WriteContractParameters } from '../wallet/writeContract.js' +import type { Chain } from '@viem/chains' import { type CallParameters, call } from './call.js' diff --git a/src/actions/public/uninstallFilter.ts b/src/actions/public/uninstallFilter.ts index 8ad5d67d61..ff0cdb6307 100644 --- a/src/actions/public/uninstallFilter.ts +++ b/src/actions/public/uninstallFilter.ts @@ -1,7 +1,7 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Filter } from '../../types/filter.js' +import type { Chain } from '@viem/chains' export type UninstallFilterParameters = { filter: Filter diff --git a/src/actions/public/verifyHash.ts b/src/actions/public/verifyHash.ts index 70d05d4901..0678e7cee6 100644 --- a/src/actions/public/verifyHash.ts +++ b/src/actions/public/verifyHash.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/index.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { universalSignatureValidatorAbi } from '../../constants/abis.js' @@ -10,6 +9,7 @@ import type { ByteArray, Hex } from '../../types/misc.js' import { isBytesEqual } from '../../utils/data/isBytesEqual.js' import { encodeDeployData, isHex, toHex } from '../../utils/index.js' import { type CallParameters, call } from './call.js' +import type { Chain } from '@viem/chains' export type VerifyHashParameters = Pick< CallParameters, diff --git a/src/actions/public/verifyMessage.ts b/src/actions/public/verifyMessage.ts index 52d81d9dc3..a916652515 100644 --- a/src/actions/public/verifyMessage.ts +++ b/src/actions/public/verifyMessage.ts @@ -1,9 +1,9 @@ -import type { Chain } from '../../chains/index.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { ByteArray, Hex, SignableMessage } from '../../types/misc.js' import { hashMessage } from '../../utils/index.js' import { type VerifyHashParameters, verifyHash } from './verifyHash.js' +import type { Chain } from '@viem/chains' import type { Address } from 'abitype' export type VerifyMessageParameters = Omit & { diff --git a/src/actions/public/verifyTypedData.ts b/src/actions/public/verifyTypedData.ts index 536228a6be..63897abe38 100644 --- a/src/actions/public/verifyTypedData.ts +++ b/src/actions/public/verifyTypedData.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/index.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { ByteArray, Hex } from '../../types/misc.js' import type { TypedDataDefinition } from '../../types/typedData.js' import { hashTypedData } from '../../utils/signature/hashTypedData.js' import { type VerifyHashParameters, verifyHash } from './verifyHash.js' +import type { Chain } from '@viem/chains' import type { Address, TypedData } from 'abitype' export type VerifyTypedDataParameters< diff --git a/src/actions/public/waitForTransactionReceipt.ts b/src/actions/public/waitForTransactionReceipt.ts index e4bf04c719..dac63de4c3 100644 --- a/src/actions/public/waitForTransactionReceipt.ts +++ b/src/actions/public/waitForTransactionReceipt.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { @@ -11,6 +10,7 @@ import type { Transaction } from '../../types/transaction.js' import { observe } from '../../utils/observe.js' import { withRetry } from '../../utils/promise/withRetry.js' import { stringify } from '../../utils/stringify.js' +import type { Chain } from '@viem/chains' import { getBlock } from './getBlock.js' import { diff --git a/src/actions/public/watchBlockNumber.test.ts b/src/actions/public/watchBlockNumber.test.ts index 7cd2037577..6987715795 100644 --- a/src/actions/public/watchBlockNumber.test.ts +++ b/src/actions/public/watchBlockNumber.test.ts @@ -2,7 +2,6 @@ import { beforeAll, describe, expect, test, vi } from 'vitest' import { localHttpUrl } from '../../_test/constants.js' import { publicClient, testClient, webSocketClient } from '../../_test/utils.js' -import { localhost } from '../../chains/index.js' import { type PublicClient, createPublicClient, @@ -11,6 +10,7 @@ import { http } from '../../clients/transports/http.js' import { wait } from '../../utils/wait.js' import { mine } from '../test/mine.js' import { setIntervalMining } from '../test/setIntervalMining.js' +import { localhost } from '@viem/chains' import * as getBlockNumber from './getBlockNumber.js' import { diff --git a/src/actions/public/watchBlockNumber.ts b/src/actions/public/watchBlockNumber.ts index 1f5089ca05..2855ec69b9 100644 --- a/src/actions/public/watchBlockNumber.ts +++ b/src/actions/public/watchBlockNumber.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { GetTransportConfig } from '../../types/transport.js' @@ -6,6 +5,7 @@ import { hexToBigInt } from '../../utils/encoding/fromHex.js' import { observe } from '../../utils/observe.js' import { poll } from '../../utils/poll.js' import { stringify } from '../../utils/stringify.js' +import type { Chain } from '@viem/chains' import { type GetBlockNumberReturnType, diff --git a/src/actions/public/watchBlocks.test.ts b/src/actions/public/watchBlocks.test.ts index 1dc9745ea5..f8c4aafcf5 100644 --- a/src/actions/public/watchBlocks.test.ts +++ b/src/actions/public/watchBlocks.test.ts @@ -7,7 +7,6 @@ import { walletClient, webSocketClient, } from '../../_test/utils.js' -import { type Chain, celo, localhost } from '../../chains/index.js' import { type PublicClient, createPublicClient, @@ -19,6 +18,7 @@ import { wait } from '../../utils/wait.js' import { mine } from '../test/mine.js' import { setIntervalMining } from '../test/setIntervalMining.js' import { sendTransaction } from '../wallet/sendTransaction.js' +import { type Chain, celo, localhost } from '@viem/chains' import * as getBlock from './getBlock.js' import { type OnBlockParameter, watchBlocks } from './watchBlocks.js' diff --git a/src/actions/public/watchBlocks.ts b/src/actions/public/watchBlocks.ts index 157a9fc6b1..b7d533603f 100644 --- a/src/actions/public/watchBlocks.ts +++ b/src/actions/public/watchBlocks.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { BlockTag } from '../../types/block.js' @@ -7,6 +6,7 @@ import { formatBlock } from '../../utils/formatters/block.js' import { observe } from '../../utils/observe.js' import { poll } from '../../utils/poll.js' import { stringify } from '../../utils/stringify.js' +import type { Chain } from '@viem/chains' import { type GetBlockReturnType, getBlock } from './getBlock.js' diff --git a/src/actions/public/watchContractEvent.ts b/src/actions/public/watchContractEvent.ts index f2398eab5b..0aeab78ff9 100644 --- a/src/actions/public/watchContractEvent.ts +++ b/src/actions/public/watchContractEvent.ts @@ -1,6 +1,5 @@ import type { Abi, AbiEvent, Address, ExtractAbiEvent } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { EncodeEventTopicsParameters, LogTopic } from '../../index.js' @@ -8,6 +7,7 @@ import type { GetEventArgs, InferEventName } from '../../types/contract.js' import type { Filter } from '../../types/filter.js' import type { Log } from '../../types/log.js' import type { GetTransportConfig } from '../../types/transport.js' +import type { Chain } from '@viem/chains' import { type GetAbiItemParameters, diff --git a/src/actions/public/watchEvent.ts b/src/actions/public/watchEvent.ts index 968746c484..b4efeeaf4d 100644 --- a/src/actions/public/watchEvent.ts +++ b/src/actions/public/watchEvent.ts @@ -1,6 +1,5 @@ import type { Abi, AbiEvent, Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { @@ -15,6 +14,7 @@ import type { EncodeEventTopicsParameters } from '../../utils/index.js' import { observe } from '../../utils/observe.js' import { poll } from '../../utils/poll.js' import { stringify } from '../../utils/stringify.js' +import type { Chain } from '@viem/chains' import { DecodeLogDataMismatch, diff --git a/src/actions/public/watchPendingTransactions.ts b/src/actions/public/watchPendingTransactions.ts index 47bac99642..74fe7fb3aa 100644 --- a/src/actions/public/watchPendingTransactions.ts +++ b/src/actions/public/watchPendingTransactions.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Filter } from '../../types/filter.js' @@ -7,6 +6,7 @@ import type { GetTransportConfig } from '../../types/transport.js' import { observe } from '../../utils/observe.js' import { poll } from '../../utils/poll.js' import { stringify } from '../../utils/stringify.js' +import type { Chain } from '@viem/chains' import { createPendingTransactionFilter } from './createPendingTransactionFilter.js' import { getFilterChanges } from './getFilterChanges.js' diff --git a/src/actions/test/dropTransaction.ts b/src/actions/test/dropTransaction.ts index 7cb1f770d8..152b5294e7 100644 --- a/src/actions/test/dropTransaction.ts +++ b/src/actions/test/dropTransaction.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import type { Hash } from '../../types/misc.js' +import type { Chain } from '@viem/chains' export type DropTransactionParameters = { /** The hash of the transaction to drop. */ diff --git a/src/actions/test/getAutomine.ts b/src/actions/test/getAutomine.ts index e0e190b037..bf4927bbf5 100644 --- a/src/actions/test/getAutomine.ts +++ b/src/actions/test/getAutomine.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' export type GetAutomineReturnType = boolean diff --git a/src/actions/test/getTxpoolContent.ts b/src/actions/test/getTxpoolContent.ts index 6519cef02f..cf606290bc 100644 --- a/src/actions/test/getTxpoolContent.ts +++ b/src/actions/test/getTxpoolContent.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -8,6 +7,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import type { RpcTransaction } from '../../types/rpc.js' +import type { Chain } from '@viem/chains' export type GetTxpoolContentReturnType = { /** Pending transactions in the pool */ diff --git a/src/actions/test/getTxpoolStatus.ts b/src/actions/test/getTxpoolStatus.ts index 8e96355c81..5a05d00fef 100644 --- a/src/actions/test/getTxpoolStatus.ts +++ b/src/actions/test/getTxpoolStatus.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { hexToNumber } from '../../utils/encoding/fromHex.js' +import type { Chain } from '@viem/chains' export type GetTxpoolStatusReturnType = { pending: number diff --git a/src/actions/test/impersonateAccount.ts b/src/actions/test/impersonateAccount.ts index d1450d855b..41437add76 100644 --- a/src/actions/test/impersonateAccount.ts +++ b/src/actions/test/impersonateAccount.ts @@ -1,12 +1,12 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' export type ImpersonateAccountParameters = { /** The account to impersonate. */ diff --git a/src/actions/test/increaseTime.ts b/src/actions/test/increaseTime.ts index 9881562a52..449110e1ee 100644 --- a/src/actions/test/increaseTime.ts +++ b/src/actions/test/increaseTime.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type IncreaseTimeParameters = { /** The amount of seconds to jump forward in time. */ diff --git a/src/actions/test/inspectTxpool.ts b/src/actions/test/inspectTxpool.ts index a5bb867699..32b44ce793 100644 --- a/src/actions/test/inspectTxpool.ts +++ b/src/actions/test/inspectTxpool.ts @@ -1,12 +1,12 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' export type InspectTxpoolReturnType = { pending: Record> diff --git a/src/actions/test/mine.ts b/src/actions/test/mine.ts index 72b495febd..12c40e84ee 100644 --- a/src/actions/test/mine.ts +++ b/src/actions/test/mine.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type MineParameters = { /** Number of blocks to mine. */ diff --git a/src/actions/test/removeBlockTimestampInterval.ts b/src/actions/test/removeBlockTimestampInterval.ts index e159245ff9..20962a169a 100644 --- a/src/actions/test/removeBlockTimestampInterval.ts +++ b/src/actions/test/removeBlockTimestampInterval.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' /** * Removes [`setBlockTimestampInterval`](https://viem.sh/docs/actions/test/setBlockTimestampInterval.html) if it exists. diff --git a/src/actions/test/reset.ts b/src/actions/test/reset.ts index 8510318bf5..e3d2740009 100644 --- a/src/actions/test/reset.ts +++ b/src/actions/test/reset.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' export type ResetParameters = { /** The block number to reset from. */ diff --git a/src/actions/test/revert.ts b/src/actions/test/revert.ts index 8ca3a37274..1b50b0bee1 100644 --- a/src/actions/test/revert.ts +++ b/src/actions/test/revert.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import type { Quantity } from '../../types/rpc.js' +import type { Chain } from '@viem/chains' export type RevertParameters = { /** The snapshot ID to revert to. */ diff --git a/src/actions/test/sendUnsignedTransaction.test.ts b/src/actions/test/sendUnsignedTransaction.test.ts index 5e5aaa7481..6766c5608e 100644 --- a/src/actions/test/sendUnsignedTransaction.test.ts +++ b/src/actions/test/sendUnsignedTransaction.test.ts @@ -2,11 +2,11 @@ import { expect, test } from 'vitest' import { accounts, address } from '../../_test/constants.js' import { publicClient, testClient } from '../../_test/utils.js' -import { celo } from '../../chains/index.js' import { createTestClient } from '../../clients/createTestClient.js' import { defineChain } from '../../utils/chain.js' import { parseEther } from '../../utils/unit/parseEther.js' import { getBalance } from '../public/getBalance.js' +import { celo } from '@viem/chains' import { http } from '../../index.js' import { mine } from './mine.js' diff --git a/src/actions/test/sendUnsignedTransaction.ts b/src/actions/test/sendUnsignedTransaction.ts index 46cf5ca23e..1094dd880e 100644 --- a/src/actions/test/sendUnsignedTransaction.ts +++ b/src/actions/test/sendUnsignedTransaction.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -12,6 +11,7 @@ import { type FormattedTransactionRequest, formatTransactionRequest, } from '../../utils/formatters/transactionRequest.js' +import type { Chain } from '@viem/chains' export type SendUnsignedTransactionParameters< TChain extends Chain | undefined = Chain | undefined, diff --git a/src/actions/test/setAutomine.ts b/src/actions/test/setAutomine.ts index 364bd90efb..bc0d7e58fc 100644 --- a/src/actions/test/setAutomine.ts +++ b/src/actions/test/setAutomine.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' /** * Enables or disables the automatic mining of new blocks with each new transaction submitted to the network. diff --git a/src/actions/test/setBalance.ts b/src/actions/test/setBalance.ts index 381571af4e..cd04ccb896 100644 --- a/src/actions/test/setBalance.ts +++ b/src/actions/test/setBalance.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -8,6 +7,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SetBalanceParameters = { /** The account address. */ diff --git a/src/actions/test/setBlockGasLimit.ts b/src/actions/test/setBlockGasLimit.ts index 9f234ffd35..719bc5b530 100644 --- a/src/actions/test/setBlockGasLimit.ts +++ b/src/actions/test/setBlockGasLimit.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SetBlockGasLimitParameters = { /** Gas limit (in wei). */ diff --git a/src/actions/test/setBlockTimestampInterval.ts b/src/actions/test/setBlockTimestampInterval.ts index 395c61d596..ae14a9de7e 100644 --- a/src/actions/test/setBlockTimestampInterval.ts +++ b/src/actions/test/setBlockTimestampInterval.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' export type SetBlockTimestampIntervalParameters = { /** The interval (in seconds). */ diff --git a/src/actions/test/setCode.ts b/src/actions/test/setCode.ts index e9ea27de8e..780928a3d3 100644 --- a/src/actions/test/setCode.ts +++ b/src/actions/test/setCode.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -8,6 +7,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import type { Hex } from '../../types/misc.js' +import type { Chain } from '@viem/chains' export type SetCodeParameters = { /** The account address. */ diff --git a/src/actions/test/setCoinbase.ts b/src/actions/test/setCoinbase.ts index b15d5b16a5..2336897a25 100644 --- a/src/actions/test/setCoinbase.ts +++ b/src/actions/test/setCoinbase.ts @@ -1,12 +1,12 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' export type SetCoinbaseParameters = { /** The coinbase address. */ diff --git a/src/actions/test/setIntervalMining.ts b/src/actions/test/setIntervalMining.ts index 90e6d74db9..01e06f9320 100644 --- a/src/actions/test/setIntervalMining.ts +++ b/src/actions/test/setIntervalMining.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' export type SetIntervalMiningParameters = { /** The mining interval. */ diff --git a/src/actions/test/setLoggingEnabled.ts b/src/actions/test/setLoggingEnabled.ts index e577ced268..38dc9e85c9 100644 --- a/src/actions/test/setLoggingEnabled.ts +++ b/src/actions/test/setLoggingEnabled.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' /** * Enable or disable logging on the test node network. diff --git a/src/actions/test/setMinGasPrice.ts b/src/actions/test/setMinGasPrice.ts index 40f1d001eb..45ab2eac15 100644 --- a/src/actions/test/setMinGasPrice.ts +++ b/src/actions/test/setMinGasPrice.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SetMinGasPriceParameters = { /** The gas price. */ diff --git a/src/actions/test/setNextBlockBaseFeePerGas.ts b/src/actions/test/setNextBlockBaseFeePerGas.ts index 2ea415104c..4dcd1c6cb7 100644 --- a/src/actions/test/setNextBlockBaseFeePerGas.ts +++ b/src/actions/test/setNextBlockBaseFeePerGas.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SetNextBlockBaseFeePerGasParameters = { /** Base fee per gas (in wei). */ diff --git a/src/actions/test/setNextBlockTimestamp.ts b/src/actions/test/setNextBlockTimestamp.ts index a1ad73d35b..35cbad71fd 100644 --- a/src/actions/test/setNextBlockTimestamp.ts +++ b/src/actions/test/setNextBlockTimestamp.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -6,6 +5,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SetNextBlockTimestampParameters = { /** The timestamp (in seconds). */ diff --git a/src/actions/test/setNonce.ts b/src/actions/test/setNonce.ts index 7f66e75fa1..4375fb973d 100644 --- a/src/actions/test/setNonce.ts +++ b/src/actions/test/setNonce.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -8,6 +7,7 @@ import type { import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SetNonceParameters = { /** The account address. */ diff --git a/src/actions/test/setRpcUrl.ts b/src/actions/test/setRpcUrl.ts index 3d08b1f698..3984b3d537 100644 --- a/src/actions/test/setRpcUrl.ts +++ b/src/actions/test/setRpcUrl.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' /** * Sets the backend RPC URL. diff --git a/src/actions/test/setStorageAt.ts b/src/actions/test/setStorageAt.ts index 862af249d5..7d8ac8a6d5 100644 --- a/src/actions/test/setStorageAt.ts +++ b/src/actions/test/setStorageAt.ts @@ -1,6 +1,5 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, @@ -9,6 +8,7 @@ import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import type { Hash, Hex } from '../../types/misc.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SetStorageAtParameters = { /** The account address. */ diff --git a/src/actions/test/snapshot.ts b/src/actions/test/snapshot.ts index 48f4ab117a..ef7b5fd9c5 100644 --- a/src/actions/test/snapshot.ts +++ b/src/actions/test/snapshot.ts @@ -1,10 +1,10 @@ -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' /** * Snapshot the state of the blockchain at the current block. diff --git a/src/actions/test/stopImpersonatingAccount.ts b/src/actions/test/stopImpersonatingAccount.ts index dd39875f6f..d6dd761ddd 100644 --- a/src/actions/test/stopImpersonatingAccount.ts +++ b/src/actions/test/stopImpersonatingAccount.ts @@ -1,12 +1,12 @@ import type { Address } from 'abitype' -import type { Chain } from '../../chains/types.js' import type { TestClient, TestClientMode, } from '../../clients/createTestClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' +import type { Chain } from '@viem/chains' export type StopImpersonatingAccountParameters = { /** The account to impersonate. */ diff --git a/src/actions/wallet/addChain.test.ts b/src/actions/wallet/addChain.test.ts index 0c108be9b9..1d0dd4fc20 100644 --- a/src/actions/wallet/addChain.test.ts +++ b/src/actions/wallet/addChain.test.ts @@ -1,7 +1,7 @@ import { test } from 'vitest' import { walletClient } from '../../_test/utils.js' -import { avalanche } from '../../chains/index.js' +import { avalanche } from '@viem/chains' import { addChain } from './addChain.js' diff --git a/src/actions/wallet/addChain.ts b/src/actions/wallet/addChain.ts index dc367c6d6b..e2b98fc470 100644 --- a/src/actions/wallet/addChain.ts +++ b/src/actions/wallet/addChain.ts @@ -1,8 +1,8 @@ import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type AddChainParameters = { /** The chain to add to the wallet. */ diff --git a/src/actions/wallet/deployContract.ts b/src/actions/wallet/deployContract.ts index a7dbe95c06..b5df7e0881 100644 --- a/src/actions/wallet/deployContract.ts +++ b/src/actions/wallet/deployContract.ts @@ -1,7 +1,6 @@ import type { Abi } from 'abitype' import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { GetChain } from '../../types/chain.js' @@ -9,6 +8,7 @@ import type { GetConstructorArgs } from '../../types/contract.js' import type { Hex } from '../../types/misc.js' import type { UnionOmit } from '../../types/utils.js' import { encodeDeployData } from '../../utils/abi/encodeDeployData.js' +import type { Chain } from '@viem/chains' import { type SendTransactionParameters, diff --git a/src/actions/wallet/getAddresses.ts b/src/actions/wallet/getAddresses.ts index 30d983412e..7cdca877d6 100644 --- a/src/actions/wallet/getAddresses.ts +++ b/src/actions/wallet/getAddresses.ts @@ -1,10 +1,10 @@ import type { Address } from 'abitype' import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { checksumAddress } from '../../utils/address/getAddress.js' +import type { Chain } from '@viem/chains' export type GetAddressesReturnType = Address[] diff --git a/src/actions/wallet/getPermissions.ts b/src/actions/wallet/getPermissions.ts index 3cc5a766d6..6f9363e0fc 100644 --- a/src/actions/wallet/getPermissions.ts +++ b/src/actions/wallet/getPermissions.ts @@ -1,8 +1,8 @@ import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { WalletPermission } from '../../types/eip1193.js' +import type { Chain } from '@viem/chains' export type GetPermissionsReturnType = WalletPermission[] diff --git a/src/actions/wallet/requestAddresses.ts b/src/actions/wallet/requestAddresses.ts index d1d8de2fd5..8a158ef049 100644 --- a/src/actions/wallet/requestAddresses.ts +++ b/src/actions/wallet/requestAddresses.ts @@ -1,10 +1,10 @@ import type { Address } from 'abitype' import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { getAddress } from '../../utils/address/getAddress.js' +import type { Chain } from '@viem/chains' export type RequestAddressesReturnType = Address[] diff --git a/src/actions/wallet/requestPermissions.ts b/src/actions/wallet/requestPermissions.ts index 6a7bfd246f..e201e73060 100644 --- a/src/actions/wallet/requestPermissions.ts +++ b/src/actions/wallet/requestPermissions.ts @@ -1,9 +1,9 @@ import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { WalletPermission } from '../../types/eip1193.js' import type { Prettify } from '../../types/utils.js' +import type { Chain } from '@viem/chains' export type RequestPermissionsParameters = Prettify< { diff --git a/src/actions/wallet/sendTransaction.test-d.ts b/src/actions/wallet/sendTransaction.test-d.ts index 5c76cc43d7..3be0d40e1f 100644 --- a/src/actions/wallet/sendTransaction.test-d.ts +++ b/src/actions/wallet/sendTransaction.test-d.ts @@ -5,9 +5,9 @@ import { test } from 'vitest' import { localHttpUrl } from '../../_test/constants.js' import { anvilChain } from '../../_test/utils.js' import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import { createWalletClient } from '../../clients/createWalletClient.js' import { http } from '../../clients/transports/http.js' +import type { Chain } from '@viem/chains' import { sendTransaction } from './sendTransaction.js' diff --git a/src/actions/wallet/sendTransaction.test.ts b/src/actions/wallet/sendTransaction.test.ts index b871d549b9..01e425400e 100644 --- a/src/actions/wallet/sendTransaction.test.ts +++ b/src/actions/wallet/sendTransaction.test.ts @@ -9,7 +9,6 @@ import { walletClientWithAccount, } from '../../_test/utils.js' import { privateKeyToAccount } from '../../accounts/privateKeyToAccount.js' -import { celo, localhost, mainnet, optimism } from '../../chains/index.js' import { createWalletClient } from '../../clients/createWalletClient.js' import { http } from '../../clients/transports/http.js' import { type Hex } from '../../types/misc.js' @@ -28,6 +27,7 @@ import { mine } from '../test/mine.js' import { setBalance } from '../test/setBalance.js' import { setNextBlockBaseFeePerGas } from '../test/setNextBlockBaseFeePerGas.js' import { sendTransaction } from './sendTransaction.js' +import { celo, localhost, mainnet, optimism } from '@viem/chains' const sourceAccount = accounts[0] const targetAccount = accounts[1] diff --git a/src/actions/wallet/sendTransaction.ts b/src/actions/wallet/sendTransaction.ts index 4cebbce233..d6f29b8501 100644 --- a/src/actions/wallet/sendTransaction.ts +++ b/src/actions/wallet/sendTransaction.ts @@ -1,6 +1,5 @@ import type { Account } from '../../accounts/types.js' import { parseAccount } from '../../accounts/utils/parseAccount.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { AccountNotFoundError } from '../../errors/account.js' @@ -26,6 +25,7 @@ import { } from '../../utils/transaction/assertRequest.js' import { prepareRequest } from '../../utils/transaction/prepareRequest.js' import { getChainId } from '../public/getChainId.js' +import type { Chain } from '@viem/chains' export type SendTransactionParameters< TChain extends Chain | undefined = Chain | undefined, diff --git a/src/actions/wallet/signMessage.ts b/src/actions/wallet/signMessage.ts index 5338e00676..8636f0f5f6 100644 --- a/src/actions/wallet/signMessage.ts +++ b/src/actions/wallet/signMessage.ts @@ -1,12 +1,12 @@ import type { Account } from '../../accounts/types.js' import { parseAccount } from '../../accounts/utils/parseAccount.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { AccountNotFoundError } from '../../errors/account.js' import type { GetAccountParameter } from '../../types/account.js' import type { Hex, SignableMessage } from '../../types/misc.js' import { stringToHex, toHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SignMessageParameters< TAccount extends Account | undefined = Account | undefined, diff --git a/src/actions/wallet/signTypedData.ts b/src/actions/wallet/signTypedData.ts index 0f01a5b0a3..dafaf7db23 100644 --- a/src/actions/wallet/signTypedData.ts +++ b/src/actions/wallet/signTypedData.ts @@ -2,7 +2,6 @@ import type { TypedData } from 'abitype' import type { Account } from '../../accounts/types.js' import { parseAccount } from '../../accounts/utils/parseAccount.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { AccountNotFoundError } from '../../errors/account.js' @@ -12,6 +11,7 @@ import type { TypedDataDefinition } from '../../types/typedData.js' import { isHex } from '../../utils/data/isHex.js' import { stringify } from '../../utils/stringify.js' import { validateTypedData } from '../../utils/typedData.js' +import type { Chain } from '@viem/chains' export type SignTypedDataParameters< TTypedData extends TypedData | { [key: string]: unknown } = TypedData, diff --git a/src/actions/wallet/switchChain.test.ts b/src/actions/wallet/switchChain.test.ts index 6c672ee71a..0385564851 100644 --- a/src/actions/wallet/switchChain.test.ts +++ b/src/actions/wallet/switchChain.test.ts @@ -1,7 +1,7 @@ import { expect, test } from 'vitest' import { walletClient } from '../../_test/utils.js' -import { avalanche, fantom } from '../../chains/index.js' +import { avalanche, fantom } from '@viem/chains' import { switchChain } from './switchChain.js' diff --git a/src/actions/wallet/switchChain.ts b/src/actions/wallet/switchChain.ts index 71eb1ce1ad..57a90fb6f0 100644 --- a/src/actions/wallet/switchChain.ts +++ b/src/actions/wallet/switchChain.ts @@ -1,8 +1,8 @@ import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { numberToHex } from '../../utils/encoding/toHex.js' +import type { Chain } from '@viem/chains' export type SwitchChainParameters = { /** ID of Chain to switch to */ diff --git a/src/actions/wallet/watchAsset.ts b/src/actions/wallet/watchAsset.ts index b5ef964bc2..5f16cc28aa 100644 --- a/src/actions/wallet/watchAsset.ts +++ b/src/actions/wallet/watchAsset.ts @@ -1,8 +1,8 @@ import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { WatchAssetParams } from '../../types/eip1193.js' +import type { Chain } from '@viem/chains' export type WatchAssetParameters = WatchAssetParams export type WatchAssetReturnType = boolean diff --git a/src/actions/wallet/writeContract.test.ts b/src/actions/wallet/writeContract.test.ts index d0e2a4ecc9..e8c99b0458 100644 --- a/src/actions/wallet/writeContract.test.ts +++ b/src/actions/wallet/writeContract.test.ts @@ -11,12 +11,12 @@ import { walletClient, walletClientWithAccount, } from '../../_test/utils.js' -import { optimism } from '../../chains/index.js' import { createWalletClient } from '../../clients/createWalletClient.js' import { http } from '../../clients/transports/http.js' import { getTransaction } from '../public/getTransaction.js' import { simulateContract } from '../public/simulateContract.js' import { mine } from '../test/mine.js' +import { optimism } from '@viem/chains' import * as sendTransaction from './sendTransaction.js' import { writeContract } from './writeContract.js' diff --git a/src/actions/wallet/writeContract.ts b/src/actions/wallet/writeContract.ts index 55bde9e544..44a44a3846 100644 --- a/src/actions/wallet/writeContract.ts +++ b/src/actions/wallet/writeContract.ts @@ -1,7 +1,6 @@ import type { Abi } from 'abitype' import type { Account } from '../../accounts/types.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { GetAccountParameter } from '../../types/account.js' @@ -19,6 +18,7 @@ import { type SendTransactionReturnType, sendTransaction, } from './sendTransaction.js' +import type { Chain } from '@viem/chains' export type WriteContractParameters< TAbi extends Abi | readonly unknown[] = Abi, diff --git a/src/chains/celo/formatters.test-d.ts b/src/chains/celo/formatters.test-d.ts deleted file mode 100644 index 8be16d89b8..0000000000 --- a/src/chains/celo/formatters.test-d.ts +++ /dev/null @@ -1,312 +0,0 @@ -import { describe, expectTypeOf, test } from 'vitest' - -import { getBlock } from '../../actions/public/getBlock.js' -import { getTransaction } from '../../actions/public/getTransaction.js' -import { getTransactionReceipt } from '../../actions/public/getTransactionReceipt.js' -import { createPublicClient } from '../../clients/createPublicClient.js' -import { createWalletClient } from '../../clients/createWalletClient.js' -import { http } from '../../clients/transports/http.js' -import type { Hash } from '../../types/misc.js' -import type { - RpcBlock, - RpcTransaction, - RpcTransactionReceipt, -} from '../../types/rpc.js' -import type { TransactionRequest } from '../../types/transaction.js' -import { sendTransaction } from '../../wallet.js' -import { celo } from '../index.js' -import { formattersCelo } from './formatters.js' - -describe('block', () => { - expectTypeOf(formattersCelo.block.format).parameter(0).toEqualTypeOf< - Partial & { - randomness: { committed: `0x${string}`; revealed: `0x${string}` } - transactions: - | `0x${string}`[] - | (RpcTransaction & { - feeCurrency: `0x${string}` | null - gatewayFee: `0x${string}` | null - gatewayFeeRecipient: `0x${string}` | null - })[] - } - >() - expectTypeOf< - ReturnType['difficulty'] - >().toEqualTypeOf() - expectTypeOf< - ReturnType['gasLimit'] - >().toEqualTypeOf() - expectTypeOf< - ReturnType['mixHash'] - >().toEqualTypeOf() - expectTypeOf< - ReturnType['nonce'] - >().toEqualTypeOf() - expectTypeOf< - ReturnType['uncles'] - >().toEqualTypeOf() - expectTypeOf< - ReturnType['randomness'] - >().toEqualTypeOf<{ - committed: `0x${string}` - revealed: `0x${string}` - }>() -}) - -describe('transaction', () => { - expectTypeOf(formattersCelo.transaction.format).parameter(0).toEqualTypeOf< - Partial & { - feeCurrency: `0x${string}` | null - gatewayFee: `0x${string}` | null - gatewayFeeRecipient: `0x${string}` | null - } - >() - expectTypeOf< - ReturnType['feeCurrency'] - >().toEqualTypeOf<`0x${string}` | null>() - expectTypeOf< - ReturnType['gatewayFee'] - >().toEqualTypeOf() - expectTypeOf< - ReturnType['gatewayFeeRecipient'] - >().toEqualTypeOf<`0x${string}` | null>() -}) - -describe('transactionReceipt', () => { - expectTypeOf(formattersCelo.transactionReceipt.format) - .parameter(0) - .toEqualTypeOf< - Partial & { - feeCurrency: `0x${string}` | null - gatewayFee: `0x${string}` | null - gatewayFeeRecipient: `0x${string}` | null - } - >() - expectTypeOf< - ReturnType['feeCurrency'] - >().toEqualTypeOf<`0x${string}` | null>() - expectTypeOf< - ReturnType['gatewayFee'] - >().toEqualTypeOf() - expectTypeOf< - ReturnType< - typeof formattersCelo.transactionReceipt.format - >['gatewayFeeRecipient'] - >().toEqualTypeOf<`0x${string}` | null>() -}) - -describe('transactionRequest', () => { - expectTypeOf(formattersCelo.transactionRequest.format) - .parameter(0) - .toEqualTypeOf< - Partial & { - feeCurrency?: `0x${string}` | undefined - gatewayFee?: bigint | undefined - gatewayFeeRecipient?: `0x${string}` | undefined - } - >() - expectTypeOf< - ReturnType['feeCurrency'] - >().toEqualTypeOf<`0x${string}` | undefined>() - expectTypeOf< - ReturnType['gatewayFee'] - >().toEqualTypeOf<`0x${string}` | undefined>() - expectTypeOf< - ReturnType< - typeof formattersCelo.transactionRequest.format - >['gatewayFeeRecipient'] - >().toEqualTypeOf<`0x${string}` | undefined>() -}) - -describe('smoke', () => { - test('block', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - const block = await getBlock(client, { - blockNumber: 16645775n, - }) - - expectTypeOf(block.difficulty).toEqualTypeOf() - expectTypeOf(block.gasLimit).toEqualTypeOf() - expectTypeOf(block.mixHash).toEqualTypeOf() - expectTypeOf(block.nonce).toEqualTypeOf() - expectTypeOf(block.uncles).toEqualTypeOf() - expectTypeOf(block.randomness).toEqualTypeOf<{ - committed: `0x${string}` - revealed: `0x${string}` - }>() - expectTypeOf(block.transactions).toEqualTypeOf() - - const block_includeTransactions = await getBlock(client, { - blockNumber: 16645775n, - includeTransactions: true, - }) - expectTypeOf( - block_includeTransactions.transactions[0].feeCurrency, - ).toEqualTypeOf<`0x${string}` | null>() - expectTypeOf( - block_includeTransactions.transactions[0].gatewayFee, - ).toEqualTypeOf() - expectTypeOf( - block_includeTransactions.transactions[0].gatewayFeeRecipient, - ).toEqualTypeOf<`0x${string}` | null>() - - const block_pending = await getBlock(client, { - blockTag: 'pending', - includeTransactions: true, - }) - expectTypeOf(block_pending.hash).toEqualTypeOf() - expectTypeOf(block_pending.logsBloom).toEqualTypeOf() - expectTypeOf(block_pending.number).toEqualTypeOf() - expectTypeOf(block_pending.transactions[0].blockHash).toEqualTypeOf() - expectTypeOf( - block_pending.transactions[0].blockNumber, - ).toEqualTypeOf() - expectTypeOf( - block_pending.transactions[0].transactionIndex, - ).toEqualTypeOf() - }) - - test('transaction', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - - const transaction = await getTransaction(client, { - blockNumber: 16628100n, - index: 0, - }) - - expectTypeOf(transaction.feeCurrency).toEqualTypeOf<`0x${string}` | null>() - expectTypeOf(transaction.gatewayFee).toEqualTypeOf() - expectTypeOf(transaction.gatewayFeeRecipient).toEqualTypeOf< - `0x${string}` | null - >() - }) - - test('transactionReceipt', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - - const transaction = await getTransactionReceipt(client, { - hash: '0x', - }) - - expectTypeOf(transaction.feeCurrency).toEqualTypeOf<`0x${string}` | null>() - expectTypeOf(transaction.gatewayFee).toEqualTypeOf() - expectTypeOf(transaction.gatewayFeeRecipient).toEqualTypeOf< - `0x${string}` | null - >() - }) - - test('transactionRequest', async () => { - const client = createWalletClient({ - account: '0x', - chain: celo, - transport: http(), - }) - - sendTransaction(client, { - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - }) - - // @ts-expect-error `gasPrice` is not defined - sendTransaction(client, { - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - gasPrice: 0n, - maxFeePerGas: 0n, - maxPriorityFeePerGas: 0n, - }) - - // @ts-expect-error `gasPrice` is not defined - sendTransaction(client, { - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - gasPrice: 0n, - type: 'eip1559', - }) - - // @ts-expect-error `type` cannot be "legacy" - sendTransaction(client, { - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - maxFeePerGas: 0n, - type: 'legacy', - }) - - // @ts-expect-error `type` cannot be "eip2930" - sendTransaction(client, { - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - maxFeePerGas: 0n, - type: 'eip2930', - }) - }) - - test('transactionRequest (chain on action)', async () => { - const client = createWalletClient({ - account: '0x', - transport: http(), - }) - - sendTransaction(client, { - chain: celo, - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - }) - - // @ts-expect-error `gasPrice` is not defined - sendTransaction(client, { - chain: celo, - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - gasPrice: 0n, - maxFeePerGas: 0n, - maxPriorityFeePerGas: 0n, - }) - - // @ts-expect-error `gasPrice` is not defined - sendTransaction(client, { - chain: celo, - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - gasPrice: 0n, - type: 'eip1559', - }) - - // @ts-expect-error `type` cannot be "legacy" - sendTransaction(client, { - chain: celo, - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - maxFeePerGas: 0n, - type: 'legacy', - }) - - // @ts-expect-error `type` cannot be "eip2930" - sendTransaction(client, { - chain: celo, - feeCurrency: '0x', - gatewayFee: 0n, - gatewayFeeRecipient: '0x', - maxFeePerGas: 0n, - type: 'eip2930', - }) - }) -}) diff --git a/src/chains/celo/formatters.test.ts b/src/chains/celo/formatters.test.ts deleted file mode 100644 index 9b00272f9b..0000000000 --- a/src/chains/celo/formatters.test.ts +++ /dev/null @@ -1,810 +0,0 @@ -import { describe, expect, test } from 'vitest' - -import { getBlock } from '../../actions/public/getBlock.js' -import { getTransaction } from '../../actions/public/getTransaction.js' -import { getTransactionReceipt } from '../../actions/public/getTransactionReceipt.js' -import { createPublicClient } from '../../clients/createPublicClient.js' -import { http } from '../../clients/transports/http.js' -import { celo } from '../index.js' - -describe('block', () => { - test('formatter', () => { - const { block } = celo.formatters! - - expect( - block.format({ - baseFeePerGas: '0x0', - extraData: - '0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080', - gasUsed: '0x1', - hash: '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', - logsBloom: - '0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000', - miner: '0xe267d978037b89db06c6a5fcf82fad8297e290ff', - number: '0x2', - parentHash: - '0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed', - randomness: { - committed: - '0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711', - revealed: - '0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88', - }, - receiptsRoot: - '0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a', - size: '0x3', - stateRoot: - '0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48', - timestamp: '0x4', - totalDifficulty: '0x5', - transactions: [ - '0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85', - ], - transactionsRoot: - '0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866', - }), - ).toMatchInlineSnapshot(` - { - "baseFeePerGas": 0n, - "extraData": "0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080", - "gasUsed": 1n, - "hash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "logsBloom": "0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000", - "miner": "0xe267d978037b89db06c6a5fcf82fad8297e290ff", - "number": 2n, - "parentHash": "0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed", - "randomness": { - "committed": "0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711", - "revealed": "0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88", - }, - "receiptsRoot": "0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a", - "size": 3n, - "stateRoot": "0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48", - "timestamp": 4n, - "totalDifficulty": 5n, - "transactions": [ - "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", - ], - "transactionsRoot": "0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866", - } - `) - - expect( - block.format({ - baseFeePerGas: '0x0', - extraData: - '0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080', - gasUsed: '0x1', - hash: '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', - logsBloom: - '0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000', - miner: '0xe267d978037b89db06c6a5fcf82fad8297e290ff', - number: '0x2', - parentHash: - '0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed', - randomness: { - committed: - '0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711', - revealed: - '0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88', - }, - receiptsRoot: - '0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a', - size: '0x3', - stateRoot: - '0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48', - timestamp: '0x4', - totalDifficulty: '0x5', - transactions: [ - { - accessList: [], - blockHash: - '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', - blockNumber: '0x1', - chainId: '0x1', - feeCurrency: null, - from: '0x045d685d23e8aa34dc408a66fb408f20dc84d785', - gas: '0x69420', - maxFeePerGas: '0x0', - maxPriorityFeePerGas: '0x0', - gatewayFee: '0x0', - gatewayFeeRecipient: null, - hash: '0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85', - input: '0x389ec778', - nonce: '0x1', - r: '0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0', - s: '0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774', - to: '0xb86d682b1b6bf20d8d54f55c48f848b9487dec37', - transactionIndex: '0x0', - type: '0x2', - v: '0x0', - value: '0x0', - }, - { - accessList: [], - blockHash: - '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', - blockNumber: '0x1', - chainId: '0x1', - feeCurrency: null, - from: '0x045d685d23e8aa34dc408a66fb408f20dc84d785', - gas: '0x69420', - maxFeePerGas: '0x0', - maxPriorityFeePerGas: '0x0', - gatewayFee: null, - gatewayFeeRecipient: null, - hash: '0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85', - input: '0x389ec778', - nonce: '0x1', - r: '0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0', - s: '0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774', - to: '0xb86d682b1b6bf20d8d54f55c48f848b9487dec37', - transactionIndex: '0x0', - type: '0x2', - v: '0x0', - value: '0x0', - }, - ], - transactionsRoot: - '0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866', - }), - ).toMatchInlineSnapshot(` - { - "baseFeePerGas": 0n, - "extraData": "0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080", - "gasUsed": 1n, - "hash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "logsBloom": "0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000", - "miner": "0xe267d978037b89db06c6a5fcf82fad8297e290ff", - "number": 2n, - "parentHash": "0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed", - "randomness": { - "committed": "0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711", - "revealed": "0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88", - }, - "receiptsRoot": "0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a", - "size": 3n, - "stateRoot": "0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48", - "timestamp": 4n, - "totalDifficulty": 5n, - "transactions": [ - { - "accessList": [], - "blockHash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "blockNumber": 1n, - "chainId": 1, - "feeCurrency": null, - "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", - "gas": 431136n, - "gasPrice": undefined, - "gatewayFee": 0n, - "gatewayFeeRecipient": null, - "hash": "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", - "input": "0x389ec778", - "maxFeePerGas": 0n, - "maxPriorityFeePerGas": 0n, - "nonce": 1, - "r": "0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0", - "s": "0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774", - "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", - "transactionIndex": 0, - "type": "eip1559", - "typeHex": "0x2", - "v": 0n, - "value": 0n, - }, - { - "accessList": [], - "blockHash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "blockNumber": 1n, - "chainId": 1, - "feeCurrency": null, - "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", - "gas": 431136n, - "gasPrice": undefined, - "gatewayFee": null, - "gatewayFeeRecipient": null, - "hash": "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", - "input": "0x389ec778", - "maxFeePerGas": 0n, - "maxPriorityFeePerGas": 0n, - "nonce": 1, - "r": "0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0", - "s": "0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774", - "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", - "transactionIndex": 0, - "type": "eip1559", - "typeHex": "0x2", - "v": 0n, - "value": 0n, - }, - ], - "transactionsRoot": "0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866", - } - `) - }) - - test('action', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - - const block = await getBlock(client, { - blockNumber: 16645775n, - includeTransactions: true, - }) - - const { extraData: _extraData, transactions, ...rest } = block - expect(transactions[0]).toMatchInlineSnapshot(` - { - "blockHash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "blockNumber": 16645775n, - "chainId": undefined, - "ethCompatible": false, - "feeCurrency": null, - "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", - "gas": 1527520n, - "gasPrice": 562129081n, - "gatewayFee": 0n, - "gatewayFeeRecipient": null, - "hash": "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", - "input": "0x389ec778", - "nonce": 714820, - "r": "0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0", - "s": "0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774", - "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", - "transactionIndex": 0, - "type": "legacy", - "typeHex": "0x0", - "v": 84476n, - "value": 0n, - } - `) - expect(rest).toMatchInlineSnapshot(` - { - "baseFeePerGas": null, - "epochSnarkData": null, - "gasUsed": 5045322n, - "hash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "logsBloom": "0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000", - "miner": "0xe267d978037b89db06c6a5fcf82fad8297e290ff", - "number": 16645775n, - "parentHash": "0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed", - "randomness": { - "committed": "0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711", - "revealed": "0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88", - }, - "receiptsRoot": "0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a", - "size": 24562n, - "stateRoot": "0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48", - "timestamp": 1670896907n, - "totalDifficulty": 16645776n, - "transactionsRoot": "0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866", - } - `) - }) -}) - -describe('transaction', () => { - test('formatter', () => { - const { transaction } = celo.formatters! - - expect( - transaction.format({ - accessList: [], - blockHash: - '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', - blockNumber: '0x1', - chainId: '0x1', - feeCurrency: null, - from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - gas: '0x2', - gasPrice: undefined, - gatewayFee: '0x3', - gatewayFeeRecipient: null, - hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', - input: - '0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0', - maxFeePerGas: '0x4', - maxPriorityFeePerGas: '0x5', - nonce: '0x6', - r: '0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca', - s: '0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0', - to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', - transactionIndex: '0x7', - type: '0x2', - v: '0x1', - value: '0x0', - }), - ).toMatchInlineSnapshot(` - { - "accessList": [], - "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", - "blockNumber": 1n, - "chainId": 1, - "feeCurrency": null, - "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "gas": 2n, - "gasPrice": undefined, - "gatewayFee": 3n, - "gatewayFeeRecipient": null, - "hash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", - "input": "0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0", - "maxFeePerGas": 4n, - "maxPriorityFeePerGas": 5n, - "nonce": 6, - "r": "0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca", - "s": "0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0", - "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", - "transactionIndex": 7, - "type": "eip1559", - "typeHex": "0x2", - "v": 1n, - "value": 0n, - } - `) - - expect( - transaction.format({ - accessList: [], - blockHash: - '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', - blockNumber: '0x1', - chainId: '0x1', - feeCurrency: null, - from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - gas: '0x2', - gasPrice: undefined, - gatewayFee: null, - gatewayFeeRecipient: null, - hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', - input: - '0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0', - maxFeePerGas: '0x4', - maxPriorityFeePerGas: '0x5', - nonce: '0x6', - r: '0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca', - s: '0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0', - to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', - transactionIndex: '0x7', - type: '0x2', - v: '0x1', - value: '0x0', - }), - ).toMatchInlineSnapshot(` - { - "accessList": [], - "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", - "blockNumber": 1n, - "chainId": 1, - "feeCurrency": null, - "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "gas": 2n, - "gasPrice": undefined, - "gatewayFee": null, - "gatewayFeeRecipient": null, - "hash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", - "input": "0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0", - "maxFeePerGas": 4n, - "maxPriorityFeePerGas": 5n, - "nonce": 6, - "r": "0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca", - "s": "0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0", - "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", - "transactionIndex": 7, - "type": "eip1559", - "typeHex": "0x2", - "v": 1n, - "value": 0n, - } - `) - }) - - test('action', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - - const transaction = await getTransaction(client, { - blockNumber: 16628100n, - index: 0, - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "chainId": undefined, - "ethCompatible": false, - "feeCurrency": null, - "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", - "gas": 1527520n, - "gasPrice": 2999683966n, - "gatewayFee": 0n, - "gatewayFeeRecipient": null, - "hash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "input": "0x389ec778", - "nonce": 697201, - "r": "0xf507fb8fa33ffd05a7f26c980bbb8271aa113affc8f192feba87abe26549bda1", - "s": "0x7971c7b15ab4475ce6256da0bdf62ca1d1e491be8a03fe7637289f98c166f521", - "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", - "transactionIndex": 0, - "type": "legacy", - "typeHex": "0x0", - "v": 84475n, - "value": 0n, - } - `) - }) -}) - -describe('transactionReceipt', () => { - test('formatter', () => { - const { transactionReceipt } = celo.formatters! - expect( - transactionReceipt.format({ - blockHash: - '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', - blockNumber: '0x1', - contractAddress: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - cumulativeGasUsed: '0x2', - effectiveGasPrice: '0x3', - feeCurrency: null, - from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - gasUsed: '0x4', - gatewayFee: null, - gatewayFeeRecipient: null, - logs: [], - to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', - status: '0x0', - type: '0x0', - }), - ).toMatchInlineSnapshot(` - { - "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", - "blockNumber": 1n, - "contractAddress": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "cumulativeGasUsed": 2n, - "effectiveGasPrice": 3n, - "feeCurrency": null, - "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "gasUsed": 4n, - "gatewayFee": null, - "gatewayFeeRecipient": null, - "logs": [], - "status": "reverted", - "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", - "transactionIndex": null, - "type": "legacy", - } - `) - - expect( - transactionReceipt.format({ - blockHash: - '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', - blockNumber: '0x1', - contractAddress: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - cumulativeGasUsed: '0x2', - effectiveGasPrice: '0x3', - feeCurrency: null, - from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - gasUsed: '0x4', - gatewayFee: '0x123', - gatewayFeeRecipient: null, - logs: [], - to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', - status: '0x0', - type: '0x0', - }), - ).toMatchInlineSnapshot(` - { - "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", - "blockNumber": 1n, - "contractAddress": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "cumulativeGasUsed": 2n, - "effectiveGasPrice": 3n, - "feeCurrency": null, - "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "gasUsed": 4n, - "gatewayFee": 291n, - "gatewayFeeRecipient": null, - "logs": [], - "status": "reverted", - "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", - "transactionIndex": null, - "type": "legacy", - } - `) - }) - - test('action', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - - const transaction = await getTransactionReceipt(client, { - hash: '0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17', - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "contractAddress": null, - "cumulativeGasUsed": 490857n, - "effectiveGasPrice": 2999683966n, - "feeCurrency": undefined, - "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", - "gasUsed": 490857n, - "gatewayFee": null, - "gatewayFeeRecipient": undefined, - "logs": [ - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000004be9c24a9467d0000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", - "logIndex": 0, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000004be9c24a9467d", - "logIndex": 1, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0xe273ad7ee11dcfaa87383ad5977ee1504ac07568", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x000000000000000000000000000000000000000000000000000051069a5460020000000000000000000000000000000000000000033267b28d9c01bb6124f934", - "logIndex": 2, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0xe273ad7ee11dcfaa87383ad5977ee1504ac07568", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x000000000000000000000000000000000000000000000000000051069a546002", - "logIndex": 3, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x471ece3750da237f93b8e339c536989b8978a438", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000000000000000000", - "logIndex": 4, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000002950b4b3a43b40000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", - "logIndex": 5, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000002950b4b3a43b4", - "logIndex": 6, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x122013fd7df1c6f636a5bb8f03108e876548b455", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000000000000000000", - "logIndex": 7, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x00000000000000000000000000000000000000000000000000024144eaf931230000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", - "logIndex": 8, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x00000000000000000000000000000000000000000000000000024144eaf93123", - "logIndex": 9, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x02de4766c272abc10bc88c220d214a26960a7e92", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000000000000000000", - "logIndex": 10, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x000000000000000000000000000000000000000000000000000121f3877515ea0000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", - "logIndex": 11, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x000000000000000000000000000000000000000000000000000121f3877515ea", - "logIndex": 12, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - ], - "logsBloom": "0x00004000004000000000000000800000000000000000400002000000002000000000800000000000000180000001000000000000000000000000000000000000000000000000000020000008000800000000000000000000000000000000000000000000000000000000000040000800000004000000000000000010000800000000000000000000000010000000000000000000000000000000000000000000020000000000000000000000000000002000081000000000000000000000040020800402000000100000000000000000000000000010000010000000000000200010002000000000000000000080000000000000000000000000000004000000", - "status": "success", - "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - "type": "legacy", - } - `) - }) -}) - -describe('transactionRequest', () => { - test('formatter', () => { - const { transactionRequest } = celo.formatters! - - expect( - transactionRequest.format({ - feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - from: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - gas: 1n, - gatewayFee: 4n, - gatewayFeeRecipient: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - maxFeePerGas: 2n, - maxPriorityFeePerGas: 1n, - nonce: 1, - value: 1n, - }), - ).toMatchInlineSnapshot(` - { - "feeCurrency": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "from": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "gas": "0x1", - "gasPrice": undefined, - "gatewayFee": "0x4", - "gatewayFeeRecipient": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "maxFeePerGas": "0x2", - "maxPriorityFeePerGas": "0x1", - "nonce": "0x1", - "value": "0x1", - } - `) - - expect( - transactionRequest.format({ - feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - from: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - gas: 1n, - gatewayFeeRecipient: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - maxFeePerGas: 2n, - maxPriorityFeePerGas: 1n, - nonce: 1, - value: 1n, - }), - ).toMatchInlineSnapshot(` - { - "feeCurrency": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "from": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "gas": "0x1", - "gasPrice": undefined, - "gatewayFee": undefined, - "gatewayFeeRecipient": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "maxFeePerGas": "0x2", - "maxPriorityFeePerGas": "0x1", - "nonce": "0x1", - "value": "0x1", - } - `) - }) -}) diff --git a/src/chains/celo/formatters.ts b/src/chains/celo/formatters.ts deleted file mode 100644 index 73add5590b..0000000000 --- a/src/chains/celo/formatters.ts +++ /dev/null @@ -1,85 +0,0 @@ -import type { Hash } from '../../types/misc.js' -import { hexToBigInt } from '../../utils/encoding/fromHex.js' -import { numberToHex } from '../../utils/encoding/toHex.js' -import { defineBlock } from '../../utils/formatters/block.js' -import { - defineTransaction, - formatTransaction, -} from '../../utils/formatters/transaction.js' -import { defineTransactionReceipt } from '../../utils/formatters/transactionReceipt.js' -import { defineTransactionRequest } from '../../utils/formatters/transactionRequest.js' -import { type ChainFormatters } from '../types.js' -import type { - CeloBlockOverrides, - CeloRpcTransaction, - CeloRpcTransactionOverrides, - CeloRpcTransactionReceiptOverrides, - CeloRpcTransactionRequestOverrides, - CeloTransaction, - CeloTransactionOverrides, - CeloTransactionReceiptOverrides, - CeloTransactionRequestOverrides, -} from './types.js' - -export const formattersCelo = { - block: /*#__PURE__*/ defineBlock({ - exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'], - format( - args: CeloBlockOverrides & { - transactions: Hash[] | CeloRpcTransaction[] - }, - ): CeloBlockOverrides & { - transactions: Hash[] | CeloTransaction[] - } { - const transactions = args.transactions?.map((transaction) => { - if (typeof transaction === 'string') return transaction - return { - ...formatTransaction(transaction), - feeCurrency: transaction.feeCurrency, - gatewayFee: transaction.gatewayFee - ? hexToBigInt(transaction.gatewayFee) - : null, - gatewayFeeRecipient: transaction.gatewayFeeRecipient, - } - }) as Hash[] | CeloTransaction[] - return { - randomness: args.randomness, - transactions, - } - }, - }), - transaction: /*#__PURE__*/ defineTransaction({ - format(args: CeloRpcTransactionOverrides): CeloTransactionOverrides { - return { - feeCurrency: args.feeCurrency, - gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null, - gatewayFeeRecipient: args.gatewayFeeRecipient, - } - }, - }), - transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({ - format( - args: CeloRpcTransactionReceiptOverrides, - ): CeloTransactionReceiptOverrides { - return { - feeCurrency: args.feeCurrency, - gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null, - gatewayFeeRecipient: args.gatewayFeeRecipient, - } - }, - }), - transactionRequest: /*#__PURE__*/ defineTransactionRequest({ - format( - args: CeloTransactionRequestOverrides, - ): CeloRpcTransactionRequestOverrides { - return { - feeCurrency: args.feeCurrency, - gatewayFee: - typeof args.gatewayFee !== 'undefined' - ? numberToHex(args.gatewayFee) - : undefined, - gatewayFeeRecipient: args.gatewayFeeRecipient, - } - }, - }), -} as const satisfies ChainFormatters diff --git a/src/chains/celo/parsers.test.ts b/src/chains/celo/parsers.test.ts deleted file mode 100644 index 4809a91935..0000000000 --- a/src/chains/celo/parsers.test.ts +++ /dev/null @@ -1,222 +0,0 @@ -import { expect, test } from 'vitest' - -import { accounts } from '../../_test/constants.js' -import { - parseEther, - parseGwei, - parseTransaction as parseTransaction_, - serializeTransaction, - toRlp, -} from '../../index.js' -import { parseTransactionCelo } from './parsers.js' -import { serializeTransactionCelo } from './serializers.js' -import type { TransactionSerializableCIP42 } from './types.js' - -test('should be able to parse a cip42 transaction', () => { - const signedTransaction = - '0x7cf84682a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0' - - expect(parseTransactionCelo(signedTransaction)).toMatchInlineSnapshot(` - { - "chainId": 42220, - "feeCurrency": "0x765de816845861e75a25fca122bb6898b8b1282a", - "maxFeePerGas": 2000000000n, - "maxPriorityFeePerGas": 2000000000n, - "to": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", - "type": "cip42", - "value": 1000000000000000000n, - } - `) -}) - -const transaction = { - chainId: 1, - gas: 21001n, - maxFeePerGas: parseGwei('2'), - maxPriorityFeePerGas: parseGwei('2'), - to: accounts[3].address, - nonce: 785, - value: parseEther('1'), -} - -test('should return same result as standard parser when not CIP42', () => { - const serialized = serializeTransaction(transaction) - - expect(parseTransactionCelo(serialized)).toEqual( - parseTransaction_(serialized), - ) -}) - -test('should parse a CIP42 transaction with gatewayFee', () => { - const transactionWithGatewayFee = { - ...transaction, - chainId: 42270, - gatewayFee: parseEther('0.1'), - gatewayFeeRecipient: accounts[1].address, - } - - const serialized = serializeTransactionCelo(transactionWithGatewayFee) - - expect(parseTransactionCelo(serialized)).toMatchInlineSnapshot(` - { - "chainId": 42270, - "gas": 21001n, - "gatewayFee": 100000000000000000n, - "gatewayFeeRecipient": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", - "maxFeePerGas": 2000000000n, - "maxPriorityFeePerGas": 2000000000n, - "nonce": 785, - "to": "0x90f79bf6eb2c4f870365e785982e1f101e93b906", - "type": "cip42", - "value": 1000000000000000000n, - } - `) -}) - -test('should parse a CIP42 transaction with access list', () => { - const transactionWithAccessList: TransactionSerializableCIP42 = { - feeCurrency: '0x765de816845861e75a25fca122bb6898b8b1282a', - ...transaction, - chainId: 42270, - accessList: [ - { - address: '0x0000000000000000000000000000000000000000', - storageKeys: [ - '0x0000000000000000000000000000000000000000000000000000000000000001', - '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - ], - }, - ], - } - - const serialized = serializeTransactionCelo(transactionWithAccessList) - - expect(parseTransactionCelo(serialized)).toMatchInlineSnapshot(` - { - "accessList": [ - { - "address": "0x0000000000000000000000000000000000000000", - "storageKeys": [ - "0x0000000000000000000000000000000000000000000000000000000000000001", - "0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe", - ], - }, - ], - "chainId": 42270, - "feeCurrency": "0x765de816845861e75a25fca122bb6898b8b1282a", - "gas": 21001n, - "maxFeePerGas": 2000000000n, - "maxPriorityFeePerGas": 2000000000n, - "nonce": 785, - "to": "0x90f79bf6eb2c4f870365e785982e1f101e93b906", - "type": "cip42", - "value": 1000000000000000000n, - } - `) -}) - -test('should parse a CIP42 transaction with data as 0x', () => { - const transactionWithData: TransactionSerializableCIP42 = { - feeCurrency: '0x765de816845861e75a25fca122bb6898b8b1282a', - ...transaction, - chainId: 42270, - data: '0x', - } - - const serialized = serializeTransactionCelo(transactionWithData) - - expect(parseTransactionCelo(serialized)).toMatchInlineSnapshot(` - { - "chainId": 42270, - "feeCurrency": "0x765de816845861e75a25fca122bb6898b8b1282a", - "gas": 21001n, - "maxFeePerGas": 2000000000n, - "maxPriorityFeePerGas": 2000000000n, - "nonce": 785, - "to": "0x90f79bf6eb2c4f870365e785982e1f101e93b906", - "type": "cip42", - "value": 1000000000000000000n, - } - `) -}) - -test('should parse a CIP42 transaction with data', () => { - const transactionWithData: TransactionSerializableCIP42 = { - ...transaction, - feeCurrency: '0x765de816845861e75a25fca122bb6898b8b1282a', - chainId: 42270, - data: '0x1234', - } - - const serialized = serializeTransactionCelo(transactionWithData) - - expect(parseTransactionCelo(serialized)).toMatchInlineSnapshot(` - { - "chainId": 42270, - "data": "0x1234", - "feeCurrency": "0x765de816845861e75a25fca122bb6898b8b1282a", - "gas": 21001n, - "maxFeePerGas": 2000000000n, - "maxPriorityFeePerGas": 2000000000n, - "nonce": 785, - "to": "0x90f79bf6eb2c4f870365e785982e1f101e93b906", - "type": "cip42", - "value": 1000000000000000000n, - } - `) -}) - -test('invalid transaction (all missing)', () => { - expect(() => - parseTransactionCelo(`0x7c${toRlp([]).slice(2)}`), - ).toThrowErrorMatchingInlineSnapshot(` - "Invalid serialized transaction of type \\"cip42\\" was provided. - - Serialized Transaction: \\"0x7cc0\\" - Missing Attributes: chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, feeCurrency, to, gatewayFeeRecipient, gatewayFee, value, data, accessList - - Version: viem@1.0.2" - `) -}) - -test('invalid transaction (some missing)', () => { - expect(() => - parseTransactionCelo(`0x7c${toRlp(['0x0', '0x1']).slice(2)}`), - ).toThrowErrorMatchingInlineSnapshot(` - "Invalid serialized transaction of type \\"cip42\\" was provided. - - Serialized Transaction: \\"0x7cc20001\\" - Missing Attributes: maxPriorityFeePerGas, maxFeePerGas, gas, feeCurrency, to, gatewayFeeRecipient, gatewayFee, value, data, accessList - - Version: viem@1.0.2" - `) -}) - -test('invalid transaction (missing signature)', () => { - expect(() => - parseTransactionCelo( - `0x7c${toRlp([ - '0x', - '0x', - '0x', - '0x', - '0x', - '0x', - '0x', - '0x', - '0x', - '0x', - '0x', - '0x', - '0x', - ]).slice(2)}`, - ), - ).toThrowErrorMatchingInlineSnapshot(` - "Invalid serialized transaction of type \\"cip42\\" was provided. - - Serialized Transaction: \\"0x7ccd80808080808080808080808080\\" - Missing Attributes: r, s - - Version: viem@1.0.2" - `) -}) diff --git a/src/chains/celo/parsers.ts b/src/chains/celo/parsers.ts deleted file mode 100644 index e7cff880cb..0000000000 --- a/src/chains/celo/parsers.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { InvalidSerializedTransactionError } from '../../errors/transaction.js' -import type { Hex } from '../../types/misc.js' -import { isHex } from '../../utils/data/isHex.js' -import { sliceHex } from '../../utils/data/slice.js' -import { hexToBigInt, hexToNumber } from '../../utils/encoding/fromHex.js' -import type { RecursiveArray } from '../../utils/encoding/toRlp.js' -import type { GetSerializedTransactionType } from '../../utils/transaction/getSerializedTransactionType.js' -import { - type ParseTransactionReturnType, - parseAccessList, - parseTransaction, - toTransactionArray, -} from '../../utils/transaction/parseTransaction.js' -import { assertTransactionCIP42 } from './serializers.js' -import type { - CeloTransactionSerialized, - CeloTransactionType, - TransactionSerializableCIP42, - TransactionSerializedCIP42, -} from './types.js' - -export type ParseTransactionCeloReturnType< - TSerialized extends CeloTransactionSerialized = CeloTransactionSerialized, - TType extends CeloTransactionType = GetSerializedTransactionType, -> = TSerialized extends TransactionSerializedCIP42 - ? TransactionSerializableCIP42 - : ParseTransactionReturnType - -export function parseTransactionCelo< - TSerialized extends CeloTransactionSerialized, ->( - serializedTransaction: TSerialized, -): ParseTransactionCeloReturnType { - const serializedType = sliceHex(serializedTransaction, 0, 1) - - if (serializedType === '0x7c') - return parseTransactionCIP42( - serializedTransaction as TransactionSerializedCIP42, - ) as ParseTransactionCeloReturnType - - return parseTransaction( - serializedTransaction, - ) as ParseTransactionCeloReturnType -} - -function parseTransactionCIP42( - serializedTransaction: TransactionSerializedCIP42, -): TransactionSerializableCIP42 { - const transactionArray = toTransactionArray(serializedTransaction) - - const [ - chainId, - nonce, - maxPriorityFeePerGas, - maxFeePerGas, - gas, - feeCurrency, - gatewayFeeRecipient, - gatewayFee, - to, - value, - data, - accessList, - v, - r, - s, - ] = transactionArray - - if (transactionArray.length !== 15 && transactionArray.length !== 12) { - throw new InvalidSerializedTransactionError({ - attributes: { - chainId, - nonce, - maxPriorityFeePerGas, - maxFeePerGas, - gas, - feeCurrency, - to, - gatewayFeeRecipient, - gatewayFee, - value, - data, - accessList, - ...(transactionArray.length > 12 - ? { - v, - r, - s, - } - : {}), - }, - serializedTransaction, - type: 'cip42', - }) - } - - const transaction: Partial = { - chainId: hexToNumber(chainId as Hex), - type: 'cip42', - } - - if (isHex(to) && to !== '0x') transaction.to = to - if (isHex(gas) && gas !== '0x') transaction.gas = hexToBigInt(gas) - if (isHex(data) && data !== '0x') transaction.data = data - if (isHex(nonce) && nonce !== '0x') transaction.nonce = hexToNumber(nonce) - if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value) - if (isHex(feeCurrency) && feeCurrency !== '0x') - transaction.feeCurrency = feeCurrency - if (isHex(gatewayFeeRecipient) && gatewayFeeRecipient !== '0x') - transaction.gatewayFeeRecipient = gatewayFeeRecipient - if (isHex(gatewayFee) && gatewayFee !== '0x') - transaction.gatewayFee = hexToBigInt(gatewayFee) - if (isHex(maxFeePerGas) && maxFeePerGas !== '0x') - transaction.maxFeePerGas = hexToBigInt(maxFeePerGas) - if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x') - transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas) - if (accessList.length !== 0 && accessList !== '0x') - transaction.accessList = parseAccessList(accessList as RecursiveArray) - - assertTransactionCIP42(transaction as TransactionSerializableCIP42) - - return transaction as TransactionSerializableCIP42 -} diff --git a/src/chains/celo/serializers.test.ts b/src/chains/celo/serializers.test.ts deleted file mode 100644 index 3f9d0ddb99..0000000000 --- a/src/chains/celo/serializers.test.ts +++ /dev/null @@ -1,342 +0,0 @@ -import { describe, expect, test } from 'vitest' - -import { accounts } from '../../_test/constants.js' -import { signTransaction } from '../../accounts/utils/signTransaction.js' -import { - FeeCapTooHighError, - InvalidAddressError, - TipAboveFeeCapError, - type TransactionSerializableEIP1559, - parseEther, - parseGwei, - parseTransaction, -} from '../../index.js' -import { serializeTransactionCelo } from './serializers.js' -import type { TransactionSerializableCIP42 } from './types.js' - -const baseCip42: TransactionSerializableCIP42 = { - to: accounts[0].address, - chainId: 42220, - nonce: 0, - maxFeePerGas: parseGwei('2'), - maxPriorityFeePerGas: parseGwei('2'), - value: parseEther('1'), - feeCurrency: '0x765de816845861e75a25fca122bb6898b8b1282a', - type: 'cip42', -} - -describe('cip42', () => { - test('should be able to serialize a cip42 transaction', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - } - - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf84682a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) - - test('args: accessList', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - accessList: [ - { - address: '0x0000000000000000000000000000000000000000', - storageKeys: [ - '0x0000000000000000000000000000000000000000000000000000000000000001', - '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - ], - }, - ], - } - - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf8a282a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080f85bf859940000000000000000000000000000000000000000f842a00000000000000000000000000000000000000000000000000000000000000001a060fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - ) - }) - - test('args: data', () => { - const args: TransactionSerializableCIP42 = { - ...baseCip42, - data: '0x1234', - } - const serialized = serializeTransactionCelo(args) - expect(serialized).toEqual( - '0x7cf84882a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a7640000821234c0', - ) - }) - - test('args: feeCurrency (absent)', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - gatewayFeeRecipient: accounts[0].address, - gatewayFee: parseEther('0.1'), - feeCurrency: undefined, - } - - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf84e82a4ec8084773594008477359400808094f39fd6e51aad88f6f4ce6ab8827279cfffb9226688016345785d8a000094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) - - test('args: gas', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - gas: 69420n, - } - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf84982a4ec808477359400847735940083010f2c94765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) - - test('args: gas (absent)', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - gas: undefined, - } - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf84682a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) - - test('args: gatewayFee', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - gatewayFeeRecipient: accounts[5].address, - gatewayFee: parseEther('0.1'), - } - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf86282a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a949965507d1a55bcc2695c58ba16fb37d819b0a4dc88016345785d8a000094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) - - test('args: maxFeePerGas (absent)', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - // @ts-expect-error - maxFeePerGas: undefined, - } - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf84282a4ec808477359400808094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) - - test('args: maxPriorityFeePerGas (absent)', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - // @ts-expect-error - maxPriorityFeePerGas: undefined, - } - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf84282a4ec808084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) - - test('args: nonce', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - nonce: 20, - } - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf84682a4ec14847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) - - test('args: to (absent)', () => { - const args: TransactionSerializableCIP42 = { - ...baseCip42, - to: undefined, - } - const serialized = serializeTransactionCelo(args) - expect(serialized).toEqual( - '0x7cf282a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808080880de0b6b3a764000080c0', - ) - }) - - test('args: value (absent)', () => { - const args: TransactionSerializableCIP42 = { - ...baseCip42, - value: undefined, - } - const serialized = serializeTransactionCelo(args) - expect(serialized).toEqual( - '0x7cf83e82a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb922668080c0', - ) - }) - - test('type is undefined but has cip42 fields', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - feeCurrency: '0xd8763cba276a3738e6de85b4b3bf5fded6d6ca73', - type: undefined, - } - - expect(serializeTransactionCelo(transaction)).toEqual( - '0x7cf84682a4ec80847735940084773594008094d8763cba276a3738e6de85b4b3bf5fded6d6ca73808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - }) -}) - -test('signed', async () => { - const signed = await signTransaction({ - privateKey: accounts[0].privateKey, - transaction: baseCip42, - serializer: serializeTransactionCelo, - }) - - expect(signed).toEqual( - '0x7cf88982a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c080a01ae1d60446ad5fdd620e1982050dc315ff9a0f61b32bcc2a3cdadd0571a76df7a073aba459b3aef6796d5f2a9979551c29f66586821b5613d5080d00782b07c280', - ) -}) - -test('signature', () => { - expect( - serializeTransactionCelo( - baseCip42, - - { - r: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - s: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - v: 28n, - }, - ), - ).toEqual( - '0x7cf88982a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c001a060fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fea060fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - ) - expect( - serializeTransactionCelo( - baseCip42, - - { - r: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - s: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - v: 27n, - }, - ), - ).toEqual( - '0x7cf88982a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c080a060fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fea060fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe', - ) -}) - -describe('invalid params', () => { - test('invalid to', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - to: '0xdeadbeef', - } - expect(() => serializeTransactionCelo(transaction)).toThrowError( - InvalidAddressError, - ) - }) - - test('maxPriorityFeePerGas is higher than maxPriorityFee', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - maxPriorityFeePerGas: parseGwei('5000000000'), - maxFeePerGas: parseGwei('1'), - } - expect(() => serializeTransactionCelo(transaction)).toThrowError( - TipAboveFeeCapError, - ) - }) - - test('maxFeePerGas is too high', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - maxPriorityFeePerGas: parseGwei('5000000000'), - maxFeePerGas: - 115792089237316195423570985008687907853269984665640564039457584007913129639938n, - } - expect(() => serializeTransactionCelo(transaction)).toThrowError( - FeeCapTooHighError, - ) - }) - - test('feeCurrency is not an address', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - // @ts-expect-error - feeCurrency: 'CUSD', - } - expect(() => serializeTransactionCelo(transaction)).toThrowError( - '`feeCurrency` MUST be a token address for CIP-42 transactions.', - ) - }) - - test('gasPrice is defined', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - // @ts-expect-error - gasPrice: 1, - } - expect(() => serializeTransactionCelo(transaction)).toThrowError( - '`gasPrice` is not a valid CIP-42 Transaction attribute.', - ) - }) - - test('only one of the gateWayFee fields is defined', () => { - const transactionA: TransactionSerializableCIP42 = { - ...baseCip42, - gatewayFeeRecipient: accounts[7].address, - } - expect(() => serializeTransactionCelo(transactionA)).toThrowError( - '`gatewayFee` and `gatewayFeeRecipient` must be provided together.', - ) - const transactionB: TransactionSerializableCIP42 = { - ...baseCip42, - gatewayFee: 1000023434343n, - } - expect(() => serializeTransactionCelo(transactionB)).toThrowError( - '`gatewayFee` and `gatewayFeeRecipient` must be provided together.', - ) - }) - - test('transaction looks like cip42 but does not have values for either feeCurrency or gatewayFee', () => { - const transaction = { - ...baseCip42, - feeCurrency: undefined, - gatewayFee: undefined, - gatewayFeeRecipient: undefined, - } - expect(() => serializeTransactionCelo(transaction)).toThrowError( - 'Either `feeCurrency` or `gatewayFeeRecipient` must be provided for CIP-42 transactions.', - ) - }) - - test('chainID is invalid', () => { - const transaction: TransactionSerializableCIP42 = { - ...baseCip42, - chainId: -1, - } - - expect(() => serializeTransactionCelo(transaction)).toThrowError( - `Chain ID "${-1}" is invalid.`, - ) - }) -}) - -describe('not cip42', () => { - const transaction: TransactionSerializableEIP1559 = { - to: accounts[0].address, - chainId: 1, - nonce: 0, - maxFeePerGas: parseGwei('2'), - maxPriorityFeePerGas: parseGwei('2'), - value: parseEther('1'), - } - - test('it calls the standard serializeTransactionCelo', () => { - const serialized = serializeTransactionCelo(transaction) - expect(serialized).toEqual( - '0x02ed0180847735940084773594008094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0', - ) - expect(parseTransaction(serialized)).toEqual({ - to: accounts[0].address, - chainId: 1, - maxFeePerGas: parseGwei('2'), - maxPriorityFeePerGas: parseGwei('2'), - value: parseEther('1'), - type: 'eip1559', - }) - }) -}) diff --git a/src/chains/celo/serializers.ts b/src/chains/celo/serializers.ts deleted file mode 100644 index ca5c00f5ac..0000000000 --- a/src/chains/celo/serializers.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { InvalidAddressError } from '../../errors/address.js' -import { BaseError } from '../../errors/base.js' -import { InvalidChainIdError } from '../../errors/chain.js' -import { FeeCapTooHighError, TipAboveFeeCapError } from '../../errors/node.js' -import type { Signature } from '../../types/misc.js' -import type { TransactionSerializable } from '../../types/transaction.js' -import { isAddress } from '../../utils/address/isAddress.js' -import { concatHex } from '../../utils/data/concat.js' -import { trim } from '../../utils/data/trim.js' -import { toHex } from '../../utils/encoding/toHex.js' -import { toRlp } from '../../utils/encoding/toRlp.js' -import { serializeAccessList } from '../../utils/transaction/serializeAccessList.js' -import { - type SerializeTransactionFn, - serializeTransaction, -} from '../../utils/transaction/serializeTransaction.js' -import type { ChainSerializers } from '../types.js' -import type { - CeloTransactionSerializable, - TransactionSerializableCIP42, - TransactionSerializedCIP42, -} from './types.js' - -export const serializeTransactionCelo: SerializeTransactionFn< - CeloTransactionSerializable -> = (tx, signature) => { - // Handle CIP-42 transactions - if (isCIP42(tx)) - return serializeTransactionCIP42( - tx as TransactionSerializableCIP42, - signature, - ) - - // Handle other transaction types - return serializeTransaction(tx as TransactionSerializable, signature) -} - -export const serializersCelo = { - transaction: serializeTransactionCelo, -} as const satisfies ChainSerializers - -////////////////////////////////////////////////////////////////////////////// -// Serializers - -export type SerializeTransactionCIP42ReturnType = TransactionSerializedCIP42 - -// There shall be a typed transaction with the code 0x7c that has the following format: -// 0x7c || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, feecurrency, gatewayFeeRecipient, gatewayfee, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s]). -// This will be in addition to the type 0x02 transaction as specified in EIP-1559. -function serializeTransactionCIP42( - transaction: TransactionSerializableCIP42, - signature?: Signature, -): SerializeTransactionCIP42ReturnType { - assertTransactionCIP42(transaction) - const { - chainId, - gas, - nonce, - to, - value, - maxFeePerGas, - maxPriorityFeePerGas, - accessList, - feeCurrency, - gatewayFeeRecipient, - gatewayFee, - data, - } = transaction - - const serializedTransaction = [ - toHex(chainId), - nonce ? toHex(nonce) : '0x', - maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x', - maxFeePerGas ? toHex(maxFeePerGas) : '0x', - gas ? toHex(gas) : '0x', - feeCurrency ?? '0x', - gatewayFeeRecipient ?? '0x', - gatewayFee ? toHex(gatewayFee) : '0x', - to ?? '0x', - value ? toHex(value) : '0x', - data ?? '0x', - serializeAccessList(accessList), - ] - - if (signature) { - serializedTransaction.push( - signature.v === 27n ? '0x' : toHex(1), // yParity - trim(signature.r), - trim(signature.s), - ) - } - - return concatHex([ - '0x7c', - toRlp(serializedTransaction), - ]) as SerializeTransactionCIP42ReturnType -} - -////////////////////////////////////////////////////////////////////////////// -// Utilities - -// process as CIP42 if any of these fields are present. realistically gatewayfee is not used but is part of spec -function isCIP42(transaction: CeloTransactionSerializable) { - if ( - 'maxFeePerGas' in transaction && - 'maxPriorityFeePerGas' in transaction && - ('feeCurrency' in transaction || - 'gatewayFee' in transaction || - 'gatewayFeeRecipient' in transaction) - ) - return true - return false -} - -// maxFeePerGas must be less than 2^256 - 1: however writing like that caused exceptions to be raised -const MAX_MAX_FEE_PER_GAS = - 115792089237316195423570985008687907853269984665640564039457584007913129639935n - -export function assertTransactionCIP42( - transaction: TransactionSerializableCIP42, -) { - const { - chainId, - maxPriorityFeePerGas, - gasPrice, - maxFeePerGas, - to, - feeCurrency, - gatewayFee, - gatewayFeeRecipient, - } = transaction - if (chainId <= 0) throw new InvalidChainIdError({ chainId }) - if (to && !isAddress(to)) throw new InvalidAddressError({ address: to }) - if (gasPrice) - throw new BaseError( - '`gasPrice` is not a valid CIP-42 Transaction attribute.', - ) - - if (maxFeePerGas && maxFeePerGas > MAX_MAX_FEE_PER_GAS) - throw new FeeCapTooHighError({ maxFeePerGas }) - - if ( - maxPriorityFeePerGas && - maxFeePerGas && - maxPriorityFeePerGas > maxFeePerGas - ) - throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas }) - - if ( - (gatewayFee && !gatewayFeeRecipient) || - (gatewayFeeRecipient && !gatewayFee) - ) { - throw new BaseError( - '`gatewayFee` and `gatewayFeeRecipient` must be provided together.', - ) - } - - if (feeCurrency && !feeCurrency?.startsWith('0x')) { - throw new BaseError( - '`feeCurrency` MUST be a token address for CIP-42 transactions.', - ) - } - - if (!feeCurrency && !gatewayFeeRecipient) { - throw new BaseError( - 'Either `feeCurrency` or `gatewayFeeRecipient` must be provided for CIP-42 transactions.', - ) - } -} diff --git a/src/chains/celo/types.ts b/src/chains/celo/types.ts deleted file mode 100644 index 03876cee95..0000000000 --- a/src/chains/celo/types.ts +++ /dev/null @@ -1,143 +0,0 @@ -import type { Address } from 'abitype' - -import type { Block, BlockTag } from '../../types/block.js' -import type { FeeValuesEIP1559 } from '../../types/fee.js' -import type { Hex } from '../../types/misc.js' -import type { - RpcBlock, - RpcTransaction, - RpcTransactionReceipt, - RpcTransactionRequest, - TransactionType, -} from '../../types/rpc.js' -import type { - AccessList, - Transaction, - TransactionReceipt, - TransactionRequest, - TransactionSerializable, - TransactionSerializableBase, - TransactionSerialized, -} from '../../types/transaction.js' -import type { NeverBy } from '../../types/utils.js' -import type { OptimismRpcTransaction } from '../optimism/types.js' - -type CeloBlockExclude = - | 'difficulty' - | 'gasLimit' - | 'mixHash' - | 'nonce' - | 'uncles' - -export type CeloBlockOverrides = { - randomness: { - committed: Hex - revealed: Hex - } -} -export type CeloBlock< - TIncludeTransactions extends boolean = boolean, - TBlockTag extends BlockTag = BlockTag, -> = NeverBy< - Block< - bigint, - TIncludeTransactions, - TBlockTag, - CeloTransaction - >, - CeloBlockExclude -> & - CeloBlockOverrides - -export type CeloRpcBlockOverrides = { - randomness: { - committed: Hex - revealed: Hex - } -} -export type CeloRpcBlock< - TBlockTag extends BlockTag = BlockTag, - TIncludeTransactions extends boolean = boolean, -> = NeverBy< - RpcBlock< - TBlockTag, - TIncludeTransactions, - OptimismRpcTransaction - >, - CeloBlockExclude -> & - CeloRpcBlockOverrides - -export type CeloRpcTransactionOverrides = { - feeCurrency: Address | null - gatewayFee: Hex | null - gatewayFeeRecipient: Address | null -} -export type CeloRpcTransaction = - RpcTransaction & CeloRpcTransactionOverrides - -export type CeloRpcTransactionReceiptOverrides = { - feeCurrency: Address | null - gatewayFee: Hex | null - gatewayFeeRecipient: Address | null -} -export type CeloRpcTransactionReceipt = RpcTransactionReceipt & - CeloRpcTransactionReceiptOverrides - -export type CeloRpcTransactionRequestOverrides = { - feeCurrency?: Address - gatewayFee?: Hex - gatewayFeeRecipient?: Address -} -export type CeloRpcTransactionRequest = RpcTransactionRequest & - CeloRpcTransactionRequestOverrides - -export type CeloTransactionOverrides = { - feeCurrency: Address | null - gatewayFee: bigint | null - gatewayFeeRecipient: Address | null -} -export type CeloTransaction = - Transaction & CeloTransactionOverrides - -export type CeloTransactionReceiptOverrides = { - feeCurrency: Address | null - gatewayFee: bigint | null - gatewayFeeRecipient: Address | null -} -export type CeloTransactionReceipt = TransactionReceipt & - CeloTransactionReceiptOverrides - -export type CeloTransactionRequestOverrides = { - feeCurrency?: Address - gatewayFee?: bigint - gatewayFeeRecipient?: Address -} -export type CeloTransactionRequest = TransactionRequest & - CeloTransactionRequestOverrides - -export type CeloTransactionSerializable = - | TransactionSerializableCIP42 - | TransactionSerializable - -export type CeloTransactionSerialized< - TType extends CeloTransactionType = 'legacy', -> = TransactionSerialized | TransactionSerializedCIP42 - -export type CeloTransactionType = TransactionType | 'cip42' - -export type TransactionSerializableCIP42< - TQuantity = bigint, - TIndex = number, -> = TransactionSerializableBase & - FeeValuesEIP1559 & { - accessList?: AccessList - gasPrice?: never - feeCurrency?: Address - gatewayFeeRecipient?: Address - gatewayFee?: TQuantity - chainId: number - type?: 'cip42' - } - -export type TransactionSerializedCIP42 = `0x7c${string}` diff --git a/src/chains/index.test.ts b/src/chains/index.test.ts deleted file mode 100644 index a32a1cb686..0000000000 --- a/src/chains/index.test.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { expect, test } from 'vitest' - -import * as chains from './index.js' - -test('exports chains', () => { - expect(Object.keys(chains)).toMatchInlineSnapshot(` - [ - "arbitrum", - "arbitrumGoerli", - "aurora", - "auroraTestnet", - "avalanche", - "avalancheFuji", - "base", - "baseGoerli", - "boba", - "bronos", - "bronosTestnet", - "bsc", - "bscTestnet", - "canto", - "celo", - "celoAlfajores", - "celoCannoli", - "cronos", - "crossbell", - "dfk", - "dogechain", - "evmos", - "evmosTestnet", - "fantom", - "fantomTestnet", - "filecoin", - "filecoinCalibration", - "filecoinHyperspace", - "flare", - "flareTestnet", - "foundry", - "iotex", - "iotexTestnet", - "goerli", - "gnosis", - "gnosisChiado", - "haqqMainnet", - "haqqTestedge2", - "hardhat", - "harmonyOne", - "klaytn", - "lineaTestnet", - "localhost", - "mainnet", - "metis", - "metisGoerli", - "mev", - "mevTestnet", - "moonbaseAlpha", - "moonbeam", - "moonriver", - "nexi", - "okc", - "optimism", - "optimismGoerli", - "polygon", - "polygonMumbai", - "polygonZkEvm", - "polygonZkEvmTestnet", - "pulsechain", - "pulsechainV4", - "scrollSepolia", - "scrollTestnet", - "sepolia", - "skaleBlockBrawlers", - "skaleCalypso", - "skaleCalypsoTestnet", - "skaleChaosTestnet", - "skaleCryptoBlades", - "skaleCryptoColosseum", - "skaleEuropa", - "skaleEuropaTestnet", - "skaleExorde", - "skaleHumanProtocol", - "skaleNebula", - "skaleNebulaTestnet", - "skaleRazor", - "skaleTitan", - "skaleTitanTestnet", - "songbird", - "songbirdTestnet", - "shardeumSphinx", - "syscoin", - "taraxa", - "taraxaTestnet", - "telos", - "telosTestnet", - "thunderTestnet", - "wanchain", - "wanchainTestnet", - "xdc", - "xdcTestnet", - "zhejiang", - "zkSync", - "zkSyncTestnet", - "zora", - "zoraTestnet", - ] - `) -}) diff --git a/src/chains/index.ts b/src/chains/index.ts index 451ee48def..cef0364085 100644 --- a/src/chains/index.ts +++ b/src/chains/index.ts @@ -1,168 +1,111 @@ -import * as chains from '@wagmi/chains' - -import { defineChain } from '../utils/chain.js' -import { formattersCelo } from './celo/formatters.js' -import { serializersCelo } from './celo/serializers.js' -import { feesOptimism } from './optimism/fees.js' -import { formattersOptimism } from './optimism/formatters.js' - -export const arbitrum = /*#__PURE__*/ defineChain(chains.arbitrum) -export const arbitrumGoerli = /*#__PURE__*/ defineChain(chains.arbitrumGoerli) -export const aurora = /*#__PURE__*/ defineChain(chains.aurora) -export const auroraTestnet = /*#__PURE__*/ defineChain(chains.auroraTestnet) -export const avalanche = /*#__PURE__*/ defineChain(chains.avalanche) -export const avalancheFuji = /*#__PURE__*/ defineChain(chains.avalancheFuji) -export const base = /*#__PURE__*/ defineChain(chains.base, { - fees: feesOptimism, - formatters: formattersOptimism, -}) -export const baseGoerli = /*#__PURE__*/ defineChain(chains.baseGoerli, { - fees: feesOptimism, - formatters: formattersOptimism, -}) -export const boba = /*#__PURE__*/ defineChain(chains.boba) -export const bronos = /*#__PURE__*/ defineChain(chains.bronos) -export const bronosTestnet = /*#__PURE__*/ defineChain(chains.bronosTestnet) -export const bsc = /*#__PURE__*/ defineChain(chains.bsc) -export const bscTestnet = /*#__PURE__*/ defineChain(chains.bscTestnet) -export const canto = /*#__PURE__*/ defineChain(chains.canto) -export const celo = /*#__PURE__*/ defineChain(chains.celo, { - formatters: formattersCelo, - serializers: serializersCelo, -}) -export const celoAlfajores = /*#__PURE__*/ defineChain(chains.celoAlfajores, { - formatters: formattersCelo, - serializers: serializersCelo, -}) -export const celoCannoli = /*#__PURE__*/ defineChain(chains.celoCannoli, { - formatters: formattersCelo, - serializers: serializersCelo, -}) -export const cronos = /*#__PURE__*/ defineChain(chains.cronos) -export const crossbell = /*#__PURE__*/ defineChain(chains.crossbell) -export const dfk = /*#__PURE__*/ defineChain(chains.dfk) -export const dogechain = /*#__PURE__*/ defineChain(chains.dogechain) -export const evmos = /*#__PURE__*/ defineChain(chains.evmos) -export const evmosTestnet = /*#__PURE__*/ defineChain(chains.evmosTestnet) -export const fantom = /*#__PURE__*/ defineChain(chains.fantom) -export const fantomTestnet = /*#__PURE__*/ defineChain(chains.fantomTestnet) -export const filecoin = /*#__PURE__*/ defineChain(chains.filecoin) -export const filecoinCalibration = /*#__PURE__*/ defineChain( - chains.filecoinCalibration, -) -export const filecoinHyperspace = /*#__PURE__*/ defineChain( - chains.filecoinHyperspace, -) -export const flare = /*#__PURE__*/ defineChain(chains.flare) -export const flareTestnet = /*#__PURE__*/ defineChain(chains.flareTestnet) -export const foundry = /*#__PURE__*/ defineChain(chains.foundry) -export const iotex = /*#__PURE__*/ defineChain(chains.iotex) -export const iotexTestnet = /*#__PURE__*/ defineChain(chains.iotexTestnet) -export const goerli = /*#__PURE__*/ defineChain(chains.goerli) -export const gnosis = /*#__PURE__*/ defineChain(chains.gnosis) -export const gnosisChiado = /*#__PURE__*/ defineChain(chains.gnosisChiado) -export const haqqMainnet = /*#__PURE__*/ defineChain(chains.haqqMainnet) -export const haqqTestedge2 = /*#__PURE__*/ defineChain(chains.haqqTestedge2) -export const hardhat = /*#__PURE__*/ defineChain(chains.hardhat) -export const harmonyOne = /*#__PURE__*/ defineChain(chains.harmonyOne) -export const klaytn = /*#__PURE__*/ defineChain(chains.klaytn) -export const lineaTestnet = /*#__PURE__*/ defineChain(chains.lineaTestnet) -export const localhost = /*#__PURE__*/ defineChain(chains.localhost) -export const mainnet = /*#__PURE__*/ defineChain(chains.mainnet) -export const metis = /*#__PURE__*/ defineChain(chains.metis) -export const metisGoerli = /*#__PURE__*/ defineChain(chains.metisGoerli) -export const mev = /*#__PURE__*/ defineChain(chains.mev) -export const mevTestnet = /*#__PURE__*/ defineChain(chains.mevTestnet) -export const moonbaseAlpha = /*#__PURE__*/ defineChain(chains.moonbaseAlpha) -export const moonbeam = /*#__PURE__*/ defineChain(chains.moonbeam) -export const moonriver = /*#__PURE__*/ defineChain(chains.moonriver) -export const nexi = /*#__PURE__*/ defineChain(chains.nexi) -export const okc = /*#__PURE__*/ defineChain(chains.okc) -export const optimism = /*#__PURE__*/ defineChain(chains.optimism, { - fees: feesOptimism, - formatters: formattersOptimism, -}) -export const optimismGoerli = /*#__PURE__*/ defineChain(chains.optimismGoerli, { - fees: feesOptimism, - formatters: formattersOptimism, -}) -export const polygon = /*#__PURE__*/ defineChain(chains.polygon) -export const polygonMumbai = /*#__PURE__*/ defineChain(chains.polygonMumbai) -export const polygonZkEvm = /*#__PURE__*/ defineChain(chains.polygonZkEvm) -export const polygonZkEvmTestnet = /*#__PURE__*/ defineChain( - chains.polygonZkEvmTestnet, -) -export const pulsechain = /*#__PURE__*/ defineChain(chains.pulsechain) -export const pulsechainV4 = /*#__PURE__*/ defineChain(chains.pulsechainV4) -export const scrollSepolia = /*#__PURE__*/ defineChain(chains.scrollSepolia) -export const scrollTestnet = /*#__PURE__*/ defineChain(chains.scrollTestnet) -export const sepolia = /*#__PURE__*/ defineChain(chains.sepolia) -export const skaleBlockBrawlers = /*#__PURE__*/ defineChain( - chains.skaleBlockBrawlers, -) -export const skaleCalypso = /*#__PURE__*/ defineChain(chains.skaleCalypso) -export const skaleCalypsoTestnet = /*#__PURE__*/ defineChain( - chains.skaleCalypsoTestnet, -) -export const skaleChaosTestnet = /*#__PURE__*/ defineChain( - chains.skaleChaosTestnet, -) -export const skaleCryptoBlades = /*#__PURE__*/ defineChain( - chains.skaleCryptoBlades, -) -export const skaleCryptoColosseum = /*#__PURE__*/ defineChain( - chains.skaleCryptoColosseum, -) -export const skaleEuropa = /*#__PURE__*/ defineChain(chains.skaleEuropa) -export const skaleEuropaTestnet = /*#__PURE__*/ defineChain( - chains.skaleEuropaTestnet, -) -export const skaleExorde = /*#__PURE__*/ defineChain(chains.skaleExorde) -export const skaleHumanProtocol = /*#__PURE__*/ defineChain( - chains.skaleHumanProtocol, -) -export const skaleNebula = /*#__PURE__*/ defineChain(chains.skaleNebula) -export const skaleNebulaTestnet = /*#__PURE__*/ defineChain( - chains.skaleNebulaTestnet, -) -export const skaleRazor = /*#__PURE__*/ defineChain(chains.skaleRazor) -export const skaleTitan = /*#__PURE__*/ defineChain(chains.skaleTitan) -export const skaleTitanTestnet = /*#__PURE__*/ defineChain( - chains.skaleTitanTestnet, -) -export const songbird = /*#__PURE__*/ defineChain(chains.songbird) -export const songbirdTestnet = /*#__PURE__*/ defineChain(chains.songbirdTestnet) -export const shardeumSphinx = /*#__PURE__*/ defineChain(chains.shardeumSphinx) -export const syscoin = /*#__PURE__*/ defineChain(chains.syscoin) -export const taraxa = /*#__PURE__*/ defineChain(chains.taraxa) -export const taraxaTestnet = /*#__PURE__*/ defineChain(chains.taraxaTestnet) -export const telos = /*#__PURE__*/ defineChain(chains.telos) -export const telosTestnet = /*#__PURE__*/ defineChain(chains.telosTestnet) -export const thunderTestnet = /*#__PURE__*/ defineChain(chains.thunderTestnet) -export const wanchain = /*#__PURE__*/ defineChain(chains.wanchain) -export const wanchainTestnet = /*#__PURE__*/ defineChain(chains.wanchainTestnet) -export const xdc = /*#__PURE__*/ defineChain(chains.xdc) -export const xdcTestnet = /*#__PURE__*/ defineChain(chains.xdcTestnet) -export const zhejiang = /*#__PURE__*/ defineChain(chains.zhejiang) -export const zkSync = /*#__PURE__*/ defineChain(chains.zkSync) -export const zkSyncTestnet = /*#__PURE__*/ defineChain(chains.zkSyncTestnet) -export const zora = /*#__PURE__*/ defineChain(chains.zora, { - fees: feesOptimism, - formatters: formattersOptimism, -}) -export const zoraTestnet = /*#__PURE__*/ defineChain(chains.zoraTestnet, { - fees: feesOptimism, - formatters: formattersOptimism, -}) - -export type { - Chain, - ChainContract, - ChainFees, - ChainFormatter, - ChainFormatters, - ChainSerializers, - ExtractChainFormatterExclude, - ExtractChainFormatterParameters, - ExtractChainFormatterReturnType, -} from './types.js' +export { + type Chain, + type ChainConfig, + type ChainContract, + type ChainEstimateFeesPerGasFnParameters, + type ChainFees, + type ChainFeesFnParameters, + type ChainFormatter, + type ChainFormatters, + type ChainSerializers, + type ExtractChainFormatterExclude, + type ExtractChainFormatterParameters, + type ExtractChainFormatterReturnType, + arbitrum, + arbitrumGoerli, + aurora, + auroraTestnet, + avalanche, + avalancheFuji, + base, + baseGoerli, + boba, + bronos, + bronosTestnet, + bsc, + bscTestnet, + canto, + celo, + celoAlfajores, + celoCannoli, + cronos, + crossbell, + dfk, + dogechain, + evmos, + evmosTestnet, + fantom, + fantomTestnet, + filecoin, + filecoinCalibration, + filecoinHyperspace, + flare, + flareTestnet, + foundry, + gnosis, + gnosisChiado, + goerli, + haqqMainnet, + haqqTestedge2, + hardhat, + harmonyOne, + iotex, + iotexTestnet, + klaytn, + lineaTestnet, + localhost, + mainnet, + metis, + metisGoerli, + mev, + mevTestnet, + moonbaseAlpha, + moonbeam, + moonriver, + nexi, + okc, + optimism, + optimismGoerli, + polygon, + polygonMumbai, + polygonZkEvm, + polygonZkEvmTestnet, + pulsechain, + pulsechainV4, + scrollSepolia, + scrollTestnet, + sepolia, + shardeumSphinx, + skaleBlockBrawlers, + skaleCalypso, + skaleCalypsoTestnet, + skaleChaosTestnet, + skaleCryptoBlades, + skaleCryptoColosseum, + skaleEuropa, + skaleEuropaTestnet, + skaleExorde, + skaleHumanProtocol, + skaleNebula, + skaleNebulaTestnet, + skaleRazor, + skaleTitan, + skaleTitanTestnet, + songbird, + songbirdTestnet, + syscoin, + taraxa, + taraxaTestnet, + telos, + telosTestnet, + thunderTestnet, + wanchain, + wanchainTestnet, + xdc, + xdcTestnet, + zhejiang, + zkSync, + zkSyncTestnet, + zora, + zoraTestnet, +} from '@viem/chains' diff --git a/src/chains/optimism/fees.ts b/src/chains/optimism/fees.ts deleted file mode 100644 index c144375da3..0000000000 --- a/src/chains/optimism/fees.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { ChainFees } from '../types.js' - -export const feesOptimism = { - defaultPriorityFee: 1_000_000n, // 0.001 gwei -} as const satisfies ChainFees diff --git a/src/chains/optimism/formatters.test-d.ts b/src/chains/optimism/formatters.test-d.ts deleted file mode 100644 index dc1841357f..0000000000 --- a/src/chains/optimism/formatters.test-d.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { describe, expectTypeOf, test } from 'vitest' - -import { getBlock } from '../../actions/public/getBlock.js' -import { getTransaction } from '../../actions/public/getTransaction.js' -import { getTransactionReceipt } from '../../actions/public/getTransactionReceipt.js' -import { createPublicClient } from '../../clients/createPublicClient.js' -import { http } from '../../clients/transports/http.js' -import type { Hash } from '../../types/misc.js' -import type { RpcBlock } from '../../types/rpc.js' -import type { Assign } from '../../types/utils.js' -import { optimism } from '../index.js' -import { formattersOptimism } from './formatters.js' -import type { - OptimismRpcBlockOverrides, - OptimismRpcTransaction, -} from './types.js' - -describe('block', () => { - expectTypeOf(formattersOptimism.block.format).parameter(0).toEqualTypeOf< - Assign< - Partial, - OptimismRpcBlockOverrides & { - transactions: `0x${string}`[] | OptimismRpcTransaction[] - } - > - >() -}) - -describe('transaction', () => { - expectTypeOf< - ReturnType['sourceHash'] - >().toEqualTypeOf<`0x${string}` | undefined>() - expectTypeOf< - ReturnType['mint'] - >().toEqualTypeOf() - expectTypeOf< - ReturnType['isSystemTx'] - >().toEqualTypeOf() -}) - -describe('smoke', () => { - test('block', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - - const block = await getBlock(client, { - blockNumber: 16645775n, - }) - expectTypeOf(block.transactions).toEqualTypeOf() - - const block_includeTransactions = await getBlock(client, { - blockNumber: 16645775n, - includeTransactions: true, - }) - expectTypeOf( - block_includeTransactions.transactions[0].sourceHash, - ).toEqualTypeOf<`0x${string}` | undefined>() - expectTypeOf( - block_includeTransactions.transactions[0].type === 'deposit' && - block_includeTransactions.transactions[0].sourceHash, - ).toEqualTypeOf() - expectTypeOf( - block_includeTransactions.transactions[0].type === 'eip1559' && - block_includeTransactions.transactions[0].sourceHash, - ).toEqualTypeOf() - }) - - test('transaction', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - - const transaction = await getTransaction(client, { - blockNumber: 16628100n, - index: 0, - }) - - expectTypeOf(transaction.type).toEqualTypeOf< - 'legacy' | 'eip2930' | 'eip1559' | 'deposit' - >() - expectTypeOf( - transaction.type === 'deposit' && transaction.isSystemTx, - ).toEqualTypeOf() - expectTypeOf( - transaction.type === 'deposit' && transaction.sourceHash, - ).toEqualTypeOf() - expectTypeOf( - transaction.type === 'deposit' && transaction.mint, - ).toEqualTypeOf() - expectTypeOf( - transaction.type === 'eip1559' && transaction.isSystemTx, - ).toEqualTypeOf() - expectTypeOf( - transaction.type === 'eip1559' && transaction.sourceHash, - ).toEqualTypeOf() - expectTypeOf( - transaction.type === 'eip1559' && transaction.mint, - ).toEqualTypeOf() - }) - - test('transaction receipt', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - - const transactionReceipt = await getTransactionReceipt(client, { - hash: '0x', - }) - - expectTypeOf(transactionReceipt.l1Fee).toEqualTypeOf() - expectTypeOf(transactionReceipt.l1FeeScalar).toEqualTypeOf() - expectTypeOf(transactionReceipt.l1GasPrice).toEqualTypeOf() - expectTypeOf(transactionReceipt.l1GasUsed).toEqualTypeOf() - }) -}) diff --git a/src/chains/optimism/formatters.test.ts b/src/chains/optimism/formatters.test.ts deleted file mode 100644 index 33a17ff9c3..0000000000 --- a/src/chains/optimism/formatters.test.ts +++ /dev/null @@ -1,685 +0,0 @@ -import { describe, expect, test } from 'vitest' - -import { getBlock } from '../../actions/public/getBlock.js' -import { getTransaction } from '../../actions/public/getTransaction.js' -import { getTransactionReceipt } from '../../actions/public/getTransactionReceipt.js' -import { createPublicClient } from '../../clients/createPublicClient.js' -import { http } from '../../clients/transports/http.js' -import { optimism } from '../index.js' - -describe('block', () => { - test('formatter', async () => { - const { block } = optimism.formatters! - - expect( - block.format({ - baseFeePerGas: '0x1', - difficulty: '0x0', - gasLimit: '0x420', - gasUsed: '0x69', - hash: '0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846', - logsBloom: - '0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010', - miner: '0x4200000000000000000000000000000000000011', - mixHash: - '0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887', - nonce: '0x0000000000000000', - number: '0x69420', - parentHash: - '0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6', - receiptsRoot: - '0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde', - sha3Uncles: - '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', - size: '0x69420', - stateRoot: - '0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746', - timestamp: '0xa42069', - totalDifficulty: '0x0', - transactionsRoot: - '0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5', - transactions: [ - { - blockHash: - '0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846', - blockNumber: '0x1', - from: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001', - gas: '0x420', - hash: '0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a', - maxFeePerGas: '0x0', - maxPriorityFeePerGas: '0x0', - input: - '0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0', - mint: '0x0', - nonce: '0x420', - r: '0x0', - s: '0x0', - sourceHash: - '0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df', - to: '0x4200000000000000000000000000000000000015', - transactionIndex: '0x0', - type: '0x7e', - v: '0x0', - value: '0x0', - }, - { - blockHash: - '0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846', - blockNumber: '0x1', - from: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001', - gas: '0x420', - hash: '0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a', - maxFeePerGas: '0x0', - maxPriorityFeePerGas: '0x0', - input: - '0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0', - mint: undefined, - nonce: '0x420', - r: '0x0', - s: '0x0', - sourceHash: - '0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df', - to: '0x4200000000000000000000000000000000000015', - transactionIndex: '0x0', - type: '0x7e', - v: '0x0', - value: '0x0', - }, - ], - uncles: [], - }), - ).toMatchInlineSnapshot(` - { - "baseFeePerGas": 1n, - "difficulty": 0n, - "gasLimit": 1056n, - "gasUsed": 105n, - "hash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", - "logsBloom": "0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010", - "miner": "0x4200000000000000000000000000000000000011", - "mixHash": "0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887", - "nonce": "0x0000000000000000", - "number": 431136n, - "parentHash": "0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6", - "receiptsRoot": "0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde", - "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "size": 431136n, - "stateRoot": "0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746", - "timestamp": 10756201n, - "totalDifficulty": 0n, - "transactions": [ - { - "blockHash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", - "blockNumber": 1n, - "chainId": undefined, - "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", - "gas": 1056n, - "gasPrice": undefined, - "hash": "0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a", - "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", - "isSystemTx": undefined, - "maxFeePerGas": 0n, - "maxPriorityFeePerGas": 0n, - "mint": 0n, - "nonce": 1056, - "r": "0x0", - "s": "0x0", - "sourceHash": "0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df", - "to": "0x4200000000000000000000000000000000000015", - "transactionIndex": 0, - "type": "deposit", - "typeHex": "0x7e", - "v": 0n, - "value": 0n, - }, - { - "blockHash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", - "blockNumber": 1n, - "chainId": undefined, - "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", - "gas": 1056n, - "gasPrice": undefined, - "hash": "0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a", - "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", - "isSystemTx": undefined, - "maxFeePerGas": 0n, - "maxPriorityFeePerGas": 0n, - "mint": undefined, - "nonce": 1056, - "r": "0x0", - "s": "0x0", - "sourceHash": "0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df", - "to": "0x4200000000000000000000000000000000000015", - "transactionIndex": 0, - "type": "deposit", - "typeHex": "0x7e", - "v": 0n, - "value": 0n, - }, - ], - "transactionsRoot": "0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5", - "uncles": [], - } - `) - - expect( - block.format({ - baseFeePerGas: '0x1', - difficulty: '0x0', - gasLimit: '0x420', - gasUsed: '0x69', - hash: '0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846', - logsBloom: - '0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010', - miner: '0x4200000000000000000000000000000000000011', - mixHash: - '0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887', - nonce: '0x0000000000000000', - number: '0x69420', - parentHash: - '0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6', - receiptsRoot: - '0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde', - sha3Uncles: - '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', - size: '0x69420', - stateRoot: - '0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746', - timestamp: '0xa42069', - totalDifficulty: '0x0', - transactionsRoot: - '0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5', - transactions: ['0x'], - uncles: [], - }), - ).toMatchInlineSnapshot(` - { - "baseFeePerGas": 1n, - "difficulty": 0n, - "gasLimit": 1056n, - "gasUsed": 105n, - "hash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", - "logsBloom": "0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010", - "miner": "0x4200000000000000000000000000000000000011", - "mixHash": "0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887", - "nonce": "0x0000000000000000", - "number": 431136n, - "parentHash": "0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6", - "receiptsRoot": "0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde", - "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "size": 431136n, - "stateRoot": "0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746", - "timestamp": 10756201n, - "totalDifficulty": 0n, - "transactions": [ - "0x", - ], - "transactionsRoot": "0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5", - "uncles": [], - } - `) - }) - - test('action', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - const block = await getBlock(client, { - blockNumber: 105849734n, - includeTransactions: true, - }) - - const { extraData: _extraData, transactions, ...rest } = block - expect(transactions[0]).toMatchInlineSnapshot(` - { - "blockHash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", - "blockNumber": 105849734n, - "chainId": undefined, - "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", - "gas": 1000000n, - "gasPrice": 0n, - "hash": "0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a", - "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", - "isSystemTx": undefined, - "maxFeePerGas": undefined, - "maxPriorityFeePerGas": undefined, - "mint": 0n, - "nonce": 614670, - "r": "0x0", - "s": "0x0", - "sourceHash": "0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df", - "to": "0x4200000000000000000000000000000000000015", - "transactionIndex": 0, - "type": "deposit", - "typeHex": "0x7e", - "v": 0n, - "value": 0n, - } - `) - expect(rest).toMatchInlineSnapshot(` - { - "baseFeePerGas": 83n, - "difficulty": 0n, - "gasLimit": 30000000n, - "gasUsed": 1414689n, - "hash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", - "logsBloom": "0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010", - "miner": "0x4200000000000000000000000000000000000011", - "mixHash": "0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887", - "nonce": "0x0000000000000000", - "number": 105849734n, - "parentHash": "0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6", - "receiptsRoot": "0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde", - "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "size": 4072n, - "stateRoot": "0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746", - "timestamp": 1687298245n, - "totalDifficulty": 0n, - "transactionsRoot": "0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5", - "uncles": [], - } - `) - }) -}) - -describe('transaction', () => { - test('formatter', () => { - const { transaction } = optimism.formatters! - - expect( - transaction.format({ - accessList: [], - blockHash: - '0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574', - blockNumber: '0x1', - chainId: '0x1', - from: '0xacd03d601e5bb1b275bb94076ff46ed9d753435a', - gas: '0x69', - hash: '0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822', - input: '0x', - maxFeePerGas: '0x1', - maxPriorityFeePerGas: '0x2', - nonce: '0x3', - r: '0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e', - s: '0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a', - to: '0xeb610a69341aace81ed810ed42428249512378cd', - transactionIndex: '0x4', - type: '0x2', - v: '0x1', - value: '0x69', - }), - ).toMatchInlineSnapshot(` - { - "accessList": [], - "blockHash": "0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574", - "blockNumber": 1n, - "chainId": 1, - "from": "0xacd03d601e5bb1b275bb94076ff46ed9d753435a", - "gas": 105n, - "gasPrice": undefined, - "hash": "0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822", - "input": "0x", - "maxFeePerGas": 1n, - "maxPriorityFeePerGas": 2n, - "nonce": 3, - "r": "0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e", - "s": "0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a", - "to": "0xeb610a69341aace81ed810ed42428249512378cd", - "transactionIndex": 4, - "type": "eip1559", - "typeHex": "0x2", - "v": 1n, - "value": 105n, - } - `) - }) - - test('action', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - - const transaction = await getTransaction(client, { - hash: '0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822', - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "accessList": [], - "blockHash": "0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574", - "blockNumber": 105848892n, - "chainId": 10, - "from": "0xacd03d601e5bb1b275bb94076ff46ed9d753435a", - "gas": 21000n, - "gasPrice": 267n, - "hash": "0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822", - "input": "0x", - "maxFeePerGas": 191000n, - "maxPriorityFeePerGas": 191n, - "nonce": 775017, - "r": "0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e", - "s": "0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a", - "to": "0xeb610a69341aace81ed810ed42428249512378cd", - "transactionIndex": 7, - "type": "eip1559", - "typeHex": "0x2", - "v": 1n, - "value": 650000000000000n, - } - `) - }) -}) - -describe('transaction (deposit)', () => { - test('formatter', () => { - const { transaction } = optimism.formatters! - - expect( - transaction.format({ - accessList: [], - blockHash: - '0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574', - blockNumber: '0x1', - chainId: '0x1', - from: '0xacd03d601e5bb1b275bb94076ff46ed9d753435a', - gas: '0x69', - hash: '0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822', - input: '0x', - maxFeePerGas: '0x1', - maxPriorityFeePerGas: '0x2', - nonce: '0x3', - r: '0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e', - s: '0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a', - sourceHash: '0x', - to: '0xeb610a69341aace81ed810ed42428249512378cd', - transactionIndex: '0x4', - type: '0x7e', - v: '0x1', - value: '0x69', - }), - ).toMatchInlineSnapshot(` - { - "accessList": [], - "blockHash": "0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574", - "blockNumber": 1n, - "chainId": 1, - "from": "0xacd03d601e5bb1b275bb94076ff46ed9d753435a", - "gas": 105n, - "gasPrice": undefined, - "hash": "0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822", - "input": "0x", - "isSystemTx": undefined, - "maxFeePerGas": 1n, - "maxPriorityFeePerGas": 2n, - "mint": undefined, - "nonce": 3, - "r": "0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e", - "s": "0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a", - "sourceHash": "0x", - "to": "0xeb610a69341aace81ed810ed42428249512378cd", - "transactionIndex": 4, - "type": "deposit", - "typeHex": "0x7e", - "v": 1n, - "value": 105n, - } - `) - }) - - test('action', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - - const transaction = await getTransaction(client, { - hash: '0x97f8e79b683df44ae2cc2e9f6eeebd2febdd6f0aeda71f184e6b297cbe7f620b', - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "blockHash": "0x7c04fe001ea0efd91d5eea232e6936a2b94af8d238e56f0e025d264a55e65a58", - "blockNumber": 105847831n, - "chainId": undefined, - "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", - "gas": 1000000n, - "gasPrice": 0n, - "hash": "0x97f8e79b683df44ae2cc2e9f6eeebd2febdd6f0aeda71f184e6b297cbe7f620b", - "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b62c6000000000000000000000000000000000000000000000000000000006492119f000000000000000000000000000000000000000000000000000000078e016aff6b099ac98f4d1e69a45ad7bccba81386deddee0569412aafb388d8c1510f9e0800000000000000000000000000000000000000000000000000000000000000020000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", - "isSystemTx": undefined, - "maxFeePerGas": undefined, - "maxPriorityFeePerGas": undefined, - "mint": 0n, - "nonce": 612767, - "r": "0x0", - "s": "0x0", - "sourceHash": "0x3fd7eb0bfa68ab126d745d17de615819430e1a6e922f65e5c06418569eb8dee1", - "to": "0x4200000000000000000000000000000000000015", - "transactionIndex": 0, - "type": "deposit", - "typeHex": "0x7e", - "v": 0n, - "value": 0n, - } - `) - }) -}) - -describe('transaction receipt', async () => { - test('formatter', () => { - const { transactionReceipt } = optimism.formatters! - - expect( - transactionReceipt.format({ - blockHash: - '0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0', - blockNumber: '0x1', - contractAddress: null, - cumulativeGasUsed: '0x1', - effectiveGasPrice: '0x1', - from: '0x24476ac81915c512b0e13207aa917923fba4a16a', - gasUsed: '0x42069', - l1Fee: '0x420', - l1FeeScalar: '1.5', - l1GasPrice: '0x69', - l1GasUsed: '0x1', - logs: [], - logsBloom: - '0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000', - status: '0x1', - to: '0xdd69db25f6d620a7bad3023c5d32761d353d3de9', - transactionHash: - '0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3', - transactionIndex: '0x1', - type: '0x2', - }), - ).toMatchInlineSnapshot(` - { - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 1n, - "contractAddress": null, - "cumulativeGasUsed": 1n, - "effectiveGasPrice": 1n, - "from": "0x24476ac81915c512b0e13207aa917923fba4a16a", - "gasUsed": 270441n, - "l1Fee": 1056n, - "l1FeeScalar": 1.5, - "l1GasPrice": 105n, - "l1GasUsed": 1n, - "logs": [], - "logsBloom": "0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000", - "status": "success", - "to": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 1, - "type": "eip1559", - } - `) - - expect( - transactionReceipt.format({ - blockHash: - '0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0', - blockNumber: '0x1', - contractAddress: null, - cumulativeGasUsed: '0x1', - effectiveGasPrice: '0x1', - from: '0x24476ac81915c512b0e13207aa917923fba4a16a', - gasUsed: '0x42069', - l1Fee: null, - l1FeeScalar: null, - l1GasPrice: null, - l1GasUsed: null, - logs: [], - logsBloom: - '0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000', - status: '0x1', - to: '0xdd69db25f6d620a7bad3023c5d32761d353d3de9', - transactionHash: - '0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3', - transactionIndex: '0x1', - type: '0x2', - }), - ).toMatchInlineSnapshot(` - { - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 1n, - "contractAddress": null, - "cumulativeGasUsed": 1n, - "effectiveGasPrice": 1n, - "from": "0x24476ac81915c512b0e13207aa917923fba4a16a", - "gasUsed": 270441n, - "l1Fee": null, - "l1FeeScalar": null, - "l1GasPrice": null, - "l1GasUsed": null, - "logs": [], - "logsBloom": "0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000", - "status": "success", - "to": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 1, - "type": "eip1559", - } - `) - }) - - test('action', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - - const transaction = await getTransactionReceipt(client, { - hash: '0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3', - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 106812538n, - "contractAddress": null, - "cumulativeGasUsed": 1431996n, - "effectiveGasPrice": 58n, - "from": "0x24476ac81915c512b0e13207aa917923fba4a16a", - "gasUsed": 228719n, - "l1Fee": 44700351261503n, - "l1FeeScalar": 0.684, - "l1GasPrice": 15694378178n, - "l1GasUsed": 4164n, - "logs": [ - { - "address": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 106812538n, - "data": "0x000000000000000000000000000000000000000000000000008e1bc9bf040000", - "logIndex": 19, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x00000000000000000000000024476ac81915c512b0e13207aa917923fba4a16a", - "0x0000000000000000000000000000000000000000000000000000000000000000", - ], - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 10, - }, - { - "address": "0x81e792e5a9003cc1c8bf5569a00f34b65d75b017", - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 106812538n, - "data": "0x000000000000000000000000000000000000000000000000000031a1add99f8b", - "logIndex": 20, - "removed": false, - "topics": [ - "0xdf21c415b78ed2552cc9971249e32a053abce6087a0ae0fbf3f78db5174a3493", - ], - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 10, - }, - { - "address": "0x4d73adb72bc3dd368966edd0f0b2148401a178e2", - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 106812538n, - "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002200010000000000000000000000000000000000000000000000000000000000030d40000000000000000000000000000000000000000000000000000000000000", - "logIndex": 21, - "removed": false, - "topics": [ - "0xb0c632f55f1e1b3b2c3d82f41ee4716bb4c00f0f5d84cdafc141581bb8757a4f", - ], - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 10, - }, - { - "address": "0xa0cc33dd6f4819d473226257792afe230ec3c67f", - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 106812538n, - "data": "0x000000000000000000000000000000000000000000000000000000000000009a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000014000000000000000000000000dd69db25f6d620a7bad3023c5d32761d353d3de90000000000000000000000000000000000000000000000000000000124c9d6c5", - "logIndex": 22, - "removed": false, - "topics": [ - "0x4e41ee13e03cd5e0446487b524fdc48af6acf26c074dacdbdfb6b574b42c8146", - ], - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 10, - }, - { - "address": "0x4d73adb72bc3dd368966edd0f0b2148401a178e2", - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 106812538n, - "data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000d40000000000049d1a006fdd69db25f6d620a7bad3023c5d32761d353d3de9009a4f7a67464b5976d7547c860109e4432d50afb38e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000008e1bc9bf040000000000000000000000000000000000000000000000000000000000000000001424476ac81915c512b0e13207aa917923fba4a16a000000000000000000000000000000000000000000000000", - "logIndex": 23, - "removed": false, - "topics": [ - "0xe9bded5f24a4168e4f3bf44e00298c993b22376aad8c58c7dda9718a54cbea82", - ], - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 10, - }, - { - "address": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", - "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", - "blockNumber": 106812538n, - "data": "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000008e1bc9bf040000000000000000000000000000000000000000000000000000000000000000001424476ac81915c512b0e13207aa917923fba4a16a000000000000000000000000", - "logIndex": 24, - "removed": false, - "topics": [ - "0x39a4c66499bcf4b56d79f0dde8ed7a9d4925a0df55825206b2b8531e202be0d0", - "0x000000000000000000000000000000000000000000000000000000000000009a", - "0x00000000000000000000000024476ac81915c512b0e13207aa917923fba4a16a", - ], - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 10, - }, - ], - "logsBloom": "0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000", - "status": "success", - "to": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", - "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", - "transactionIndex": 10, - "type": "eip1559", - } - `) - }) -}) diff --git a/src/chains/optimism/formatters.ts b/src/chains/optimism/formatters.ts deleted file mode 100644 index ea5f2283cd..0000000000 --- a/src/chains/optimism/formatters.ts +++ /dev/null @@ -1,74 +0,0 @@ -import type { Hash } from '../../types/misc.js' -import { type RpcTransaction } from '../../types/rpc.js' -import { hexToBigInt } from '../../utils/encoding/fromHex.js' -import { defineBlock } from '../../utils/formatters/block.js' -import { - defineTransaction, - formatTransaction, -} from '../../utils/formatters/transaction.js' -import { defineTransactionReceipt } from '../../utils/formatters/transactionReceipt.js' -import { type ChainFormatters } from '../types.js' -import type { - OptimismBlockOverrides, - OptimismRpcBlockOverrides, - OptimismRpcTransaction, - OptimismRpcTransactionReceiptOverrides, - OptimismTransaction, - OptimismTransactionReceiptOverrides, -} from './types.js' - -export const formattersOptimism = { - block: /*#__PURE__*/ defineBlock({ - format( - args: OptimismRpcBlockOverrides & { - transactions: Hash[] | OptimismRpcTransaction[] - }, - ): OptimismBlockOverrides & { - transactions: Hash[] | OptimismTransaction[] - } { - const transactions = args.transactions?.map((transaction) => { - if (typeof transaction === 'string') return transaction - const formatted = formatTransaction( - transaction as RpcTransaction, - ) as OptimismTransaction - if (formatted.typeHex === '0x7e') { - formatted.isSystemTx = transaction.isSystemTx - formatted.mint = transaction.mint - ? hexToBigInt(transaction.mint) - : undefined - formatted.sourceHash = transaction.sourceHash - formatted.type = 'deposit' - } - return formatted - }) as Hash[] | OptimismTransaction[] - return { - transactions, - stateRoot: args.stateRoot, - } - }, - }), - transaction: /*#__PURE__*/ defineTransaction({ - format(args: OptimismRpcTransaction): OptimismTransaction { - const transaction = {} as OptimismTransaction - if (args.type === '0x7e') { - transaction.isSystemTx = args.isSystemTx - transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined - transaction.sourceHash = args.sourceHash - transaction.type = 'deposit' - } - return transaction - }, - }), - transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({ - format( - args: OptimismRpcTransactionReceiptOverrides, - ): OptimismTransactionReceiptOverrides { - return { - l1GasPrice: args.l1GasPrice ? hexToBigInt(args.l1GasPrice) : null, - l1GasUsed: args.l1GasUsed ? hexToBigInt(args.l1GasUsed) : null, - l1Fee: args.l1Fee ? hexToBigInt(args.l1Fee) : null, - l1FeeScalar: args.l1FeeScalar ? Number(args.l1FeeScalar) : null, - } - }, - }), -} as const satisfies ChainFormatters diff --git a/src/chains/optimism/types.ts b/src/chains/optimism/types.ts deleted file mode 100644 index 4c89f3e249..0000000000 --- a/src/chains/optimism/types.ts +++ /dev/null @@ -1,102 +0,0 @@ -import type { Block, BlockTag } from '../../types/block.js' -import type { FeeValuesEIP1559 } from '../../types/fee.js' -import type { Hash, Hex } from '../../types/misc.js' -import type { - Index, - Quantity, - RpcBlock, - RpcTransaction as RpcTransaction_, - RpcTransactionReceipt, -} from '../../types/rpc.js' -import type { - Transaction as Transaction_, - TransactionBase, - TransactionReceipt, -} from '../../types/transaction.js' - -export type OptimismBlockOverrides = { - stateRoot: Hash -} -export type OptimismBlock< - TIncludeTransactions extends boolean = boolean, - TBlockTag extends BlockTag = BlockTag, -> = Block< - bigint, - TIncludeTransactions, - TBlockTag, - OptimismTransaction -> & - OptimismBlockOverrides - -export type OptimismRpcBlockOverrides = { - stateRoot: Hash -} -export type OptimismRpcBlock< - TBlockTag extends BlockTag = BlockTag, - TIncludeTransactions extends boolean = boolean, -> = RpcBlock< - TBlockTag, - TIncludeTransactions, - OptimismRpcTransaction -> & - OptimismRpcBlockOverrides - -type RpcTransaction = - RpcTransaction_ & { - isSystemTx?: undefined - mint?: undefined - sourceHash?: undefined - } - -export type OptimismRpcDepositTransaction = - Omit, 'typeHex'> & - FeeValuesEIP1559 & { - isSystemTx?: boolean - mint?: Hex - sourceHash: Hex - type: '0x7e' - } -export type OptimismRpcTransaction = - | RpcTransaction - | OptimismRpcDepositTransaction - -export type OptimismRpcTransactionReceiptOverrides = { - l1GasPrice: Hex | null - l1GasUsed: Hex | null - l1Fee: Hex | null - l1FeeScalar: `${number}` | null -} -export type OptimismRpcTransactionReceipt = RpcTransactionReceipt & - OptimismRpcTransactionReceiptOverrides - -type Transaction = Transaction_< - bigint, - number, - TPending -> & { - isSystemTx?: undefined - mint?: undefined - sourceHash?: undefined -} - -export type OptimismDepositTransaction = - TransactionBase & - FeeValuesEIP1559 & { - isSystemTx?: boolean - mint?: bigint - sourceHash: Hex - type: 'deposit' - } - -export type OptimismTransaction = - | Transaction - | OptimismDepositTransaction - -export type OptimismTransactionReceiptOverrides = { - l1GasPrice: bigint | null - l1GasUsed: bigint | null - l1Fee: bigint | null - l1FeeScalar: number | null -} -export type OptimismTransactionReceipt = TransactionReceipt & - OptimismTransactionReceiptOverrides diff --git a/src/chains/types.ts b/src/chains/types.ts deleted file mode 100644 index fbdf80d4a4..0000000000 --- a/src/chains/types.ts +++ /dev/null @@ -1,165 +0,0 @@ -import type { Address } from 'abitype' - -import type { EstimateFeesPerGasReturnType } from '../actions/public/estimateFeesPerGas.js' -import type { Client } from '../clients/createClient.js' -import type { Transport } from '../clients/transports/createTransport.js' -import type { Account } from '../types/account.js' -import type { FeeValuesType } from '../types/fee.js' -import type { - TransactionSerializable, - TransactionSerializableGeneric, -} from '../types/transaction.js' -import type { Prettify } from '../types/utils.js' -import type { FormattedBlock } from '../utils/formatters/block.js' -import type { PrepareRequestParameters } from '../utils/transaction/prepareRequest.js' -import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js' - -export type Chain< - formatters extends ChainFormatters | undefined = ChainFormatters | undefined, -> = import('@wagmi/chains').Chain & ChainConfig - -export type ChainConfig< - formatters extends ChainFormatters | undefined = ChainFormatters | undefined, -> = { - /** - * Modifies how chain data structures (ie. Blocks, Transactions, etc) - * are formatted & typed. - */ - formatters?: formatters | undefined - /** Modifies how data (ie. Transactions) is serialized. */ - serializers?: ChainSerializers | undefined - /** Modifies how fees are derived. */ - fees?: ChainFees | undefined -} - -export type ChainContract = { - address: Address - blockCreated?: number -} - -export type ChainFees< - formatters extends ChainFormatters | undefined = ChainFormatters | undefined, -> = { - /** - * The fee multiplier to use to account for fee fluctuations. - * Used in the [`estimateFeesPerGas` Action](/docs/actions/public/estimateFeesPerGas). - * - * @default 1.2 - */ - baseFeeMultiplier?: - | number - | ((args: ChainFeesFnParameters) => Promise | number) - /** - * The default `maxPriorityFeePerGas` to use when a priority - * fee is not defined upon sending a transaction. - * - * Overrides the return value in the [`estimateMaxPriorityFeePerGas` Action](/docs/actions/public/estimateMaxPriorityFeePerGas). - */ - defaultPriorityFee?: - | bigint - | ((args: ChainFeesFnParameters) => Promise | bigint) - /** - * Allows customization of fee per gas values (e.g. `maxFeePerGas`/`maxPriorityFeePerGas`). - * - * Overrides the return value in the [`estimateFeesPerGas` Action](/docs/actions/public/estimateFeesPerGas). - */ - estimateFeesPerGas?: ( - args: ChainEstimateFeesPerGasFnParameters, - ) => Promise | bigint -} - -export type ChainFormatters = { - /** Modifies how the Block structure is formatted & typed. */ - block?: ChainFormatter<'block'> - /** Modifies how the Transaction structure is formatted & typed. */ - transaction?: ChainFormatter<'transaction'> - /** Modifies how the TransactionReceipt structure is formatted & typed. */ - transactionReceipt?: ChainFormatter<'transactionReceipt'> - /** Modifies how the TransactionRequest structure is formatted & typed. */ - transactionRequest?: ChainFormatter<'transactionRequest'> -} - -export type ChainFormatter = { - format: (args: any) => any - type: type -} - -export type ChainSerializers< - formatters extends ChainFormatters | undefined = undefined, -> = { - /** Modifies how Transactions are serialized. */ - transaction?: SerializeTransactionFn< - formatters extends ChainFormatters - ? formatters['transactionRequest'] extends ChainFormatter - ? TransactionSerializableGeneric & - Parameters[0] - : TransactionSerializable - : TransactionSerializable - > -} - -///////////////////////////////////////////////////////////////////// -// Parameters - -export type ChainFeesFnParameters< - formatters extends ChainFormatters | undefined = ChainFormatters | undefined, -> = { - /** The latest block. */ - block: Prettify> - client: Client - /** - * A transaction request. This value will be undefined if the caller - * is outside of a transaction request context (e.g. a direct call to - * the `estimateFeesPerGas` Action). - */ - request?: PrepareRequestParameters< - Omit & { formatters: formatters }, - Account | undefined, - undefined - > -} - -export type ChainEstimateFeesPerGasFnParameters< - formatters extends ChainFormatters | undefined = ChainFormatters | undefined, -> = { - /** - * A function to multiply the base fee based on the `baseFeeMultiplier` value. - */ - multiply(x: bigint): bigint - /** - * The type of fees to return. - */ - type: FeeValuesType -} & ChainFeesFnParameters - -///////////////////////////////////////////////////////////////////// -// Utils - -export type ExtractChainFormatterExclude< - chain extends { formatters?: Chain['formatters'] } | undefined, - type extends keyof ChainFormatters, -> = chain extends { formatters?: infer _Formatters extends ChainFormatters } - ? _Formatters[type] extends { exclude: infer Exclude } - ? Extract[number] - : '' - : '' - -export type ExtractChainFormatterParameters< - chain extends { formatters?: Chain['formatters'] } | undefined, - type extends keyof ChainFormatters, - fallback, -> = chain extends { formatters?: infer _Formatters extends ChainFormatters } - ? _Formatters[type] extends ChainFormatter - ? Parameters<_Formatters[type]['format']>[0] - : fallback - : fallback - -export type ExtractChainFormatterReturnType< - chain extends { formatters?: Chain['formatters'] } | undefined, - type extends keyof ChainFormatters, - fallback, -> = chain extends { formatters?: infer _Formatters extends ChainFormatters } - ? _Formatters[type] extends ChainFormatter - ? ReturnType<_Formatters[type]['format']> - : fallback - : fallback diff --git a/src/chains/utils.test.ts b/src/chains/utils.test.ts deleted file mode 100644 index 70276852f9..0000000000 --- a/src/chains/utils.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expect, test } from 'vitest' - -import * as utils from './utils.js' - -test('exports', () => { - expect(Object.keys(utils)).toMatchInlineSnapshot(` - [ - "formattersCelo", - "serializeTransactionCelo", - "serializersCelo", - "formattersOptimism", - ] - `) -}) diff --git a/src/chains/utils.ts b/src/chains/utils.ts index d1764ebf82..a4c38f7482 100644 --- a/src/chains/utils.ts +++ b/src/chains/utils.ts @@ -1,45 +1,41 @@ -export { formattersCelo } from './celo/formatters.js' export { + type CeloBlock, + type CeloBlockOverrides, + type CeloRpcBlock, + type CeloRpcBlockOverrides, + type CeloRpcTransaction, + type CeloRpcTransactionOverrides, + type CeloRpcTransactionReceipt, + type CeloRpcTransactionReceiptOverrides, + type CeloRpcTransactionRequest, + type CeloRpcTransactionRequestOverrides, + type CeloTransaction, + type CeloTransactionOverrides, + type CeloTransactionReceipt, + type CeloTransactionReceiptOverrides, + type CeloTransactionRequest, + type CeloTransactionRequestOverrides, + type CeloTransactionSerializable, + type CeloTransactionSerialized, + type CeloTransactionType, + type OptimismBlock, + type OptimismBlockOverrides, + type OptimismDepositTransaction, + type OptimismRpcBlock, + type OptimismRpcBlockOverrides, + type OptimismRpcDepositTransaction, + type OptimismRpcTransaction, + type OptimismRpcTransactionReceipt, + type OptimismRpcTransactionReceiptOverrides, + type OptimismTransaction, + type OptimismTransactionReceipt, + type OptimismTransactionReceiptOverrides, + type TransactionSerializableCIP42, + type TransactionSerializedCIP42, + formattersCelo, + formattersOptimism, + parseTransactionCelo, serializeTransactionCelo, serializersCelo, -} from './celo/serializers.js' -export { parseTransactionCelo } from './celo/parsers.js' -export type { - CeloBlock, - CeloBlockOverrides, - CeloRpcBlock, - CeloRpcBlockOverrides, - CeloRpcTransaction, - CeloRpcTransactionOverrides, - CeloRpcTransactionReceipt, - CeloRpcTransactionReceiptOverrides, - CeloRpcTransactionRequest, - CeloRpcTransactionRequestOverrides, - CeloTransaction, - CeloTransactionOverrides, - CeloTransactionReceipt, - CeloTransactionReceiptOverrides, - CeloTransactionRequest, - CeloTransactionRequestOverrides, - CeloTransactionSerializable, - CeloTransactionSerialized, - CeloTransactionType, - TransactionSerializableCIP42, - TransactionSerializedCIP42, -} from './celo/types.js' - -export { formattersOptimism } from './optimism/formatters.js' -export type { - OptimismBlock, - OptimismBlockOverrides, - OptimismDepositTransaction, - OptimismRpcBlock, - OptimismRpcBlockOverrides, - OptimismRpcDepositTransaction, - OptimismRpcTransaction, - OptimismRpcTransactionReceipt, - OptimismRpcTransactionReceiptOverrides, - OptimismTransaction, - OptimismTransactionReceipt, - OptimismTransactionReceiptOverrides, -} from './optimism/types.js' + defineChain, +} from '@viem/chains/utils' diff --git a/src/clients/createClient.test-d.ts b/src/clients/createClient.test-d.ts index 83758def39..db0b0c6629 100644 --- a/src/clients/createClient.test-d.ts +++ b/src/clients/createClient.test-d.ts @@ -1,4 +1,4 @@ -import { localhost } from '@wagmi/chains' +import { localhost } from '@viem/chains' import { expectTypeOf, test } from 'vitest' import type { JsonRpcAccount } from '../accounts/types.js' diff --git a/src/clients/createClient.test.ts b/src/clients/createClient.test.ts index f293ba8069..08e61aa30a 100644 --- a/src/clients/createClient.test.ts +++ b/src/clients/createClient.test.ts @@ -1,7 +1,6 @@ import { assertType, describe, expect, test, vi } from 'vitest' import { localWsUrl } from '../_test/constants.js' -import { localhost, mainnet } from '../chains/index.js' import type { EIP1193RequestFn, EIP1474Methods } from '../types/eip1193.js' import { createClient } from './createClient.js' import { publicActions } from './decorators/public.js' @@ -9,6 +8,7 @@ import { createTransport } from './transports/createTransport.js' import { custom } from './transports/custom.js' import { http } from './transports/http.js' import { webSocket } from './transports/webSocket.js' +import { localhost, mainnet } from '@viem/chains' test('creates', () => { const mockTransport = () => diff --git a/src/clients/createClient.ts b/src/clients/createClient.ts index 0dbb17f8e9..df4c14ddb3 100644 --- a/src/clients/createClient.ts +++ b/src/clients/createClient.ts @@ -1,7 +1,7 @@ +import type { Chain } from '@viem/chains' import type { Address } from 'abitype' import type { Account, JsonRpcAccount } from '../accounts/types.js' -import type { Chain } from '../chains/types.js' import type { EIP1193RequestFn, EIP1474Methods, diff --git a/src/clients/createPublicClient.test-d.ts b/src/clients/createPublicClient.test-d.ts index d0501668e9..7a99b139fd 100644 --- a/src/clients/createPublicClient.test-d.ts +++ b/src/clients/createPublicClient.test-d.ts @@ -1,4 +1,4 @@ -import { localhost } from '@wagmi/chains' +import { localhost } from '@viem/chains' import { expectTypeOf, test } from 'vitest' import { type PublicClient, createPublicClient } from './createPublicClient.js' diff --git a/src/clients/createPublicClient.test.ts b/src/clients/createPublicClient.test.ts index 71f88fc8db..0918f4759c 100644 --- a/src/clients/createPublicClient.test.ts +++ b/src/clients/createPublicClient.test.ts @@ -1,7 +1,6 @@ import { assertType, describe, expect, test, vi } from 'vitest' import { localWsUrl } from '../_test/constants.js' -import { localhost } from '../chains/index.js' import { type EIP1193RequestFn, type PublicRpcSchema } from '../index.js' import { createPublicClient } from './createPublicClient.js' import { testActions } from './decorators/test.js' @@ -10,6 +9,7 @@ import { createTransport } from './transports/createTransport.js' import { custom } from './transports/custom.js' import { http } from './transports/http.js' import { webSocket } from './transports/webSocket.js' +import { localhost } from '@viem/chains' const mockTransport = () => createTransport({ diff --git a/src/clients/createPublicClient.ts b/src/clients/createPublicClient.ts index 563ac262b7..934f683bdc 100644 --- a/src/clients/createPublicClient.ts +++ b/src/clients/createPublicClient.ts @@ -1,4 +1,5 @@ -import type { Chain } from '../chains/types.js' +import type { Chain } from '@viem/chains' + import type { PublicRpcSchema } from '../types/eip1193.js' import type { Prettify } from '../types/utils.js' import { type Client, type ClientConfig, createClient } from './createClient.js' diff --git a/src/clients/createTestClient.test-d.ts b/src/clients/createTestClient.test-d.ts index 8f06d5e3f5..0dd31629fe 100644 --- a/src/clients/createTestClient.test-d.ts +++ b/src/clients/createTestClient.test-d.ts @@ -1,4 +1,4 @@ -import { localhost } from '@wagmi/chains' +import { localhost } from '@viem/chains' import { expectTypeOf, test } from 'vitest' import { type TestClient, createTestClient } from './createTestClient.js' diff --git a/src/clients/createTestClient.test.ts b/src/clients/createTestClient.test.ts index 5e35ec6283..cacfccc4b4 100644 --- a/src/clients/createTestClient.test.ts +++ b/src/clients/createTestClient.test.ts @@ -1,7 +1,6 @@ import { assertType, describe, expect, test, vi } from 'vitest' import { accounts, localWsUrl } from '../_test/constants.js' -import { localhost } from '../chains/index.js' import { type EIP1193RequestFn, type TestRpcSchema } from '../index.js' import { createTestClient } from './createTestClient.js' import { publicActions } from './decorators/public.js' @@ -9,6 +8,7 @@ import { walletActions } from './decorators/wallet.js' import { createTransport } from './transports/createTransport.js' import { http } from './transports/http.js' import { webSocket } from './transports/webSocket.js' +import { localhost } from '@viem/chains' const mockTransport = () => createTransport({ diff --git a/src/clients/createTestClient.ts b/src/clients/createTestClient.ts index 736abb171c..cc4e4d35b7 100644 --- a/src/clients/createTestClient.ts +++ b/src/clients/createTestClient.ts @@ -1,11 +1,11 @@ import type { Account } from '../accounts/types.js' -import type { Chain } from '../chains/types.js' import type { ParseAccount } from '../types/account.js' import type { TestRpcSchema } from '../types/eip1193.js' import type { Prettify } from '../types/utils.js' import { type Client, type ClientConfig, createClient } from './createClient.js' import { type TestActions, testActions } from './decorators/test.js' import type { Transport } from './transports/createTransport.js' +import type { Chain } from '@viem/chains' import type { Address } from 'abitype' export type TestClientMode = 'anvil' | 'hardhat' | 'ganache' diff --git a/src/clients/createWalletClient.test-d.ts b/src/clients/createWalletClient.test-d.ts index 8883e1b19b..34104514b9 100644 --- a/src/clients/createWalletClient.test-d.ts +++ b/src/clients/createWalletClient.test-d.ts @@ -1,4 +1,4 @@ -import { localhost } from '@wagmi/chains' +import { localhost } from '@viem/chains' import { expectTypeOf, test } from 'vitest' diff --git a/src/clients/createWalletClient.test.ts b/src/clients/createWalletClient.test.ts index a3c406a37f..50b76b1757 100644 --- a/src/clients/createWalletClient.test.ts +++ b/src/clients/createWalletClient.test.ts @@ -3,7 +3,6 @@ import { assertType, describe, expect, test, vi } from 'vitest' import { accounts, localWsUrl } from '../_test/constants.js' import { privateKeyToAccount } from '../accounts/privateKeyToAccount.js' import type { JsonRpcAccount, PrivateKeyAccount } from '../accounts/types.js' -import { localhost } from '../chains/index.js' import type { EIP1193RequestFn, WalletRpcSchema } from '../types/eip1193.js' import { createWalletClient } from './createWalletClient.js' import { publicActions } from './decorators/public.js' @@ -12,6 +11,7 @@ import { createTransport } from './transports/createTransport.js' import { custom } from './transports/custom.js' import { http } from './transports/http.js' import { webSocket } from './transports/webSocket.js' +import { localhost } from '@viem/chains' const mockTransport = () => createTransport({ diff --git a/src/clients/createWalletClient.ts b/src/clients/createWalletClient.ts index 91350921d4..a08617e1c2 100644 --- a/src/clients/createWalletClient.ts +++ b/src/clients/createWalletClient.ts @@ -1,13 +1,13 @@ import type { Address } from 'abitype' import type { Account } from '../accounts/types.js' -import type { Chain } from '../chains/types.js' import type { ParseAccount } from '../types/account.js' import type { WalletRpcSchema } from '../types/eip1193.js' import type { Prettify } from '../types/utils.js' import { type Client, type ClientConfig, createClient } from './createClient.js' import { type WalletActions, walletActions } from './decorators/wallet.js' import type { Transport } from './transports/createTransport.js' +import type { Chain } from '@viem/chains' export type WalletClientConfig< transport extends Transport = Transport, diff --git a/src/clients/decorators/public.ts b/src/clients/decorators/public.ts index c538f7ff62..b8567b8313 100644 --- a/src/clients/decorators/public.ts +++ b/src/clients/decorators/public.ts @@ -1,3 +1,4 @@ +import type { Chain } from '@viem/chains' import type { Abi, AbiEvent } from 'abitype' import { @@ -206,7 +207,6 @@ import { type WatchPendingTransactionsReturnType, watchPendingTransactions, } from '../../actions/public/watchPendingTransactions.js' -import type { Chain } from '../../chains/types.js' import type { Account } from '../../types/account.js' import type { BlockNumber, BlockTag } from '../../types/block.js' import type { diff --git a/src/clients/decorators/test.ts b/src/clients/decorators/test.ts index 7e8db28102..98bd0bbf7e 100644 --- a/src/clients/decorators/test.ts +++ b/src/clients/decorators/test.ts @@ -84,12 +84,12 @@ import { type StopImpersonatingAccountParameters, stopImpersonatingAccount, } from '../../actions/test/stopImpersonatingAccount.js' -import type { Chain } from '../../chains/types.js' import type { Account } from '../../types/account.js' import type { Quantity } from '../../types/rpc.js' import type { Client } from '../createClient.js' import type { TestClientMode } from '../createTestClient.js' import type { Transport } from '../transports/createTransport.js' +import type { Chain } from '@viem/chains' export type TestActions = { /** diff --git a/src/clients/decorators/wallet.test.ts b/src/clients/decorators/wallet.test.ts index 585e4321c7..6872814f25 100644 --- a/src/clients/decorators/wallet.test.ts +++ b/src/clients/decorators/wallet.test.ts @@ -3,8 +3,8 @@ import { describe, expect, test } from 'vitest' import { baycContractConfig, wagmiContractConfig } from '../../_test/abis.js' import { accounts } from '../../_test/constants.js' import { walletClient, walletClientWithAccount } from '../../_test/utils.js' -import { avalanche } from '../../chains/index.js' import { parseEther } from '../../utils/unit/parseEther.js' +import { avalanche } from '@viem/chains' import { walletActions } from './wallet.js' diff --git a/src/clients/decorators/wallet.ts b/src/clients/decorators/wallet.ts index 1c8f774bb7..ad972cf594 100644 --- a/src/clients/decorators/wallet.ts +++ b/src/clients/decorators/wallet.ts @@ -60,9 +60,9 @@ import { type WriteContractReturnType, writeContract, } from '../../actions/wallet/writeContract.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../createClient.js' import type { Transport } from '../transports/createTransport.js' +import type { Chain } from '@viem/chains' export type WalletActions< TChain extends Chain | undefined = Chain | undefined, diff --git a/src/clients/transports/createTransport.ts b/src/clients/transports/createTransport.ts index e62397b529..a45b4c6a30 100644 --- a/src/clients/transports/createTransport.ts +++ b/src/clients/transports/createTransport.ts @@ -1,7 +1,7 @@ -import type { Chain } from '../../chains/types.js' import type { EIP1193RequestFn } from '../../types/eip1193.js' import { buildRequest } from '../../utils/buildRequest.js' import type { ClientConfig } from '../createClient.js' +import type { Chain } from '@viem/chains' export type TransportConfig< TType extends string = string, diff --git a/src/clients/transports/fallback.test.ts b/src/clients/transports/fallback.test.ts index 5978b0b51e..49cc6dae5b 100644 --- a/src/clients/transports/fallback.test.ts +++ b/src/clients/transports/fallback.test.ts @@ -2,10 +2,10 @@ import { assertType, describe, expect, test } from 'vitest' import { createHttpServer } from '../../_test/utils.js' import { getBlockNumber } from '../../actions/public/getBlockNumber.js' -import { localhost } from '../../chains/index.js' import { wait } from '../../utils/wait.js' import { createClient } from '../createClient.js' import { createPublicClient } from '../createPublicClient.js' +import { localhost } from '@viem/chains' import type { Transport } from './createTransport.js' import { diff --git a/src/clients/transports/fallback.ts b/src/clients/transports/fallback.ts index 5aa70eada1..7d1c2301db 100644 --- a/src/clients/transports/fallback.ts +++ b/src/clients/transports/fallback.ts @@ -1,6 +1,6 @@ -import type { Chain } from '../../chains/types.js' import { isDeterministicError } from '../../utils/buildRequest.js' import { wait } from '../../utils/wait.js' +import type { Chain } from '@viem/chains' import { type Transport, diff --git a/src/clients/transports/http.test.ts b/src/clients/transports/http.test.ts index 8746c6e509..4cd45d9435 100644 --- a/src/clients/transports/http.test.ts +++ b/src/clients/transports/http.test.ts @@ -2,8 +2,8 @@ import { assertType, describe, expect, test } from 'vitest' import { localHttpUrl } from '../../_test/constants.js' import { createHttpServer } from '../../_test/utils.js' -import { localhost } from '../../chains/index.js' import { wait } from '../../utils/wait.js' +import { localhost } from '@viem/chains' import { type HttpTransport, http } from './http.js' import type { IncomingHttpHeaders } from 'http' diff --git a/src/clients/transports/webSocket.test.ts b/src/clients/transports/webSocket.test.ts index ecb93d67a3..f3bb6fa3f2 100644 --- a/src/clients/transports/webSocket.test.ts +++ b/src/clients/transports/webSocket.test.ts @@ -3,8 +3,8 @@ import { WebSocket } from 'isomorphic-ws' import { assertType, describe, expect, test } from 'vitest' import { localWsUrl } from '../../_test/constants.js' -import { localhost } from '../../chains/index.js' import { wait } from '../../utils/wait.js' +import { localhost } from '@viem/chains' import { type WebSocketTransport, webSocket } from './webSocket.js' diff --git a/src/errors/chain.test.ts b/src/errors/chain.test.ts index e1b4e0f289..8ef156c663 100644 --- a/src/errors/chain.test.ts +++ b/src/errors/chain.test.ts @@ -1,6 +1,6 @@ import { expect, test } from 'vitest' -import { mainnet } from '../chains/index.js' +import { mainnet } from '@viem/chains' import { ChainDoesNotSupportContract, diff --git a/src/errors/chain.ts b/src/errors/chain.ts index d65e2aa689..e99e4f553e 100644 --- a/src/errors/chain.ts +++ b/src/errors/chain.ts @@ -1,4 +1,4 @@ -import type { Chain } from '../chains/types.js' +import type { Chain } from '@viem/chains' import { BaseError } from './base.js' diff --git a/src/errors/contract.test.ts b/src/errors/contract.test.ts index 81d2c912a4..288dc54295 100644 --- a/src/errors/contract.test.ts +++ b/src/errors/contract.test.ts @@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest' import { baycContractConfig } from '../_test/abis.js' import { address } from '../_test/constants.js' import { errorsExampleABI } from '../_test/generated.js' -import { polygon } from '../chains/index.js' +import { polygon } from '@viem/chains' import { BaseError } from './base.js' import { diff --git a/src/errors/contract.ts b/src/errors/contract.ts index ec116b4a65..c5b2a43961 100644 --- a/src/errors/contract.ts +++ b/src/errors/contract.ts @@ -2,7 +2,6 @@ import type { Abi, Address } from 'abitype' import { parseAccount } from '../accounts/utils/parseAccount.js' import type { CallParameters } from '../actions/public/call.js' -import type { Chain } from '../chains/types.js' import { panicReasons } from '../constants/solidity.js' import type { Hex } from '../types/misc.js' import { @@ -14,6 +13,7 @@ import { formatAbiItemWithArgs } from '../utils/abi/formatAbiItemWithArgs.js' import { getAbiItem } from '../utils/abi/getAbiItem.js' import { formatEther } from '../utils/unit/formatEther.js' import { formatGwei } from '../utils/unit/formatGwei.js' +import type { Chain } from '@viem/chains' import { AbiErrorSignatureNotFoundError } from './abi.js' import { BaseError } from './base.js' diff --git a/src/errors/estimateGas.test.ts b/src/errors/estimateGas.test.ts index 92250b0d24..e54e9703dd 100644 --- a/src/errors/estimateGas.test.ts +++ b/src/errors/estimateGas.test.ts @@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest' import { address } from '../_test/constants.js' import { parseAccount } from '../accounts/utils/parseAccount.js' -import { polygon } from '../chains/index.js' +import { polygon } from '@viem/chains' import { BaseError } from './base.js' import { EstimateGasExecutionError } from './estimateGas.js' diff --git a/src/errors/estimateGas.ts b/src/errors/estimateGas.ts index b254f98483..9e90a12730 100644 --- a/src/errors/estimateGas.ts +++ b/src/errors/estimateGas.ts @@ -1,8 +1,8 @@ import type { Account } from '../accounts/types.js' import type { EstimateGasParameters } from '../actions/public/estimateGas.js' -import type { Chain } from '../chains/types.js' import { formatEther } from '../utils/unit/formatEther.js' import { formatGwei } from '../utils/unit/formatGwei.js' +import type { Chain } from '@viem/chains' import { BaseError } from './base.js' import { prettyPrint } from './transaction.js' diff --git a/src/errors/transaction.test.ts b/src/errors/transaction.test.ts index d4decc5e42..7ac46daeeb 100644 --- a/src/errors/transaction.test.ts +++ b/src/errors/transaction.test.ts @@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest' import { address } from '../_test/constants.js' import { parseAccount } from '../accounts/utils/parseAccount.js' -import { polygon } from '../chains/index.js' +import { polygon } from '@viem/chains' import { BaseError } from './base.js' import { diff --git a/src/errors/transaction.ts b/src/errors/transaction.ts index 6f6d7550fb..02e69fd8a3 100644 --- a/src/errors/transaction.ts +++ b/src/errors/transaction.ts @@ -1,11 +1,11 @@ import type { Account } from '../accounts/types.js' import type { SendTransactionParameters } from '../actions/wallet/sendTransaction.js' -import type { Chain } from '../chains/types.js' import type { BlockTag } from '../types/block.js' import type { Hash, Hex } from '../types/misc.js' import type { TransactionType } from '../types/transaction.js' import { formatEther } from '../utils/unit/formatEther.js' import { formatGwei } from '../utils/unit/formatGwei.js' +import type { Chain } from '@viem/chains' import { BaseError } from './base.js' diff --git a/src/index.ts b/src/index.ts index c2766ff282..a5c5605bc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,26 @@ +export type { + Chain, + ChainContract, + ChainFees, + ChainFormatter, + /** @deprecated use `ChainFormatter` instead. */ + ChainFormatter as Formatter, + ChainFormatters, + /** @deprecated use `ChainFormatters` instead. */ + ChainFormatters as Formatters, + ChainSerializers, + /** @deprecated use `ChainSerializers` instead. */ + ChainSerializers as Serializers, + ExtractChainFormatterExclude, + /** @deprecated use `ExtractChainFormatterExclude` instead. */ + ExtractChainFormatterExclude as ExtractFormatterExclude, + ExtractChainFormatterParameters, + /** @deprecated use `ExtractChainFormatterParameters` instead. */ + ExtractChainFormatterParameters as ExtractFormatterParameters, + ExtractChainFormatterReturnType, + /** @deprecated use `ExtractChainFormatterReturnType` instead. */ + ExtractChainFormatterReturnType as ExtractFormatterReturnType, +} from '@viem/chains' export { type Abi, type Address, @@ -253,29 +276,6 @@ export type { WriteContractParameters, WriteContractReturnType, } from './actions/wallet/writeContract.js' -export type { - Chain, - ChainContract, - ChainFees, - ChainFormatter, - /** @deprecated use `ChainFormatter` instead. */ - ChainFormatter as Formatter, - ChainFormatters, - /** @deprecated use `ChainFormatters` instead. */ - ChainFormatters as Formatters, - ChainSerializers, - /** @deprecated use `ChainSerializers` instead. */ - ChainSerializers as Serializers, - ExtractChainFormatterExclude, - /** @deprecated use `ExtractChainFormatterExclude` instead. */ - ExtractChainFormatterExclude as ExtractFormatterExclude, - ExtractChainFormatterParameters, - /** @deprecated use `ExtractChainFormatterParameters` instead. */ - ExtractChainFormatterParameters as ExtractFormatterParameters, - ExtractChainFormatterReturnType, - /** @deprecated use `ExtractChainFormatterReturnType` instead. */ - ExtractChainFormatterReturnType as ExtractFormatterReturnType, -} from './chains/types.js' export { type Client, type ClientConfig, @@ -579,6 +579,7 @@ export type { TransactionSerializableBase, TransactionSerializableEIP1559, TransactionSerializableEIP2930, + TransactionSerializableGeneric, TransactionSerializableLegacy, TransactionSerialized, TransactionSerializedEIP1559, @@ -677,7 +678,6 @@ export { labelhash } from './utils/ens/labelhash.js' export { namehash } from './utils/ens/namehash.js' export { type FormattedBlock, - defineBlock, formatBlock, } from './utils/formatters/block.js' export { formatLog } from './utils/formatters/log.js' @@ -735,17 +735,15 @@ export { } from './utils/abi/encodeFunctionResult.js' export { type FormattedTransaction, - defineTransaction, formatTransaction, transactionType, } from './utils/formatters/transaction.js' export { type FormattedTransactionReceipt, - defineTransactionReceipt, + formatTransactionReceipt, } from './utils/formatters/transactionReceipt.js' export { type FormattedTransactionRequest, - defineTransactionRequest, formatTransactionRequest, } from './utils/formatters/transactionRequest.js' export { @@ -878,7 +876,11 @@ export { toTransactionArray, } from './utils/transaction/parseTransaction.js' export { parseUnits } from './utils/unit/parseUnits.js' -export { prepareRequest } from './utils/transaction/prepareRequest.js' +export { + type PrepareRequestParameters, + type PrepareRequestReturnType, + prepareRequest, +} from './utils/transaction/prepareRequest.js' export { serializeAccessList } from './utils/transaction/serializeAccessList.js' export { serializeTransaction, diff --git a/src/internal.ts b/src/internal.ts index da1f05df59..c9e053eb59 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -1 +1 @@ -export type { Assign, NeverBy } from './types/utils.js' +export type { Assign, NeverBy, Prettify } from './types/utils.js' diff --git a/src/types/chain.ts b/src/types/chain.ts index 0dfef33412..bf0f65ec85 100644 --- a/src/types/chain.ts +++ b/src/types/chain.ts @@ -1,5 +1,5 @@ -import type { Chain } from '../chains/types.js' import type { IsUndefined } from './utils.js' +import type { Chain } from '@viem/chains' export type GetChain< chain extends Chain | undefined, diff --git a/src/utils/ccip.ts b/src/utils/ccip.ts index d6e45e7127..7349807cd3 100644 --- a/src/utils/ccip.ts +++ b/src/utils/ccip.ts @@ -1,7 +1,6 @@ import type { Abi, Address } from 'abitype' import { type CallParameters, call } from '../actions/public/call.js' -import type { Chain } from '../chains/types.js' import type { Transport } from '../clients/transports/createTransport.js' import { type BaseError } from '../errors/base.js' import { @@ -12,6 +11,7 @@ import { import { HttpRequestError } from '../errors/request.js' import type { GetErrorArgs } from '../types/contract.js' import type { Hex } from '../types/misc.js' +import type { Chain } from '@viem/chains' import type { Client } from '../clients/createClient.js' import { decodeErrorResult } from './abi/decodeErrorResult.js' diff --git a/src/utils/chain.test.ts b/src/utils/chain.test.ts index 1f2280b8db..007a997cfc 100644 --- a/src/utils/chain.test.ts +++ b/src/utils/chain.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from 'vitest' -import { mainnet, optimism, polygon } from '../chains/index.js' +import { mainnet, optimism, polygon } from '@viem/chains' import { assertCurrentChain, diff --git a/src/utils/chain.ts b/src/utils/chain.ts index 1eacf2d4b5..ec7364a7f1 100644 --- a/src/utils/chain.ts +++ b/src/utils/chain.ts @@ -1,15 +1,15 @@ -import type { - Chain, - ChainConfig, - ChainContract, - ChainFormatters, -} from '../chains/types.js' import { ChainDoesNotSupportContract, ChainMismatchError, ChainNotFoundError, } from '../errors/chain.js' import type { Assign } from '../types/utils.js' +import type { + Chain, + ChainConfig, + ChainContract, + ChainFormatters, +} from '@viem/chains' export type AssertCurrentChainParameters = { chain?: Chain diff --git a/src/utils/ens/avatar/parseAvatarRecord.ts b/src/utils/ens/avatar/parseAvatarRecord.ts index 011b8eb950..890906bf6c 100644 --- a/src/utils/ens/avatar/parseAvatarRecord.ts +++ b/src/utils/ens/avatar/parseAvatarRecord.ts @@ -1,7 +1,7 @@ -import type { Chain } from '../../../chains/types.js' import type { Client } from '../../../clients/createClient.js' import type { Transport } from '../../../clients/transports/createTransport.js' import type { AssetGatewayUrls } from '../../../types/ens.js' +import type { Chain } from '@viem/chains' import { getJsonImage, diff --git a/src/utils/ens/avatar/utils.ts b/src/utils/ens/avatar/utils.ts index 355cf5ba41..7bd33eac94 100644 --- a/src/utils/ens/avatar/utils.ts +++ b/src/utils/ens/avatar/utils.ts @@ -1,7 +1,6 @@ import type { Address } from 'abitype' import { readContract } from '../../../actions/public/readContract.js' -import type { Chain } from '../../../chains/types.js' import type { Client } from '../../../clients/createClient.js' import type { Transport } from '../../../clients/transports/createTransport.js' import { @@ -11,6 +10,7 @@ import { EnsAvatarUriResolutionError, } from '../../../errors/ens.js' import type { AssetGatewayUrls } from '../../../types/ens.js' +import type { Chain } from '@viem/chains' type UriItem = { uri: string diff --git a/src/utils/errors/getCallError.ts b/src/utils/errors/getCallError.ts index 055567eac3..5156afdf90 100644 --- a/src/utils/errors/getCallError.ts +++ b/src/utils/errors/getCallError.ts @@ -1,7 +1,7 @@ import type { CallParameters } from '../../actions/public/call.js' -import type { Chain } from '../../chains/types.js' import type { BaseError } from '../../errors/base.js' import { CallExecutionError } from '../../errors/contract.js' +import type { Chain } from '@viem/chains' import { type GetNodeErrorParameters, diff --git a/src/utils/errors/getEstimateGasError.ts b/src/utils/errors/getEstimateGasError.ts index 31d14cddec..a934f41811 100644 --- a/src/utils/errors/getEstimateGasError.ts +++ b/src/utils/errors/getEstimateGasError.ts @@ -1,8 +1,8 @@ import type { Account } from '../../accounts/types.js' import type { EstimateGasParameters } from '../../actions/public/estimateGas.js' -import type { Chain } from '../../chains/types.js' import type { BaseError } from '../../errors/base.js' import { EstimateGasExecutionError } from '../../errors/estimateGas.js' +import type { Chain } from '@viem/chains' import { type GetNodeErrorParameters, diff --git a/src/utils/errors/getTransactionError.ts b/src/utils/errors/getTransactionError.ts index 9b0749521e..65d8a70757 100644 --- a/src/utils/errors/getTransactionError.ts +++ b/src/utils/errors/getTransactionError.ts @@ -1,8 +1,8 @@ import type { Account } from '../../accounts/types.js' import type { SendTransactionParameters } from '../../actions/wallet/sendTransaction.js' -import type { Chain } from '../../chains/types.js' import type { BaseError } from '../../errors/base.js' import { TransactionExecutionError } from '../../errors/transaction.js' +import type { Chain } from '@viem/chains' import { type GetNodeErrorParameters, diff --git a/src/utils/filters/createFilterRequestScope.ts b/src/utils/filters/createFilterRequestScope.ts index 6c784cecc9..d963ede0b0 100644 --- a/src/utils/filters/createFilterRequestScope.ts +++ b/src/utils/filters/createFilterRequestScope.ts @@ -1,4 +1,3 @@ -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import type { OnResponseFn } from '../../clients/transports/fallback.js' @@ -6,6 +5,7 @@ import type { PublicRpcSchema } from '../../types/eip1193.js' import type { EIP1193RequestFn } from '../../types/eip1193.js' import type { Hex } from '../../types/misc.js' import type { Filter } from '../../types/utils.js' +import type { Chain } from '@viem/chains' type CreateFilterRequestScopeParameters = { method: diff --git a/src/utils/formatters/block.ts b/src/utils/formatters/block.ts index 3598791a33..68c742970d 100644 --- a/src/utils/formatters/block.ts +++ b/src/utils/formatters/block.ts @@ -1,14 +1,13 @@ -import type { Chain } from '../../chains/types.js' -import type { - ExtractChainFormatterExclude, - ExtractChainFormatterReturnType, -} from '../../chains/types.js' import type { Block, BlockTag } from '../../types/block.js' import type { Hash } from '../../types/misc.js' import type { RpcBlock } from '../../types/rpc.js' import type { Prettify } from '../../types/utils.js' +import type { Chain } from '@viem/chains' +import type { + ExtractChainFormatterExclude, + ExtractChainFormatterReturnType, +} from '@viem/chains' -import { defineFormatter } from './formatter.js' import { type FormattedTransaction, formatTransaction } from './transaction.js' type BlockPendingDependencies = 'hash' | 'logsBloom' | 'nonce' | 'number' @@ -62,5 +61,3 @@ export function formatBlock(block: Partial) { : null, } as Block } - -export const defineBlock = /*#__PURE__*/ defineFormatter('block', formatBlock) diff --git a/src/utils/formatters/extract.ts b/src/utils/formatters/extract.ts index 23e58fb073..ffb7cf5777 100644 --- a/src/utils/formatters/extract.ts +++ b/src/utils/formatters/extract.ts @@ -1,4 +1,4 @@ -import type { ChainFormatter } from '../../chains/types.js' +import type { ChainFormatter } from '@viem/chains' /** * @description Picks out the keys from `value` that exist in the formatter. diff --git a/src/utils/formatters/formatter.ts b/src/utils/formatters/formatter.ts deleted file mode 100644 index 4c789cb689..0000000000 --- a/src/utils/formatters/formatter.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { Assign, Prettify } from '../../types/utils.js' - -export function defineFormatter( - type: TType, - format: (_: TParameters) => TReturnType, -) { - return < - TOverrideParameters, - TOverrideReturnType, - TExclude extends (keyof TParameters)[] = [], - >({ - exclude, - format: overrides, - }: { - exclude?: TExclude - format: (_: TOverrideParameters) => TOverrideReturnType - }) => { - return { - exclude, - format: (args: Assign) => { - const formatted = format(args as any) - if (exclude) { - for (const key of exclude) { - delete (formatted as any)[key] - } - } - return { - ...formatted, - ...overrides(args), - } as Prettify> & { - [K in TExclude[number]]: never - } - }, - type, - } - } -} diff --git a/src/utils/formatters/transaction.ts b/src/utils/formatters/transaction.ts index f0619e8113..6f3e1d2795 100644 --- a/src/utils/formatters/transaction.ts +++ b/src/utils/formatters/transaction.ts @@ -1,14 +1,13 @@ -import type { Chain } from '../../chains/types.js' -import type { - ExtractChainFormatterExclude, - ExtractChainFormatterReturnType, -} from '../../chains/types.js' import type { BlockTag } from '../../types/block.js' import type { RpcTransaction } from '../../types/rpc.js' import type { Transaction } from '../../types/transaction.js' import type { UnionOmit } from '../../types/utils.js' import { hexToNumber } from '../encoding/fromHex.js' -import { defineFormatter } from './formatter.js' +import type { Chain } from '@viem/chains' +import type { + ExtractChainFormatterExclude, + ExtractChainFormatterReturnType, +} from '@viem/chains' type TransactionPendingDependencies = | 'blockHash' @@ -78,8 +77,3 @@ export function formatTransaction(transaction: Partial) { } return transaction_ as Transaction } - -export const defineTransaction = /*#__PURE__*/ defineFormatter( - 'transaction', - formatTransaction, -) diff --git a/src/utils/formatters/transactionReceipt.ts b/src/utils/formatters/transactionReceipt.ts index 03695058bd..ff5deb5e4c 100644 --- a/src/utils/formatters/transactionReceipt.ts +++ b/src/utils/formatters/transactionReceipt.ts @@ -1,12 +1,8 @@ -import type { - Chain, - ExtractChainFormatterReturnType, -} from '../../chains/types.js' import type { RpcTransactionReceipt } from '../../types/rpc.js' import type { TransactionReceipt } from '../../types/transaction.js' import { hexToNumber } from '../encoding/fromHex.js' +import type { Chain, ExtractChainFormatterReturnType } from '@viem/chains' -import { defineFormatter } from './formatter.js' import { formatLog } from './log.js' import { transactionType } from './transaction.js' @@ -60,8 +56,3 @@ export function formatTransactionReceipt( : null, } as TransactionReceipt } - -export const defineTransactionReceipt = /*#__PURE__*/ defineFormatter( - 'transactionReceipt', - formatTransactionReceipt, -) diff --git a/src/utils/formatters/transactionRequest.ts b/src/utils/formatters/transactionRequest.ts index 62c0477d66..68f8ddf5b4 100644 --- a/src/utils/formatters/transactionRequest.ts +++ b/src/utils/formatters/transactionRequest.ts @@ -1,11 +1,7 @@ -import type { - Chain, - ExtractChainFormatterParameters, -} from '../../chains/types.js' import type { RpcTransactionRequest } from '../../types/rpc.js' import type { TransactionRequest } from '../../types/transaction.js' import { numberToHex } from '../encoding/toHex.js' -import { defineFormatter } from './formatter.js' +import type { Chain, ExtractChainFormatterParameters } from '@viem/chains' export type FormattedTransactionRequest< TChain extends Chain | undefined = Chain | undefined, @@ -46,8 +42,3 @@ export function formatTransactionRequest( : undefined, } as RpcTransactionRequest } - -export const defineTransactionRequest = /*#__PURE__*/ defineFormatter( - 'transactionRequest', - formatTransactionRequest, -) diff --git a/src/utils/index.ts b/src/utils/index.ts index 168624473f..d19e7c0a16 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -119,23 +119,17 @@ export { slice, sliceBytes, sliceHex } from './data/slice.js' export { trim } from './data/trim.js' export { type FormattedBlock, - defineBlock, formatBlock, } from './formatters/block.js' export { type FormattedTransaction, - defineTransaction, formatTransaction, transactionType, } from './formatters/transaction.js' export { formatLog } from './formatters/log.js' -export { - type FormattedTransactionReceipt, - defineTransactionReceipt, -} from './formatters/transactionReceipt.js' +export { type FormattedTransactionReceipt } from './formatters/transactionReceipt.js' export { type FormattedTransactionRequest, - defineTransactionRequest, formatTransactionRequest, } from './formatters/transactionRequest.js' export { extract } from './formatters/extract.js' @@ -174,7 +168,6 @@ export { getCallError } from './errors/getCallError.js' export { getContractError } from './errors/getContractError.js' export { getEstimateGasError } from './errors/getEstimateGasError.js' export { getTransactionError } from './errors/getTransactionError.js' -export { defineFormatter } from './formatters/formatter.js' export { getEventSelector } from './hash/getEventSelector.js' export { getFunctionSelector } from './hash/getFunctionSelector.js' export { isHash } from './hash/isHash.js' diff --git a/src/utils/transaction/assertRequest.ts b/src/utils/transaction/assertRequest.ts index 011cf2ec6d..77eb3c821f 100644 --- a/src/utils/transaction/assertRequest.ts +++ b/src/utils/transaction/assertRequest.ts @@ -1,10 +1,10 @@ import { parseAccount } from '../../accounts/utils/parseAccount.js' import type { SendTransactionParameters } from '../../actions/wallet/sendTransaction.js' -import type { Chain } from '../../chains/types.js' import { InvalidAddressError } from '../../errors/address.js' import { FeeCapTooHighError, TipAboveFeeCapError } from '../../errors/node.js' import { FeeConflictError } from '../../errors/transaction.js' import { isAddress } from '../address/isAddress.js' +import type { Chain } from '@viem/chains' export type AssertRequestParameters = Partial> diff --git a/src/utils/transaction/prepareRequest.ts b/src/utils/transaction/prepareRequest.ts index 23bd51d118..8b2af2b95b 100644 --- a/src/utils/transaction/prepareRequest.ts +++ b/src/utils/transaction/prepareRequest.ts @@ -10,7 +10,6 @@ import { import { getBlock } from '../../actions/public/getBlock.js' import { getTransactionCount } from '../../actions/public/getTransactionCount.js' import type { SendTransactionParameters } from '../../actions/wallet/sendTransaction.js' -import type { Chain } from '../../chains/types.js' import type { Client } from '../../clients/createClient.js' import type { Transport } from '../../clients/transports/createTransport.js' import { AccountNotFoundError } from '../../errors/account.js' @@ -23,6 +22,7 @@ import type { GetChain } from '../../types/chain.js' import type { UnionOmit } from '../../types/utils.js' import { type FormattedTransactionRequest } from '../index.js' import { type AssertRequestParameters, assertRequest } from './assertRequest.js' +import type { Chain } from '@viem/chains' export type PrepareRequestParameters< TChain extends Chain | undefined = Chain | undefined, diff --git a/tsconfig.base.json b/tsconfig.base.json index 9e3351f97e..d8e1e87a00 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -40,6 +40,14 @@ ], // Skip type checking for node modules - "skipLibCheck": true + "skipLibCheck": true, + + "baseUrl": ".", + "paths": { + "@viem/chains": ["./chains/src/index.ts"], + "@viem/chains/*": ["./chains/src/*.ts", "./chains/src/*/index.ts"], + "viem": ["./src/index.ts"], + "viem/*": ["./src/*.ts", "./src/*/index.ts"], + } } } diff --git a/tsconfig.build.json b/tsconfig.build.json index 76907b36ef..f520428d76 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -10,6 +10,6 @@ ], "compilerOptions": { "sourceMap": true, - "rootDir": "./src" + "rootDir": "." } } diff --git a/tsconfig.json b/tsconfig.json index c270a4889e..54b56deb26 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { // This configuration is used for local development and type checking. "extends": "./tsconfig.base.json", - "include": ["src"], + "include": ["chains", "src"], "exclude": [], "references": [{ "path": "./tsconfig.node.json" }], "compilerOptions": {