Skip to content

Commit

Permalink
🐛 Fix(vm): Fix issues with tsup and package.json (#709)
Browse files Browse the repository at this point in the history
## Description

Issues with package including
- bad folder path (copy pasta)
- linking to wring esm/cjs modules in package.json
- not compiling cjs

## Testing

Explain the quality checks that have been done on the code changes

## Additional Information

- [ ] I read the [contributing docs](../docs/contributing.md) (if this
is your first contribution)

Your ENS/address:

Co-authored-by: Will Cory <[email protected]>
  • Loading branch information
roninjin10 and Will Cory authored Nov 22, 2023
1 parent c81495f commit e34ce0a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 57 deletions.
29 changes: 13 additions & 16 deletions vm/docs/classes/EVMts.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,23 @@ const balance = await evmts.runContractCall(

### constructor

**new EVMts**(`stateManager`, `common?`, `customPrecompiles?`, `_evm?`): [`EVMts`](EVMts.md)
**new EVMts**(`_evm`): [`EVMts`](EVMts.md)

A local EVM instance running in JavaScript. Similar to Anvil in your browser

#### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `stateManager` | `DefaultStateManager` \| `ViemStateManager` | `undefined` |
| `common` | `Common` | `undefined` |
| `customPrecompiles` | `CustomPrecompile`[] | `[]` |
| `_evm` | `EVM` | `undefined` |
| Name | Type |
| :------ | :------ |
| `_evm` | `EVM` |

#### Returns

[`EVMts`](EVMts.md)

#### Defined in

[evmts.ts:133](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L133)
[evmts.ts:146](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L146)

## Properties

Expand All @@ -86,7 +83,7 @@ A local EVM instance running in JavaScript. Similar to Anvil in your browser

#### Defined in

[evmts.ts:137](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L137)
[evmts.ts:147](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L147)

___

Expand All @@ -98,7 +95,7 @@ Makes sure evmts is invoked with EVMts.create and not with new EVMts

#### Defined in

[evmts.ts:101](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L101)
[evmts.ts:100](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L100)

## Methods

Expand Down Expand Up @@ -129,7 +126,7 @@ evmts.putAccount({

#### Defined in

[evmts.ts:198](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L198)
[evmts.ts:196](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L196)

___

Expand Down Expand Up @@ -160,7 +157,7 @@ evmts.putContract({

#### Defined in

[evmts.ts:212](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L212)
[evmts.ts:210](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L210)

___

Expand Down Expand Up @@ -193,7 +190,7 @@ const result = await evmts.runCall({

#### Defined in

[evmts.ts:228](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L228)
[evmts.ts:226](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L226)

___

Expand Down Expand Up @@ -233,7 +230,7 @@ const result = await evmts.runContractCall({

#### Defined in

[evmts.ts:244](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L244)
[evmts.ts:242](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L242)

___

Expand Down Expand Up @@ -286,7 +283,7 @@ evmts.runScript({

#### Defined in

[evmts.ts:179](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L179)
[evmts.ts:177](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L177)

___

Expand All @@ -308,4 +305,4 @@ Creates a [EVMts](EVMts.md) instance

#### Defined in

[evmts.ts:106](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L106)
[evmts.ts:105](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L105)
2 changes: 1 addition & 1 deletion vm/docs/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Options for creating an EVMts instance

#### Defined in

[evmts.ts:42](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L42)
[evmts.ts:41](https://github.com/evmts/evmts-monorepo/blob/main/vm/src/evmts.ts#L41)

___

Expand Down
9 changes: 5 additions & 4 deletions vm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"repository": {
"type": "git",
"url": "https://github.com/evmts/evmts-monorepo.git",
"directory": "prototype/core"
"directory": "vm"
},
"license": "MIT",
"contributors": [
Expand All @@ -26,17 +26,18 @@
"./package.json": "./package.json",
".": {
"import": "./dist/index.js",
"default": "./dist/index.js",
"default": "./dist/index.cjs",
"types": "./types/index.d.ts"
}
},
"main": "dist/index.js",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "types/index.d.ts",
"files": [
"dist",
"types",
"src"
"src",
"!src/**/*.spec.ts"
],
"scripts": {
"all": "pnpm i && bun run build && bun lint && bun format && bun test:run && bun generate:docs",
Expand Down
38 changes: 18 additions & 20 deletions vm/src/evmts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
runScriptHandler,
} from './actions/index.js'
import { ViemStateManager } from './stateManager/ViemStateManager.js'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { EVM } from '@ethereumjs/evm'
import { Common, Hardfork } from '@ethereumjs/common'
import { DefaultStateManager } from '@ethereumjs/statemanager'
import type { Abi } from 'abitype'
import { createPublicClient, http } from 'viem'
Expand Down Expand Up @@ -60,7 +59,7 @@ type ConstructorArgument<T> = T extends new (
* TODO this should be modified to take a hex address rather than an ethjs address to be consistent with rest of EVMts
*/
export type CustomPrecompile = Exclude<
Exclude<ConstructorArgument<typeof EVM>, undefined>['customPrecompiles'],
Exclude<ConstructorArgument<typeof import("@ethereumjs/evm").EVM>, undefined>['customPrecompiles'],
undefined
>[number]

Expand Down Expand Up @@ -105,6 +104,7 @@ export class EVMts {
*/
static readonly create = async (options: CreateEVMOptions = {}) => {
EVMts.isCreating = true
const { EVM: _EVM } = await import('@ethereumjs/evm')
try {
let stateManager: DefaultStateManager | ViemStateManager
// ethereumjs throws an error for most chain ids
Expand All @@ -121,7 +121,20 @@ export class EVMts {
stateManager = new DefaultStateManager()
}
const common = new Common({ chain: chainId, hardfork })
return new EVMts(stateManager, common, options.customPrecompiles)
const evm = new _EVM({
common,
stateManager,
// blockchain, // Always running the EVM statelessly so not including blockchain
allowUnlimitedContractSize: false,
allowUnlimitedInitCodeSize: false,
customOpcodes: [],
// TODO uncomment the mapping once we make the api correct
customPrecompiles: options.customPrecompiles ?? [], // : customPrecompiles.map(p => ({ ...p, address: new EthjsAddress(hexToBytes(p.address)) })),
profiler: {
enabled: false,
},
})
return new EVMts(evm)
} finally {
EVMts.isCreating = false
}
Expand All @@ -131,22 +144,7 @@ export class EVMts {
* A local EVM instance running in JavaScript. Similar to Anvil in your browser
*/
constructor(
stateManager: DefaultStateManager | ViemStateManager,
common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai }),
customPrecompiles: CustomPrecompile[] = [],
public readonly _evm = new EVM({
common,
stateManager,
// blockchain, // Always running the EVM statelessly so not including blockchain
allowUnlimitedContractSize: false,
allowUnlimitedInitCodeSize: false,
customOpcodes: [],
// TODO uncomment the mapping once we make the api correct
customPrecompiles, // : customPrecompiles.map(p => ({ ...p, address: new EthjsAddress(hexToBytes(p.address)) })),
profiler: {
enabled: false,
},
}),
public readonly _evm: import("@ethereumjs/evm").EVM,
) {
if (!EVMts.isCreating) {
throw new Error('EVMts must be created with EVMts.create method')
Expand Down
11 changes: 4 additions & 7 deletions vm/src/stateManager/EthersStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
bytesToHex,
toBytes,
} from '@ethereumjs/util'
import debugDefault from 'debug'
import { debug as createDebugLogger } from 'debug'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { ethers } from 'ethers'

Expand Down Expand Up @@ -73,7 +73,6 @@ class OriginalStorageCache {
this.map = new Map()
}
}
const { debug: createDebugLogger } = debugDefault

export interface EthersStateManagerOpts {
provider: string | ethers.JsonRpcProvider
Expand Down Expand Up @@ -367,10 +366,8 @@ export class EthersStateManager implements EVMStateManagerInterface {
): Promise<void> {
if (this.DEBUG) {
this._debug(
`Save account address=${address} nonce=${account?.nonce} balance=${
account?.balance
} contract=${account?.isContract() ? 'yes' : 'no'} empty=${
account?.isEmpty() ? 'yes' : 'no'
`Save account address=${address} nonce=${account?.nonce} balance=${account?.balance
} contract=${account?.isContract() ? 'yes' : 'no'} empty=${account?.isEmpty() ? 'yes' : 'no'
}`,
)
}
Expand Down Expand Up @@ -497,7 +494,7 @@ export class EthersStateManager implements EVMStateManagerInterface {
/**
* @deprecated This method is not used by the Ethers State Manager and is a stub required by the State Manager interface
*/
setStateRoot = async (_root: Uint8Array) => {}
setStateRoot = async (_root: Uint8Array) => { }

/**
* @deprecated This method is not used by the Ethers State Manager and is a stub required by the State Manager interface
Expand Down
12 changes: 4 additions & 8 deletions vm/src/stateManager/ViemStateManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Trie } from '@ethereumjs/trie'
import { Account } from '@ethereumjs/util'
import debugDefault from 'debug'
import { debug as createDebugLogger } from 'debug'
import { keccak256 } from 'ethereum-cryptography/keccak.js'

import { AccountCache, CacheType, StorageCache } from '@ethereumjs/statemanager'
Expand All @@ -25,8 +25,6 @@ import {
toHex,
} from 'viem'

const { debug: createDebugLogger } = debugDefault

export interface ViemStateManagerOpts {
client: PublicClient
blockTag: bigint | 'earliest'
Expand Down Expand Up @@ -302,10 +300,8 @@ export class ViemStateManager implements EVMStateManagerInterface {
): Promise<void> {
if (this.DEBUG) {
this._debug(
`Save account address=${address} nonce=${account?.nonce} balance=${
account?.balance
} contract=${account?.isContract() ? 'yes' : 'no'} empty=${
account?.isEmpty() ? 'yes' : 'no'
`Save account address=${address} nonce=${account?.nonce} balance=${account?.balance
} contract=${account?.isContract() ? 'yes' : 'no'} empty=${account?.isEmpty() ? 'yes' : 'no'
}`,
)
}
Expand Down Expand Up @@ -442,7 +438,7 @@ export class ViemStateManager implements EVMStateManagerInterface {
/**
* @deprecated This method is not used by the Viem State Manager and is a stub required by the State Manager interface
*/
setStateRoot = async (_root: Uint8Array) => {}
setStateRoot = async (_root: Uint8Array) => { }

/**
* @deprecated This method is not used by the Viem State Manager and is a stub required by the State Manager interface
Expand Down
3 changes: 2 additions & 1 deletion vm/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export default defineConfig({
name: packageJson.name,
entry: ['src/index.ts'],
outDir: 'dist',
format: ['esm'],
format: ['esm', 'cjs'],
splitting: false,
treeshake: true,
sourcemap: true,
clean: true,
})

1 comment on commit e34ce0a

@vercel
Copy link

@vercel vercel bot commented on e34ce0a Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

evmts-docs – ./

evmts-docs-git-main-evmts.vercel.app
evmts.dev
evmts-docs-evmts.vercel.app

Please sign in to comment.