Skip to content

Commit

Permalink
♻️ Remove unneded props from baseClient
Browse files Browse the repository at this point in the history
  • Loading branch information
William Cory authored and William Cory committed May 23, 2024
1 parent d5a29e4 commit 131de52
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 72 deletions.
16 changes: 1 addition & 15 deletions packages/base-client/src/BaseClientOptions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Common, type CustomCrypto } from '@tevm/common'
import { type Common } from '@tevm/common'
import type { LogOptions } from '@tevm/logger'
import type { CustomPredeploy } from '@tevm/predeploys'
import type { StateOptions } from '@tevm/state'
import type { SyncStoragePersister } from '@tevm/sync-storage-persister'
import type { CustomPrecompile } from './CustomPrecompile.js'
import type { Hardfork } from './Hardfork.js'
import type { MiningConfig } from './MiningConfig.js'

/**
Expand All @@ -25,10 +24,6 @@ export type BaseClientOptions = StateOptions & {
* `
*/
readonly common?: Common
/**
* Custom crypto functionality provided to the EVM. For 4844 support, kzg must be passed.
*/
readonly customCrypto?: CustomCrypto
/**
* Configure logging options for the client
*/
Expand All @@ -44,15 +39,6 @@ export type BaseClientOptions = StateOptions & {
* Enable profiler. Defaults to false.
*/
readonly profiler?: boolean
/**
* Hardfork to use. Defaults to `shanghai`
*/
readonly hardfork?: Hardfork
// TODO type this more strongly
/**
* Eips to enable. Defaults to `[1559, 4895]`
*/
readonly eips?: ReadonlyArray<number>
/**
* Custom precompiles allow you to run arbitrary JavaScript code in the EVM.
* See the [Precompile guide](https://todo.todo) documentation for a deeper dive
Expand Down
32 changes: 4 additions & 28 deletions packages/base-client/src/createBaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { KECCAK256_RLP, bytesToHex, hexToBigInt, keccak256 } from '@tevm/utils'
import { createVm } from '@tevm/vm'
import { DEFAULT_CHAIN_ID } from './DEFAULT_CHAIN_ID.js'
import { GENESIS_STATE } from './GENESIS_STATE.js'
import { createMockKzg } from './createMockKzg.js'
import { getBlockNumber } from './getBlockNumber.js'
import { getChainId } from './getChainId.js'
import { statePersister } from './statePersister.js'
Expand Down Expand Up @@ -98,45 +97,22 @@ export const createBaseClient = (options = {}) => {

const chainCommonPromise = chainIdPromise
.then((chainId) => {
// TODO we will eventually want to be setting common hardfork based on chain id and block number
// ethereumjs does this for mainnet but we forgo all this functionality
const customCrypto = options?.customCrypto ?? {}
if (options.common) {
return createCommon({
...options.common,
id: Number(chainId),
loggingLevel: options.loggingLevel ?? 'warn',
hardfork: 'cancun',
eips: options.eips ?? [],
customCrypto: {
kzg: createMockKzg(),
...customCrypto,
},
})
}
if (!options.fork?.url) {
return createCommon({
...tevmDefault,
id: Number(chainId),
hardfork: 'cancun',
eips: options.eips ?? [],
loggingLevel: options.loggingLevel ?? 'warn',
customCrypto: {
kzg: createMockKzg(),
...customCrypto,
},
hardfork: /** @type {import('@tevm/common').Hardfork}*/ (options.common.ethjsCommon.hardfork()) ?? 'cancun',
eips: options.common.ethjsCommon.eips(),
customCrypto: options.common.ethjsCommon.customCrypto,
})
}
return createCommon({
...tevmDefault,
id: Number(chainId),
loggingLevel: options.loggingLevel ?? 'warn',
hardfork: 'cancun',
eips: options.eips ?? [],
customCrypto: {
kzg: createMockKzg(),
...customCrypto,
},
eips: [],
})
})
.then((common) => {
Expand Down
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"dependencies": {
"@ethereumjs/common": "^4.3.0",
"@tevm/logger": "workspace:^",
"@tevm/utils": "workspace:1.1.0-next.52",
"viem": "^2.12.0"
},
"devDependencies": {
Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion packages/common/src/createCommon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Common } from '@ethereumjs/common'
import { createLogger } from '@tevm/logger'
import { createMockKzg } from './createMockKzg.js'

/**
* Creates an ethereumjs Common object used by the EVM
Expand All @@ -8,7 +9,7 @@ import { createLogger } from '@tevm/logger'
* @param {import('./CommonOptions.js').CommonOptions} options
* @returns {import('./Common.js').Common}
*/
export const createCommon = ({ loggingLevel, hardfork, eips = [], ...chain }) => {
export const createCommon = ({ customCrypto = {}, loggingLevel, hardfork, eips = [], ...chain }) => {
const logger = createLogger({ level: loggingLevel, name: '@tevm/common' })
const ethjsCommon = Common.custom(
{
Expand All @@ -21,6 +22,10 @@ export const createCommon = ({ loggingLevel, hardfork, eips = [], ...chain }) =>
hardfork: hardfork ?? 'cancun',
baseChain: 1,
eips: [...(eips ?? []), 1559, 4895, 4844, 4788],
customCrypto: {
kzg: createMockKzg(),
...customCrypto,
},
},
)
if (ethjsCommon.isActivatedEIP(6800)) {
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export {
tevmDefault,
zoraSepolia,
} from './presets/index.js'
export { type MockKzg } from './MockKzg.js'
export { createMockKzg } from './createMockKzg.js'
25 changes: 5 additions & 20 deletions packages/memory-client/src/test/viemPublicActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,10 @@ describe('viemPublicActions', () => {
getEnsAddress: async () => {
const kzg = await loadKZG()
const mainnetClient = createMemoryClient({
common: mainnet,
common: Object.assign({ kzg }, mainnet),
fork: {
url: getAlchemyUrl('mainnet'),
},
customCrypto: {
kzg,
},
})
it(
'should work',
Expand All @@ -215,13 +212,10 @@ describe('viemPublicActions', () => {
getEnsAvatar: async () => {
const kzg = await loadKZG()
const mainnetClient = createMemoryClient({
common: mainnet,
common: Object.assign({ kzg }, mainnet),
fork: {
url: getAlchemyUrl('mainnet'),
},
customCrypto: {
kzg,
},
})
it(
'should work',
Expand All @@ -238,13 +232,10 @@ describe('viemPublicActions', () => {
getEnsName: async () => {
const kzg = await loadKZG()
const mainnetClient = createMemoryClient({
common: mainnet,
common: Object.assign({ kzg }, mainnet),
fork: {
url: getAlchemyUrl('mainnet'),
},
customCrypto: {
kzg,
},
})
it(
'should work',
Expand All @@ -261,13 +252,10 @@ describe('viemPublicActions', () => {
getEnsResolver: async () => {
const kzg = await loadKZG()
const mainnetClient = createMemoryClient({
common: mainnet,
common: Object.assign({ kzg }, mainnet),
fork: {
url: getAlchemyUrl('mainnet'),
},
customCrypto: {
kzg,
},
})
it(
'should work',
Expand All @@ -284,13 +272,10 @@ describe('viemPublicActions', () => {
getEnsText: async () => {
const kzg = await loadKZG()
const mainnetClient = createMemoryClient({
common: mainnet,
common: Object.assign({ kzg }, mainnet),
fork: {
url: getAlchemyUrl('mainnet'),
},
customCrypto: {
kzg,
},
})
it.todo('should work', async () => {
expect(await mainnetClient.getEnsText({ name: 'vitalik.eth', key: 'key' })).toBe(
Expand Down
20 changes: 12 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 131de52

Please sign in to comment.