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 anvil_deal #1492

Merged
merged 3 commits into from
Nov 1, 2024
Merged
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
8 changes: 8 additions & 0 deletions .changeset/little-coats-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@tevm/memory-client": minor
"@tevm/decorators": minor
"@tevm/actions": minor
---

Added eth_createAccessList and anvil_deal json-rpc requests
Added MemoryClient.deal action
4 changes: 4 additions & 0 deletions packages/actions/src/anvil/AnvilHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
AnvilDealParams,
AnvilDropTransactionParams,
AnvilDumpStateParams,
AnvilGetAutomineParams,
Expand All @@ -14,6 +15,7 @@ import type {
AnvilStopImpersonatingAccountParams,
} from './AnvilParams.js'
import type {
AnvilDealResult,
AnvilDropTransactionResult,
AnvilDumpStateResult,
AnvilGetAutomineResult,
Expand Down Expand Up @@ -64,3 +66,5 @@ export type AnvilDumpStateHandler = (params: AnvilDumpStateParams) => Promise<An
// TODO make this the same as our load state
// anvil_loadState
export type AnvilLoadStateHandler = (params: AnvilLoadStateParams) => Promise<AnvilLoadStateResult>
// anvil_deal
export type AnvilDealHandler = (params: AnvilDealParams) => Promise<AnvilDealResult>
7 changes: 7 additions & 0 deletions packages/actions/src/anvil/AnvilJsonRpcRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { JsonRpcRequest } from '@tevm/jsonrpc'
import type { Address, Hex } from '@tevm/utils'
import type { SerializeToJson } from '../utils/SerializeToJson.js'
import type { AnvilDealParams } from './AnvilParams.js'
import type {
AnvilDropTransactionParams,
AnvilDumpStateParams,
Expand Down Expand Up @@ -111,6 +112,11 @@ export type AnvilLoadStateJsonRpcRequest = JsonRpcRequest<
'anvil_loadState',
readonly [SerializeToJson<AnvilLoadStateParams>]
>
// anvil_deal
/**
* JSON-RPC request for `anvil_deal` method
*/
export type AnvilDealJsonRpcRequest = JsonRpcRequest<'anvil_deal', [SerializeToJson<AnvilDealParams>]>

export type AnvilJsonRpcRequest =
| AnvilImpersonateAccountJsonRpcRequest
Expand All @@ -127,3 +133,4 @@ export type AnvilJsonRpcRequest =
| AnvilDumpStateJsonRpcRequest
| AnvilLoadStateJsonRpcRequest
| AnvilSetCoinbaseJsonRpcRequest
| AnvilDealJsonRpcRequest
6 changes: 6 additions & 0 deletions packages/actions/src/anvil/AnvilJsonRpcResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { JsonRpcResponse } from '@tevm/jsonrpc'
import type { Address } from '@tevm/utils'
import type { SerializeToJson } from '../utils/SerializeToJson.js'
import type {
AnvilDealResult,
AnvilDropTransactionResult,
AnvilDumpStateResult,
AnvilGetAutomineResult,
Expand Down Expand Up @@ -144,3 +145,8 @@ export type AnvilLoadStateJsonRpcResponse = JsonRpcResponse<
SerializeToJson<AnvilLoadStateResult>,
AnvilError
>
// anvil_deal
/**
* JSON-RPC response for `anvil_deal` procedure
*/
export type AnvilDealJsonRpcResponse = JsonRpcResponse<'anvil_deal', SerializeToJson<AnvilDealResult>, AnvilError>
9 changes: 9 additions & 0 deletions packages/actions/src/anvil/AnvilParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,12 @@ export type AnvilLoadStateParams = {
*/
readonly state: Record<Hex, Hex>
}

export type AnvilDealParams = {
/** The address of the ERC20 token to deal */
erc20?: Address
/** The owner of the dealt tokens */
account: Address
/** The amount of tokens to deal */
amount: bigint
}
24 changes: 24 additions & 0 deletions packages/actions/src/anvil/AnvilProcedure.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
AnvilDealJsonRpcRequest,
AnvilDropTransactionJsonRpcRequest,
AnvilDumpStateJsonRpcRequest,
AnvilGetAutomineJsonRpcRequest,
Expand All @@ -15,6 +16,7 @@ import type {
AnvilStopImpersonatingAccountJsonRpcRequest,
} from './AnvilJsonRpcRequest.js'
import type {
AnvilDealJsonRpcResponse,
AnvilDropTransactionJsonRpcResponse,
AnvilDumpStateJsonRpcResponse,
AnvilGetAutomineJsonRpcResponse,
Expand Down Expand Up @@ -120,3 +122,25 @@ export type AnvilDumpStateProcedure = (request: AnvilDumpStateJsonRpcRequest) =>
* JSON-RPC procedure for `anvil_loadState`
*/
export type AnvilLoadStateProcedure = (request: AnvilLoadStateJsonRpcRequest) => Promise<AnvilLoadStateJsonRpcResponse>
// anvil_deal
/**
* JSON-RPC procedure for `anvil_deal`
*/
export type AnvilDealProcedure = (request: AnvilDealJsonRpcRequest) => Promise<AnvilDealJsonRpcResponse>

export type AnvilProcedure =
| AnvilSetCoinbaseProcedure
| AnvilImpersonateAccountProcedure
| AnvilStopImpersonatingAccountProcedure
| AnvilGetAutomineProcedure
| AnvilMineProcedure
| AnvilResetProcedure
| AnvilDropTransactionProcedure
| AnvilSetBalanceProcedure
| AnvilSetCodeProcedure
| AnvilSetNonceProcedure
| AnvilSetStorageAtProcedure
| AnvilSetChainIdProcedure
| AnvilDumpStateProcedure
| AnvilLoadStateProcedure
| AnvilDealProcedure
4 changes: 4 additions & 0 deletions packages/actions/src/anvil/AnvilResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ export type AnvilDumpStateResult = Hex
// TODO make this the same as our load state
// anvil_loadState tf
export type AnvilLoadStateResult = null
// anvil_deal
export type AnvilDealResult = {
errors?: Error[]
}
59 changes: 59 additions & 0 deletions packages/actions/src/anvil/anvilDealHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ERC20 } from '@tevm/contract'
import { numberToHex } from '@tevm/utils'
import { encodeFunctionData } from 'viem'
import { setAccountHandler } from '../SetAccount/setAccountHandler.js'
import { ethCreateAccessListProcedure } from '../eth/ethCreateAccessListProcedure.js'
import { anvilSetStorageAtJsonRpcProcedure } from './anvilSetStorageAtProcedure.js'

/**
* Deals ERC20 tokens to an account by overriding the storage of balanceOf(account)
* @param {import('@tevm/node').TevmNode} client
* @returns {import('./AnvilHandler.js').AnvilDealHandler}
*/
export const dealHandler =
(client) =>
async ({ erc20, account, amount }) => {
if (!erc20) {
return setAccountHandler(client)({
address: account,
balance: amount,
})
}

const value = numberToHex(amount, { size: 32 })

// Get storage slots accessed by balanceOf
const accessListResponse = await ethCreateAccessListProcedure(client)({
method: 'eth_createAccessList',
params: [
{
to: erc20,
data: encodeFunctionData({
abi: ERC20.abi,
functionName: 'balanceOf',
args: [account],
}),
},
],
id: 1,
jsonrpc: '2.0',
})

if (!accessListResponse.result?.accessList) {
throw new Error('Failed to get access list')
}
Comment on lines +42 to +44
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhance error handling for access list retrieval failure

The current error message might not provide sufficient context for debugging. Consider including additional details about the failure to aid in troubleshooting.

Apply this diff to improve the error message:

-if (!accessListResponse.result?.accessList) {
-	throw new Error('Failed to get access list')
+if (!accessListResponse.result?.accessList) {
+	throw new Error(`Failed to retrieve access list for ERC20 contract at address ${erc20}`)
}

Committable suggestion skipped: line range outside the PR's diff.


// Try each storage slot until we find the right one
for (const { address, storageKeys } of accessListResponse.result.accessList) {
for (const slot of storageKeys) {
await anvilSetStorageAtJsonRpcProcedure(client)({
method: 'anvil_setStorageAt',
params: [address, slot, value],
id: 1,
jsonrpc: '2.0',
})
}
}

return {}
}
55 changes: 55 additions & 0 deletions packages/actions/src/anvil/anvilDealProcedure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { hexToBigInt } from 'viem'
import { dealHandler } from './anvilDealHandler.js'

/**
* JSON-RPC procedure for anvil_deal
* Deals ERC20 tokens to an account by overriding the storage of balanceOf(account)
* @param {import('@tevm/node').TevmNode} client
* @returns {import('./AnvilProcedure.js').AnvilDealProcedure}
* @example
* ```typescript
* const response = await client.request({
* method: 'anvil_deal',
* params: [{
* erc20: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // Optional: USDC address
* account: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
* amount: 1000000n // 1 USDC (6 decimals)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure consistency in 'amount' parameter format

In the example, amount is provided as a BigInt (e.g., amount: 1000000n), but in the code, amount is converted using hexToBigInt(amount), implying amount should be a hex string. This inconsistency may cause confusion or errors. Please ensure that amount is consistently handled as either a BigInt or a hex string.

Apply this diff to align the code with the example, assuming amount is a BigInt and remove the conversion:

-		amount: hexToBigInt(amount),
+		amount: amount,

Alternatively, if amount should be a hex string, update the example to use a hex string (e.g., amount: '0xF4240') and ensure the code handles amount accordingly.

Also applies to: 29-29

* }],
* id: 1,
* jsonrpc: '2.0'
* })
* ```
*/
export const anvilDealJsonRpcProcedure = (client) => async (request) => {
const [{ erc20, account, amount }] = request.params

Comment on lines +24 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add validation for request parameters to prevent runtime errors

The code assumes that request.params is an array with at least one object. If request.params is undefined, empty, or not structured as expected, this could cause a runtime error. Adding validation for request.params will improve robustness.

Apply this diff to add parameter validation:

 export const anvilDealJsonRpcProcedure = (client) => async (request) => {
+	if (!Array.isArray(request.params) || request.params.length === 0 || typeof request.params[0] !== 'object') {
+		return {
+			jsonrpc: request.jsonrpc,
+			...(request.id !== undefined ? { id: request.id } : {}),
+			error: {
+				code: -32602,
+				message: 'Invalid params: Expected an array with at least one object.',
+			},
+		}
+	}
 	const [{ erc20, account, amount }] = request.params

Committable suggestion skipped: line range outside the PR's diff.

const result = await dealHandler(client)({
...(erc20 !== undefined ? { erc20 } : {}),
account,
amount: hexToBigInt(amount),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle potential errors when converting 'amount' with 'hexToBigInt'

If amount is not a valid hex string, hexToBigInt(amount) may throw an error. To prevent runtime exceptions, add error handling or input validation for amount.

Apply this diff to include error handling:

+	let parsedAmount
+	try {
+		parsedAmount = hexToBigInt(amount)
+	} catch (error) {
+		return {
+			jsonrpc: request.jsonrpc,
+			...(request.id !== undefined ? { id: request.id } : {}),
+			error: {
+				code: -32602,
+				message: 'Invalid amount parameter: must be a valid hex string.',
+			},
+		}
+	}

And update the amount assignment:

-		amount: hexToBigInt(amount),
+		amount: parsedAmount,

Committable suggestion skipped: line range outside the PR's diff.

})

if ('errors' in result && result.errors) {
/**
* @type {import('./AnvilJsonRpcResponse.js').AnvilDealJsonRpcResponse}
*/
const out = {
jsonrpc: request.jsonrpc,
...(request.id !== undefined ? { id: request.id } : {}),
method: 'anvil_deal',
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove 'method' from JSON-RPC response object

According to the JSON-RPC 2.0 specification, the response object should not include a method field. The method is used in requests, not in responses.

Apply this diff to remove method from the response:

In the error response:

 			jsonrpc: request.jsonrpc,
 			...(request.id !== undefined ? { id: request.id } : {}),
-			method: 'anvil_deal',
 			error: {
 				code: result.errors[0]?.code ?? -32000,
 				message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occurred',
 			},

In the success response:

 		return {
 			jsonrpc: request.jsonrpc,
 			...(request.id !== undefined ? { id: request.id } : {}),
-			method: 'anvil_deal',
 			result: {},
 		}

Also applies to: 52-52

error: {
// @ts-expect-error being lazy here
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Resolve TypeScript errors instead of suppressing them

The comment // @ts-expect-error being lazy here indicates suppression of a TypeScript error without proper resolution. It's better to address the underlying type issue to improve code quality and maintainability.

Apply this diff to fix the TypeScript error:

-				// @ts-expect-error being lazy here
 				code: (result.errors[0]?.code ?? -32000).toString(),
+				// Ensure 'code' is of the correct type
+				code: result.errors[0]?.code ?? -32000,

Committable suggestion skipped: line range outside the PR's diff.

code: (result.errors[0]?.code ?? -32000).toString(),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure 'code' in error object is a number per JSON-RPC specification

In the JSON-RPC error response, the code should be a number, not a string. Currently, code is being converted to a string.

Apply this diff to correct the error code type:

-				code: (result.errors[0]?.code ?? -32000).toString(),
+				code: result.errors[0]?.code ?? -32000,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
code: (result.errors[0]?.code ?? -32000).toString(),
code: result.errors[0]?.code ?? -32000,

message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occured',
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in error message

The error message contains a typo: 'An unknown error occured' should be 'An unknown error occurred'.

Apply this diff to fix the typo:

-				message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occured',
+				message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occurred',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occured',
message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occurred',

},
}
return out
}
Comment on lines +26 to +47
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for exceptions thrown by 'dealHandler'

If dealHandler throws an exception, the current code does not catch it, which may lead to unhandled promise rejections. Wrapping the dealHandler call in a try-catch block will ensure proper error handling and return a valid JSON-RPC error response.

Apply this diff to add error handling:

 export const anvilDealJsonRpcProcedure = (client) => async (request) => {
 	const [{ erc20, account, amount }] = request.params

+	try {
 		const result = await dealHandler(client)({
 			...(erc20 !== undefined ? { erc20 } : {}),
 			account,
 			amount: hexToBigInt(amount),
 		})

 		if ('errors' in result && result.errors) {
 			const out = {
 				jsonrpc: request.jsonrpc,
 				...(request.id !== undefined ? { id: request.id } : {}),
-				method: 'anvil_deal',
 				error: {
 					code: result.errors[0]?.code ?? -32000,
 					message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occurred',
 				},
 			}
 			return out
 		}

 		return {
 			jsonrpc: request.jsonrpc,
 			...(request.id !== undefined ? { id: request.id } : {}),
-			method: 'anvil_deal',
 			result: {},
 		}
+	} catch (error) {
+		return {
+			jsonrpc: request.jsonrpc,
+			...(request.id !== undefined ? { id: request.id } : {}),
+			error: {
+				code: -32603,
+				message: error.message || 'Internal error',
+			},
+		}
+	}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const result = await dealHandler(client)({
...(erc20 !== undefined ? { erc20 } : {}),
account,
amount: hexToBigInt(amount),
})
if ('errors' in result && result.errors) {
/**
* @type {import('./AnvilJsonRpcResponse.js').AnvilDealJsonRpcResponse}
*/
const out = {
jsonrpc: request.jsonrpc,
...(request.id !== undefined ? { id: request.id } : {}),
method: 'anvil_deal',
error: {
// @ts-expect-error being lazy here
code: (result.errors[0]?.code ?? -32000).toString(),
message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occured',
},
}
return out
}
try {
const result = await dealHandler(client)({
...(erc20 !== undefined ? { erc20 } : {}),
account,
amount: hexToBigInt(amount),
})
if ('errors' in result && result.errors) {
/**
* @type {import('./AnvilJsonRpcResponse.js').AnvilDealJsonRpcResponse}
*/
const out = {
jsonrpc: request.jsonrpc,
...(request.id !== undefined ? { id: request.id } : {}),
error: {
// @ts-expect-error being lazy here
code: (result.errors[0]?.code ?? -32000).toString(),
message: result.errors[0]?.message ?? result.errors[0]?.name ?? 'An unknown error occured',
},
}
return out
}
return {
jsonrpc: request.jsonrpc,
...(request.id !== undefined ? { id: request.id } : {}),
result: {},
}
} catch (error) {
return {
jsonrpc: request.jsonrpc,
...(request.id !== undefined ? { id: request.id } : {}),
error: {
code: -32603,
message: error.message || 'Internal error',
},
}
}


return {
jsonrpc: request.jsonrpc,
...(request.id !== undefined ? { id: request.id } : {}),
method: 'anvil_deal',
result: {},
}
}
62 changes: 62 additions & 0 deletions packages/actions/src/anvil/anvilDealProcedure.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { createAddress } from '@tevm/address'
import { createTevmNode } from '@tevm/node'
import { TestERC20 } from '@tevm/test-utils'
import { describe, expect, it } from 'vitest'
import { setAccountHandler } from '../SetAccount/setAccountHandler.js'
import { anvilDealJsonRpcProcedure } from './anvilDealProcedure.js'

describe('anvilDealJsonRpcProcedure', () => {
it('should deal ERC20 tokens', async () => {
const client = createTevmNode()
const erc20 = TestERC20.withAddress(createAddress('0x66a44').toString())

// Deploy contract
await setAccountHandler(client)({
address: erc20.address,
deployedBytecode: erc20.deployedBytecode,
})

const result = await anvilDealJsonRpcProcedure(client)({
method: 'anvil_deal',
params: [
{
erc20: erc20.address,
account: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
amount: '0xf4240', // 1M (6 decimals)
},
],
id: 1,
jsonrpc: '2.0',
})

expect(result).toEqual({
jsonrpc: '2.0',
id: 1,
method: 'anvil_deal',
result: {},
})
})

it('should deal native tokens when no erc20 address provided', async () => {
const client = createTevmNode()

const result = await anvilDealJsonRpcProcedure(client)({
method: 'anvil_deal',
params: [
{
account: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
amount: '0xde0b6b3a7640000', // 1 ETH
},
],
id: 1,
jsonrpc: '2.0',
})

expect(result).toEqual({
jsonrpc: '2.0',
id: 1,
method: 'anvil_deal',
result: {},
})
})
Comment on lines +40 to +61
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test coverage for native token dealing.

Similar to the ERC20 test case, this test could benefit from additional verifications and documentation.

Consider applying these improvements:

 it('should deal native tokens when no erc20 address provided', async () => {
   const client = createTevmNode()
+  const account = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
+  const amount = '0xde0b6b3a7640000' // 1 ETH (1e18 wei)

+  // Get initial balance
+  const initialBalance = await client.getBalance({
+    address: account,
+  })

   const result = await anvilDealJsonRpcProcedure(client)({
     method: 'anvil_deal',
     params: [
       {
-        account: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
-        amount: '0xde0b6b3a7640000', // 1 ETH
+        account,
+        amount,
       },
     ],
     id: 1,
     jsonrpc: '2.0',
   })

+  // Verify balance increase
+  const finalBalance = await client.getBalance({
+    address: account,
+  })
+  expect(finalBalance - initialBalance).toBe(BigInt(amount))

   expect(result).toEqual({
     jsonrpc: '2.0',
     id: 1,
     method: 'anvil_deal',
-    result: {},
+    result: {
+      success: true,
+      balance: amount,
+    },
   })
 })

Committable suggestion skipped: line range outside the PR's diff.

})
2 changes: 2 additions & 0 deletions packages/actions/src/anvil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export * from './anvilSetCoinbaseProcedure.js'
export * from './anvilSetNonceProcedure.js'
export * from './anvilSetStorageAtProcedure.js'
export * from './anvilStopImpersonatingAccountProcedure.js'
export * from './anvilDealHandler.js'
export * from './anvilDealProcedure.js'
4 changes: 4 additions & 0 deletions packages/actions/src/createHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getAccountProcedure } from './GetAccount/getAccountProcedure.js'
import { loadStateProcedure } from './LoadState/loadStateProcedure.js'
import { mineProcedure } from './Mine/mineProcedure.js'
import { setAccountProcedure } from './SetAccount/setAccountProcedure.js'
import { anvilDealJsonRpcProcedure } from './anvil/anvilDealProcedure.js'
import { anvilDropTransactionJsonRpcProcedure } from './anvil/anvilDropTransactionProcedure.js'
import { anvilDumpStateJsonRpcProcedure } from './anvil/anvilDumpStateProcedure.js'
import { anvilGetAutomineJsonRpcProcedure } from './anvil/anvilGetAutomineProcedure.js'
Expand All @@ -25,6 +26,7 @@ import { chainIdProcedure } from './eth/chainIdProcedure.js'
import { ethBlobBaseFeeJsonRpcProcedure } from './eth/ethBlobBaseFeeProcedure.js'
import { ethCallProcedure } from './eth/ethCallProcedure.js'
import { ethCoinbaseJsonRpcProcedure } from './eth/ethCoinbaseProcedure.js'
import { ethCreateAccessListProcedure } from './eth/ethCreateAccessListProcedure.js'
import { ethEstimateGasJsonRpcProcedure } from './eth/ethEstimateGasProcedure.js'
import { ethGetBlockByHashJsonRpcProcedure } from './eth/ethGetBlockByHashProcedure.js'
import { ethGetBlockByNumberJsonRpcProcedure } from './eth/ethGetBlockByNumberProcedure.js'
Expand Down Expand Up @@ -92,6 +94,7 @@ export const createHandlers = (client) => {
eth_blockNumber: blockNumberProcedure(client),
eth_chainId: chainIdProcedure(client),
eth_call: ethCallProcedure(client),
eth_createAccessList: ethCreateAccessListProcedure(client),
eth_getCode: getCodeProcedure(client),
eth_getStorageAt: getStorageAtProcedure(client),
eth_gasPrice: gasPriceProcedure(client),
Expand Down Expand Up @@ -145,6 +148,7 @@ export const createHandlers = (client) => {
}

const anvilHandlers = {
anvil_deal: anvilDealJsonRpcProcedure(client),
anvil_setCode: anvilSetCodeJsonRpcProcedure(client),
anvil_setBalance: anvilSetBalanceJsonRpcProcedure(client),
anvil_setNonce: anvilSetNonceJsonRpcProcedure(client),
Expand Down
11 changes: 10 additions & 1 deletion packages/actions/src/eth/EthJsonRpcRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type JsonRpcTransaction = {
/**
* The address from which the transaction is sent
*/
from: Address
from?: Address
/**
* The address to which the transaction is addressed
*/
Expand Down Expand Up @@ -293,6 +293,14 @@ export type EthNewPendingTransactionFilterJsonRpcRequest = JsonRpcRequest<
* JSON-RPC request for `eth_uninstallFilter` procedure
*/
export type EthUninstallFilterJsonRpcRequest = JsonRpcRequest<'eth_uninstallFilter', readonly [filterId: Hex]>
// eth_createAccessList
/**
* JSON-RPC request for `eth_createAccessList` procedure
*/
export type EthCreateAccessListJsonRpcRequest = JsonRpcRequest<
'eth_createAccessList',
readonly [tx: JsonRpcTransaction, tag?: BlockTag | Hex]
>

export type EthJsonRpcRequest =
| EthAccountsJsonRpcRequest
Expand Down Expand Up @@ -334,3 +342,4 @@ export type EthJsonRpcRequest =
| EthNewBlockFilterJsonRpcRequest
| EthNewPendingTransactionFilterJsonRpcRequest
| EthUninstallFilterJsonRpcRequest
| EthCreateAccessListJsonRpcRequest
16 changes: 16 additions & 0 deletions packages/actions/src/eth/EthJsonRpcResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,19 @@ export type EthNewPendingTransactionFilterJsonRpcResponse = JsonRpcResponse<
* JSON-RPC response for `eth_uninstallFilter` procedure
*/
export type EthUninstallFilterJsonRpcResponse = JsonRpcResponse<'eth_uninstallFilter', boolean, string | number>

// eth_createAccessList
/**
* JSON-RPC response for `eth_createAccessList` procedure
*/
export type EthCreateAccessListJsonRpcResponse = JsonRpcResponse<
'eth_createAccessList',
{
accessList: Array<{
address: Address
storageKeys: Hex[]
}>
gasUsed: Hex
},
string | number
>
Loading
Loading