{"version":3,"sources":["../src/Evm.js","../src/createEvm.js"],"names":["EVM","MisconfiguredClientError","getActivePrecompiles","InvalidParamsError","evm","createEVM","logger","createLogger"],"mappings":";;;;;;;AAwBO,IAAM,GAAA,GAAN,MAAM,IAAA,SAAYA,OAAA,CAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM5B,oBAAoB,UAAA,EAAY;AAC/B,IAAA,IAAI,IAAA,CAAK,uBAAuB,MAAA,EAAW;AAC1C,MAAA,MAAM,IAAIC,+BAAA;AAAA,QACT;AAAA,OACD;AAAA,IACD;AACA,IAAA,IAAA,CAAK,kBAAA,CAAmB,KAAK,UAAU,CAAA;AACvC,IAAA,IAAA,CAAK,YAAA,GAAeC,wBAAA,CAAqB,IAAA,CAAK,MAAA,EAAQ,KAAK,kBAAkB,CAAA;AAAA,EAC9E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,uBAAuB,UAAA,EAAY;AAClC,IAAA,IAAI,IAAA,CAAK,uBAAuB,MAAA,EAAW;AAC1C,MAAA,MAAM,IAAID,+BAAA;AAAA,QACT;AAAA,OACD;AAAA,IACD;AACA,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,kBAAA,CAAmB,OAAA,CAAQ,UAAU,CAAA;AACxD,IAAA,IAAI,UAAU,EAAA,EAAI;AACjB,MAAA,MAAM,IAAIE,0BAAmB,sBAAsB,CAAA;AAAA,IACpD;AACA,IAAA,IAAA,CAAK,kBAAA,CAAmB,MAAA,CAAO,KAAA,EAAO,CAAC,CAAA;AACvC,IAAA,IAAA,CAAK,YAAA,GAAeD,wBAAA,CAAqB,IAAA,CAAK,MAAA,EAAQ,KAAK,kBAAkB,CAAA;AAAA,EAC9E;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,MAAA,GAAS,OAAO,OAAA,KAAY;AAClC,IAAA,MAAME,KAAA;AAAA;AAAA,MAAyB,MAAMC,cAAU,OAAO;AAAA,KAAA;AACtD,IAAAD,KAAA,CAA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AACA,EAAA,GAAA,CAAI,mBAAA,GAAsB,GAAA,CAAI,mBAAA,EAAqB,IAAA,CAAK,GAAG,KAAK,GAAA,CAAI,SAAA,CAAU,mBAAA,CAAoB,IAAA,CAAK,GAAG,CAAA;AAC1G,EAAA,GAAA,CAAI,sBAAA,GAAyB,GAAA,CAAI,sBAAA,EAAwB,IAAA,CAAK,GAAG,KAAK,GAAA,CAAI,SAAA,CAAU,sBAAA,CAAuB,IAAA,CAAK,GAAG,CAAA;AACnH,EAAA,OAAO,GAAA;AACR","file":"index.cjs","sourcesContent":["import { createEVM, EVM, getActivePrecompiles } from '@ethereumjs/evm'\nimport { InvalidParamsError, MisconfiguredClientError } from '@tevm/errors'\n\n/**\n * The Tevm EVM is in charge of executing bytecode. It is a very light wrapper around ethereumjs EVM\n * The Evm class provides tevm specific typing with regard to the custom stateManager. It does not\n * provide custom typing to the blockchain or common objects.\n * @type {typeof import('./EvmType.js').Evm}\n * @example\n * ```typescript\n * import { type Evm, createEvm, CreateEvmOptions } from 'tevm/evm'\n * import { mainnet } from 'tevm/common'\n * import { createStateManager } from 'tevm/state'\n * import { createBlockchain } from 'tevm/blockchain'}\n * import { EthjsAddress } from 'tevm/utils'\n *\n * const evm = createEvm({\n *   common: mainnet.copy(),\n *   stateManager: createStateManager(),\n *   blockchain: createBlockchain(),\n * })\n * ```\n * @see [createEvm](https://tevm.sh/reference/tevm/evm/functions/createevm/)\n */\nexport class Evm extends EVM {\n\t/**\n\t * Adds a custom precompile to the EVM.\n\t * @param {import('./CustomPrecompile.js').CustomPrecompile} precompile\n\t * @throws {MisconfiguredClientError}\n\t */\n\taddCustomPrecompile(precompile) {\n\t\tif (this._customPrecompiles === undefined) {\n\t\t\tthrow new MisconfiguredClientError(\n\t\t\t\t'Custom precompiles is empty. This is an internal bug as it should always be defined',\n\t\t\t)\n\t\t}\n\t\tthis._customPrecompiles.push(precompile)\n\t\tthis._precompiles = getActivePrecompiles(this.common, this._customPrecompiles)\n\t}\n\n\t/**\n\t * Removes a custom precompile from the EVM.\n\t * @param {import('./CustomPrecompile.js').CustomPrecompile} precompile\n\t * @throws {MisconfiguredClientError}\n\t * @throws {InvalidParamsError}\n\t */\n\tremoveCustomPrecompile(precompile) {\n\t\tif (this._customPrecompiles === undefined) {\n\t\t\tthrow new MisconfiguredClientError(\n\t\t\t\t'Custom precompiles is empty. This is an internal bug as it should always be defined',\n\t\t\t)\n\t\t}\n\t\tconst index = this._customPrecompiles.indexOf(precompile)\n\t\tif (index === -1) {\n\t\t\tthrow new InvalidParamsError('Precompile not found')\n\t\t}\n\t\tthis._customPrecompiles.splice(index, 1)\n\t\tthis._precompiles = getActivePrecompiles(this.common, this._customPrecompiles)\n\t}\n\n\t/**\n\t * @type {(typeof import('./EvmType.js').Evm)['create']}\n\t */\n\tstatic create = async (options) => {\n\t\tconst evm = /** @type {any}*/ (await createEVM(options))\n\t\tevm.addCustomPrecompile = Evm.prototype.addCustomPrecompile.bind(evm)\n\t\tevm.removeCustomPrecompile = Evm.prototype.removeCustomPrecompile.bind(evm)\n\t\treturn evm\n\t}\n}\n","import { createLogger } from '@tevm/logger'\nimport { Evm } from './Evm.js'\n\n/**\n * Creates the Tevm Evm to execute ethereum bytecode internally.\n * Wraps [ethereumjs EVM](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/evm)\n * @example\n * ```typescript\n * import { createEvm } from '@tevm/evm'\n * import { mainnet } from '@tevm/common'\n * import { createBlockchain } from '@tevm/blockchain'\n * import { createStateManager } from '@tevm/state-manager'\n * import { EthjsAddress } from '@tevm/utils'\n *\n * const common = mainnet.clone()\n * const stateManager = createStateManager({ common })\n * const blockchain = createBlockchain({ common })\n * const evm = await createEvm({ common, stateManager, blockchain})\n *\n * const runCallResult = await evm.runCall({\n *   to: EthjsAddress.from(`0x${'00'.repeat(20)}`),\n *   value: 420n,\n *   skipBalance: true,\n * })\n * console.log(runCallResult)\n * ````\n * @param {import('./CreateEvmOptions.js').CreateEvmOptions} options\n * @returns {Promise<import('./EvmType.js').Evm>} A tevm Evm instance with tevm specific defaults\n */\nexport const createEvm = async ({\n\tcommon,\n\tstateManager,\n\tblockchain,\n\tcustomPrecompiles,\n\tprofiler,\n\tallowUnlimitedContractSize,\n\tloggingLevel,\n}) => {\n\tconst logger = createLogger({\n\t\tname: '@tevm/evm',\n\t\tlevel: loggingLevel ?? 'warn',\n\t})\n\tlogger.debug({\n\t\tallowUnlimitedContractSize,\n\t\tprofiler,\n\t\tcustomPrecompiles: customPrecompiles?.map((c) => c.address.toString()),\n\t})\n\tconst evm = await Evm.create({\n\t\tcommon: common.ethjsCommon,\n\t\tstateManager,\n\t\tblockchain,\n\t\tallowUnlimitedContractSize: allowUnlimitedContractSize ?? false,\n\t\tallowUnlimitedInitCodeSize: false,\n\t\tcustomOpcodes: [],\n\t\t// TODO uncomment the mapping once we make the api correct\n\t\t// Edit: nvm not letting this block a stable release maybe update it next major\n\t\t// @warning Always pass in an empty array if no precompiles as `addPrecompile` method assumes it's there\n\t\tcustomPrecompiles: customPrecompiles ?? [],\n\t\tprofiler: {\n\t\t\tenabled: profiler ?? false,\n\t\t},\n\t})\n\tif (loggingLevel === 'trace') {\n\t\t// we are hacking ethereumjs logger into working with our logger\n\t\tconst evmAny = /** @type {any} */ (evm)\n\t\tevmAny.DEBUG = true\n\t\tevmAny._debug = logger\n\t}\n\tevm.addCustomPrecompile = evm.addCustomPrecompile?.bind(evm) ?? Evm.prototype.addCustomPrecompile.bind(evm)\n\tevm.removeCustomPrecompile = evm.removeCustomPrecompile?.bind(evm) ?? Evm.prototype.removeCustomPrecompile.bind(evm)\n\treturn evm\n}\n"]}