Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feat: Add official tevm trace methods #824

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tevm/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
export type {
StructLog,
TraceCallParams,
TraceCallResult,
TraceCallHandler,
TraceScriptParams,
TraceScriptResult,
TraceCallProcedure,
TraceScriptHandler,
AnvilJsonRpcRequest,
DebugJsonRpcRequest,
TraceContractParams,
TraceContractResult,
TraceContractHandler,
TraceScriptProcedure,
TraceContractProcedure,
TraceCallJsonRpcRequest,
TraceCallJsonRpcResponse,
TraceScriptJsonRpcRequest,
TraceScriptJsonRpcResponse,
TraceContractJsonRpcRequest,
TraceContractJsonRpcResponse,
AnvilImpersonateAccountParams,
AnvilMineParams,
DebugTraceCallParams,
Expand Down
28 changes: 12 additions & 16 deletions vm/api/src/Tevm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import type {
AccountHandler,
CallHandler,
ContractHandler,
// DebugTraceCallHandler,
// DebugTraceTransactionHandler,
DebugTraceCallHandler,
DebugTraceTransactionHandler,
EthBlockNumberHandler,
// EthCallHandler,
EthChainIdHandler,
EthGasPriceHandler,
EthGetBalanceHandler,
EthGetCodeHandler,
EthGetStorageAtHandler,
ScriptHandler,
TraceCallHandler,
TraceContractHandler,
TraceScriptHandler,
} from './handlers/index.js'

/**
Expand All @@ -27,25 +29,19 @@ export type Tevm = {
account: AccountHandler
call: CallHandler
contract: ContractHandler
traceCall: TraceCallHandler
traceContract: TraceContractHandler
traceScript: TraceScriptHandler
eth: {
blockNumber: EthBlockNumberHandler
chainId: EthChainIdHandler
// call: EthCallHandler
getCode: EthGetCodeHandler
getStorageAt: EthGetStorageAtHandler
gasPrice: EthGasPriceHandler
getBalance: EthGetBalanceHandler
}
// Eth Handlers
// debug handlers
// traceTransaction: DebugTraceTransactionHandler
// traceCall: DebugTraceCallHandler
// anvil handlers
// Not implementing any yet
// hardhat handlers
// Not implementing any yet
// Ganache handlers
// Not implementing any yet
// Compile handlers
// Not implementing any yet
debug: {
traceTransaction: DebugTraceTransactionHandler
traceCall: DebugTraceCallHandler
}
}
22 changes: 14 additions & 8 deletions vm/api/src/TevmJsonRpcRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ import type {
import type { AnvilJsonRpcRequest } from './requests/AnvilJsonRpcRequest.js'
import type { DebugJsonRpcRequest } from './requests/DebugJsonRpcRequest.js'
import type { EthJsonRpcRequest } from './requests/EthJsonRpcRequest.js'
import type { TraceCallJsonRpcResponse } from './responses/TraceCallJsonRpcResponse.js'
import type { TraceContractJsonRpcResponse } from './responses/TraceContractJsonRpcResponse.js'
import type { TraceScriptJsonRpcResponse } from './responses/TraceScriptJsonRpcResponse.js'

type DebugReturnType = {
debug_traceTransaction: DebugTraceTransactionJsonRpcResponse
Expand Down Expand Up @@ -128,14 +131,17 @@ type TevmReturnType = {
tevm_call: CallJsonRpcResponse
tevm_script: ScriptJsonRpcResponse
tevm_account: AccountJsonRpcResponse
tevm_traceCall: TraceCallJsonRpcResponse
tevm_traceContract: TraceContractJsonRpcResponse
tevm_traceScript: TraceScriptJsonRpcResponse
}

type ReturnType<
TMethod extends
| keyof EthReturnType
| keyof TevmReturnType
| keyof AnvilReturnType
| keyof DebugReturnType,
| keyof EthReturnType
| keyof TevmReturnType
| keyof AnvilReturnType
| keyof DebugReturnType,
> = (EthReturnType &
TevmReturnType &
AnvilReturnType &
Expand All @@ -147,10 +153,10 @@ type ReturnType<
*/
export type TevmJsonRpcRequestHandler = <
TRequest extends
| TevmJsonRpcRequest
| EthJsonRpcRequest
| AnvilJsonRpcRequest
| DebugJsonRpcRequest,
| TevmJsonRpcRequest
| EthJsonRpcRequest
| AnvilJsonRpcRequest
| DebugJsonRpcRequest,
>(
request: TRequest,
) => Promise<ReturnType<TRequest['method']>>
Expand Down
7 changes: 7 additions & 0 deletions vm/api/src/handlers/TraceCallHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { TraceCallParams } from "../params/TraceCallParams.js";
import type { TraceCallResult } from "../result/TraceCallResult.js";

// tevm_traceCall
export type TraceCallHandler = (
params: TraceCallParams,
) => Promise<TraceCallResult>
7 changes: 7 additions & 0 deletions vm/api/src/handlers/TraceContractHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { TraceContractParams } from "../params/TraceContractParams.js";
import type { TraceContractResult } from "../result/TraceContractResult.js";

// tevm_traceCall
export type TraceContractHandler = (
params: TraceContractParams,
) => Promise<TraceContractResult>
7 changes: 7 additions & 0 deletions vm/api/src/handlers/TraceScriptHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { TraceScriptParams } from "../params/TraceScriptParams.js";
import type { TraceScriptResult } from "../result/TraceScriptResult.js";

// tevm_traceScript
export type TraceScriptHandler = (
params: TraceScriptParams,
) => Promise<TraceScriptResult>
3 changes: 3 additions & 0 deletions vm/api/src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export type * from './ScriptHandler.js'
export type * from './AnvilHandler.js'
export type * from './DebugHandler.js'
export type * from './EthHandler.js'
export type * from './TraceCallHandler.js'
export type * from './TraceScriptHandler.js'
export type * from './TraceContractHandler.js'
20 changes: 20 additions & 0 deletions vm/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type {
TraceScriptParams,
TraceContractParams, TraceCallParams,
AnvilImpersonateAccountParams,
AnvilMineParams,
DebugTraceCallParams,
Expand Down Expand Up @@ -106,6 +108,9 @@ export type {
TevmEVMErrorMessage,
} from './errors/index.js'
export type {
TraceScriptHandler,
TraceContractHandler,
TraceCallHandler,
CallHandler,
ScriptHandler,
AccountHandler,
Expand Down Expand Up @@ -165,6 +170,8 @@ export type {
AnvilStopImpersonatingAccountHandler,
} from './handlers/index.js'
export type {
TraceCallResult,
StructLog,
AccountResult,
CallResult,
ScriptResult,
Expand Down Expand Up @@ -222,8 +229,15 @@ export type {
AnvilDropTransactionResult,
AnvilStopImpersonatingAccountResult,
DebugTraceTransactionResult,
TraceScriptResult,
TraceContractResult
} from './result/index.js'
export type {
TraceCallJsonRpcRequest,
AnvilJsonRpcRequest,
DebugJsonRpcRequest,
TraceScriptJsonRpcRequest,
TraceContractJsonRpcRequest,
JsonRpcRequest,
CallJsonRpcRequest,
ScriptJsonRpcRequest,
Expand Down Expand Up @@ -286,6 +300,9 @@ export type {
EthJsonRpcRequest,
} from './requests/index.js'
export type {
TraceScriptJsonRpcResponse,
TraceContractJsonRpcResponse,
TraceCallJsonRpcResponse,
JsonRpcResponse,
CallJsonRpcResponse,
ContractJsonRpcResponse,
Expand Down Expand Up @@ -346,6 +363,9 @@ export type {
DebugTraceTransactionJsonRpcResponse,
} from './responses/index.js'
export type {
TraceCallProcedure,
TraceScriptProcedure,
TraceContractProcedure,
CallJsonRpcProcedure,
ContractJsonRpcProcedure,
ScriptJsonRpcProcedure,
Expand Down
17 changes: 8 additions & 9 deletions vm/api/src/params/DebugParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BlockTag, CallParameters, Chain, Hex } from 'viem'
import type { BlockTag, Hex } from 'viem'
import type { CallParams } from './CallParams.js'

/**
* Config params for trace calls
Expand Down Expand Up @@ -33,7 +34,7 @@ export type TraceParams = {
/**
* boolean Setting this to true will disable stack capture. This avoids extra processing for each call frame if stack is not required.
*/
// readonly disableStack?: boolean
readonly disableStack?: boolean
}
}

Expand All @@ -45,22 +46,20 @@ export type DebugTraceTransactionParams = TraceParams & {
/**
* The transaction hash
*/
transactionHash: Hex
readonly transactionHash: Hex
}

// debug_traceCall
/**
* Params taken by `debug_traceCall` handler
*/
export type DebugTraceCallParams<
TChain extends Chain | undefined = Chain | undefined,
> = TraceParams & {
export type DebugTraceCallParams = TraceParams & {
/**
* The transaction to debug
* The call to debug
*/
transaction: CallParameters<TChain>
readonly call: CallParams
/**
* Block information
*/
block?: BlockTag | Hex | BigInt
readonly block?: BlockTag | Hex | bigint
}
23 changes: 23 additions & 0 deletions vm/api/src/params/TraceCallParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { BlockTag, Hex } from 'viem'
import type { CallParams } from './CallParams.js'
import type { TraceParams } from './DebugParams.js'

// tevm_traceCall
/**
* Params taken by `tevm_traceCall` handler
* Tevm trace call is the same as eth_traceCall but with
* some extra nice to have features and the call interface
* nicely matches tevm_call interface.
*
* eth_traceCall uses tevm_call under the hood
*/
export type TraceCallParams = TraceParams & {
/**
* The call to debug
*/
readonly call: CallParams
/**
* Block information
*/
readonly block?: BlockTag | Hex | bigint
}
23 changes: 23 additions & 0 deletions vm/api/src/params/TraceContractParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { BlockTag, Hex } from 'viem'
import type { ContractParams } from './ContractParams.js'
import type { TraceParams } from './DebugParams.js'

// tevm_traceContract
/**
* Params taken by `tevm_traceContract` handler
* Tevm trace call is the same as eth_traceContract but with
* some extra nice to have features and the call interface
* nicely matches tevm_call interface.
*
* eth_traceContract uses tevm_call under the hood
*/
export type TraceContractParams = TraceParams & {
/**
* The call to debug
*/
readonly call: ContractParams
/**
* Block information
*/
readonly block?: BlockTag | Hex | bigint
}
23 changes: 23 additions & 0 deletions vm/api/src/params/TraceScriptParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { BlockTag, Hex } from 'viem'
import type { ScriptParams } from './ScriptParams.js'
import type { TraceParams } from './DebugParams.js'

// tevm_traceScript
/**
* Params taken by `tevm_traceScript` handler
* Tevm trace call is the same as eth_traceScript but with
* some extra nice to have features and the call interface
* nicely matches tevm_call interface.
*
* eth_traceScript uses tevm_call under the hood
*/
export type TraceScriptParams = TraceParams & {
/**
* The call to debug
*/
readonly call: ScriptParams
/**
* Block information
*/
readonly block?: BlockTag | Hex | bigint
}
3 changes: 3 additions & 0 deletions vm/api/src/params/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ export type * from './ScriptParams.js'
export type * from './EthParams.js'
export type * from './AnvilParams.js'
export type * from './DebugParams.js'
export type * from './TraceCallParams.js'
export type * from './TraceScriptParams.js'
export type * from './TraceContractParams.js'
12 changes: 12 additions & 0 deletions vm/api/src/procedure/TraceCallProcedure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

// tevm_traceCall

import type { TraceCallJsonRpcRequest } from "../requests/TraceCallJsonRpcRequest.js";
import type { TraceCallJsonRpcResponse } from "../responses/TraceCallJsonRpcResponse.js";

/**
* JSON-RPC procedure for `tevm_traceCall`
*/
export type TraceCallProcedure = (
request: TraceCallJsonRpcRequest,
) => Promise<TraceCallJsonRpcResponse>
10 changes: 10 additions & 0 deletions vm/api/src/procedure/TraceContractProcedure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { TraceContractJsonRpcRequest } from "../requests/TraceContractJsonRpcRequest.js";
import type { TraceContractJsonRpcResponse } from "../responses/TraceContractJsonRpcResponse.js";

// tevm_traceContract
/**
* JSON-RPC procedure for `tevm_traceContract`
*/
export type TraceContractProcedure = (
request: TraceContractJsonRpcRequest,
) => Promise<TraceContractJsonRpcResponse>
11 changes: 11 additions & 0 deletions vm/api/src/procedure/TraceScriptProcedure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { TraceScriptJsonRpcRequest } from "../requests/TraceScriptJsonRpcRequest.js";
import type { TraceScriptJsonRpcResponse } from "../responses/TraceScriptJsonRpcResponse.js";

// tevm_traceScript

/**
* JSON-RPC procedure for `tevm_traceScript`
*/
export type TraceScriptProcedure = (
request: TraceScriptJsonRpcRequest,
) => Promise<TraceScriptJsonRpcResponse>
3 changes: 3 additions & 0 deletions vm/api/src/procedure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ export type * from './EthProcedure.js'
export type * from './EthProcedure.js'
export type * from './AnvilProcedure.js'
export type * from './DebugProcedure.js'
export type * from './TraceCallProcedure.js'
export type * from './TraceScriptProcedure.js'
export type * from './TraceContractProcedure.js'
Loading
Loading