-
-
Notifications
You must be signed in to change notification settings - Fork 26
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(contract): Add address utility to contract #828
✨ Feat(contract): Add address utility to contract #828
Conversation
🦋 Changeset detectedLatest commit: 78aaa35 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Current dependencies on/for this PR: This stack of pull requests is managed by Graphite. |
WalkthroughThe overarching update streamlines the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files ignored due to path filters (1)
packages/contract/package.json
is excluded by:!**/*.json
Files selected for processing (57)
- .changeset/neat-sloths-film.md (1 hunks)
- bundler/base/TestContract.d.ts (2 hunks)
- bundler/base/src/bundler.spec.ts (8 hunks)
- bundler/bun/docs/modules.md (2 hunks)
- bundler/bundler-cache/TestContract.d.ts (2 hunks)
- bundler/compiler/TestContract.d.ts (2 hunks)
- bundler/resolutions/TestContract.d.ts (2 hunks)
- bundler/runtime/docs/modules.md (2 hunks)
- bundler/runtime/src/generateRuntime.js (2 hunks)
- bundler/runtime/src/generateRuntime.spec.ts (2 hunks)
- bundler/runtime/src/generateTevmBody.js (2 hunks)
- bundler/runtime/src/generateTevmBody.spec.ts (4 hunks)
- bundler/runtime/src/generateTevmBodyDts.js (2 hunks)
- bundler/runtime/src/generateTevmBodyDts.spec.ts (1 hunks)
- bundler/runtime/vitest.config.ts (1 hunks)
- bundler/solc/TestContract.d.ts (2 hunks)
- extensions/viem/src/tests/ERC20.sol.ts (2 hunks)
- lsp/ts-plugin/src/decorators/getDefinitionAtPosition.spec.ts (1 hunks)
- lsp/ts-plugin/src/decorators/getDefinitionAtPosition.ts (2 hunks)
- lsp/ts-plugin/src/decorators/getScriptSnapshot.spec.ts (1 hunks)
- packages/contract/docs/modules.md (3 hunks)
- packages/contract/src/Contract.ts (1 hunks)
- packages/contract/src/Script.ts (1 hunks)
- packages/contract/src/createContract.js (1 hunks)
- packages/contract/src/createContract.spec.ts (1 hunks)
- packages/contract/src/createScript.js (1 hunks)
- packages/contract/src/createScript.spec.ts (1 hunks)
- packages/contract/src/event/Event.ts (4 hunks)
- packages/contract/src/event/eventFactory.js (1 hunks)
- packages/contract/src/event/eventFactory.spec.ts (1 hunks)
- packages/contract/src/index.js (1 hunks)
- packages/contract/src/index.ts (1 hunks)
- packages/contract/src/read/Read.ts (3 hunks)
- packages/contract/src/read/readFactory.js (1 hunks)
- packages/contract/src/read/readFactory.spec.ts (1 hunks)
- packages/contract/src/types.ts (1 hunks)
- packages/contract/src/write/Write.ts (3 hunks)
- packages/contract/src/write/writeFactory.js (1 hunks)
- packages/contract/src/write/writeFactory.spec.ts (1 hunks)
- tevm/contract/index.d.ts (1 hunks)
- tevm/contract/index.js (1 hunks)
- tevm/contract/index.ts (1 hunks)
- tevm/docs/modules/contract.md (2 hunks)
- tevm/docs/modules/index.md (5 hunks)
- tevm/docs/modules/vm.md (1 hunks)
- tevm/index.d.ts (1 hunks)
- tevm/index.js (1 hunks)
- tevm/index.ts (1 hunks)
- vm/client/src/test/Add.s.sol.ts (2 hunks)
- vm/client/src/test/ERC20.sol.ts (2 hunks)
- vm/predeploys/docs/classes/Predeploy.md (5 hunks)
- vm/predeploys/docs/modules.md (2 hunks)
- vm/predeploys/src/definePredeploy.ts (2 hunks)
- vm/predeploys/src/predeploy.spec.ts (1 hunks)
- vm/vm/docs/modules.md (1 hunks)
- vm/vm/src/CreateEVMOptions.ts (1 hunks)
- vm/vm/src/test/predeploy.spec.ts (1 hunks)
Files skipped from review due to trivial changes (5)
- bundler/bun/docs/modules.md
- bundler/runtime/docs/modules.md
- lsp/ts-plugin/src/decorators/getDefinitionAtPosition.spec.ts
- tevm/docs/modules/contract.md
- tevm/index.ts
Additional comments: 93
tevm/contract/index.d.ts (1)
- 2-3: The changes correctly reflect the renaming of
TevmContract
toContract
andcreateTevmContract
tocreateContract
. This aligns with the PR objectives and the AI-generated summary.tevm/contract/index.ts (1)
- 2-9: The changes correctly reflect the renaming of
TevmContract
toContract
andcreateTevmContract
tocreateContract
. This aligns with the PR objectives and the AI-generated summary.tevm/contract/index.js (1)
- 2-2: The changes correctly reflect the renaming of
createTevmContract
tocreateContract
. This aligns with the PR objectives and the AI-generated summary.bundler/runtime/vitest.config.ts (1)
- 7-12: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [5-9]
The simplification of the
coverage
configuration by removing several properties is a positive change for maintainability, assuming that the removed properties are indeed not required.tevm/index.js (1)
- 3-3: The changes correctly reflect the renaming of
createTevmContract
tocreateContract
. This aligns with the PR objectives and the AI-generated summary.vm/vm/src/CreateEVMOptions.ts (1)
- 11-11: The change in
CreateEVMOptions
to accept only two type parameters forcustomPredeploys
suggests a simplification of the type structure. Ensure that all usages ofcustomPredeploys
are updated to reflect this change.Verification successful
The usage of
customPredeploys
inpredeploy.spec.ts
is consistent with the updatedCustomPredeploy
type structure inCreateEVMOptions.ts
, which now accepts only two type parameters. Thepredeploy
variable is correctly defined with the necessaryaddress
andcontract
properties to match theCustomPredeploy
type.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that all usages of customPredeploys have been updated. rg "customPredeploys" --type tsLength of output: 188
Script:
#!/bin/bash # Check the definition of the CustomPredeploy type ast-grep --lang typescript --pattern 'type CustomPredeploy<$_, $_> = $$$' # Inspect the predeploy variable in predeploy.spec.ts rg "const predeploy =" vm/vm/src/test/predeploy.spec.tsLength of output: 632
Script:
#!/bin/bash # Inspect the parameters passed to definePredeploy in predeploy.spec.ts rg "definePredeploy\(" vm/vm/src/test/predeploy.spec.tsLength of output: 94
Script:
#!/bin/bash # Extract the full definition of the predeploy variable to see the actual arguments passed to definePredeploy rg -A 10 "const predeploy =" vm/vm/src/test/predeploy.spec.tsLength of output: 262
packages/contract/src/index.js (1)
- 1-17: The export changes and additions are consistent with the PR objectives and the AI-generated summary, which includes the introduction of
createScript
and the reorganization of utility functions.tevm/index.d.ts (1)
- 20-21: The changes correctly reflect the renaming of
TevmContract
toContract
andcreateTevmContract
tocreateContract
. This aligns with the PR objectives and the AI-generated summary.packages/contract/src/index.ts (1)
- 1-22: The changes in
index.ts
correctly introduce new type exports and utility functions, aligning with the PR objectives and the AI-generated summary..changeset/neat-sloths-film.md (1)
- 5-10: The changeset file correctly documents the major changes made to
@tevm/contract
, including the renaming ofTevmContract
andcreateTevmContract
, the addition ofScript
, and the newwithAddress
method.packages/contract/src/Script.ts (1)
- 7-28: The
Script
type definition is well-structured and includes awithAddress
method for associating an address with a script, which is a new feature mentioned in the PR objectives and the AI-generated summary.vm/predeploys/src/predeploy.spec.ts (1)
- 12-12: The test file reflects the change from
createTevmContract
tocreateScript
, which is consistent with the changes described in the PR objectives and the AI-generated summary.packages/contract/src/Contract.ts (1)
- 6-27: The
Contract
type definition correctly omits thebytecode
anddeployedBytecode
properties, aligning with the PR objectives and the AI-generated summary.packages/contract/src/types.ts (1)
- 4-39: The
CreateContractParams
andCreateScriptParams
types are correctly defined, and theCreateContract
andCreateScript
types are consistent with the changes described in the PR objectives and the AI-generated summary.vm/predeploys/src/definePredeploy.ts (3)
- 11-11: The
CustomPredeploy
type now correctly usesScript
instead ofTevmContract
, which is consistent with the changes described in the PR objectives and the AI-generated summary.- 18-18: The
Predeploy
class correctly usesScript
instead ofTevmContract
, aligning with the broader refactoring efforts and the introduction of the newScript
type.- 33-36: The
definePredeploy
function has been updated to reflect the removal ofTBytecode
andTDeployedBytecode
from its generic type parameters, which is consistent with the changes described in the PR objectives and the AI-generated summary.packages/contract/src/event/eventFactory.js (1)
- 12-41: The
eventsFactory
function is correctly implemented to create event action creators from parameters. The internal TODO comments suggest areas for future improvement, which is good for maintainability.vm/vm/src/test/predeploy.spec.ts (1)
- 12-12: The test file reflects the change from
createTevmContract
tocreateScript
, which is consistent with the changes described in the PR objectives and the AI-generated summary.vm/client/src/test/Add.s.sol.ts (1)
- 33-36: The change from
createTevmContract
tocreateScript
and the update of thebytecode
property fromundefined
to'0x0'
are consistent with the changes described in the PR objectives and the AI-generated summary.bundler/runtime/src/generateRuntime.js (1)
- 29-30: The dynamic selection of imports based on
moduleType
andincludeBytecode
parameters is a good example of conditional logic to handle different scenarios, which improves the flexibility of import handling.vm/predeploys/docs/modules.md (2)
- 23-23: The
CustomPredeploy
type alias documentation correctly reflects the removal ofTBytecode
andTDeployedBytecode
type parameters, aligning with the changes in the codebase.- 47-47: The
definePredeploy
function documentation has been updated to reflect the changes in the codebase, removing theTBytecode
andTDeployedBytecode
type parameters.packages/contract/src/read/Read.ts (1)
- 27-52: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [16-51]
The
Read
type has been updated to includeTAddress
andTAddressArgs
, which adds conditional properties based on the length ofTArgs
. This change is consistent with the PR objectives and the AI-generated summary.packages/contract/src/write/Write.ts (1)
- 30-55: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [16-54]
The
Write
type has been updated to includeTAddress
andTAddressArgs
, which adds conditional properties based on the length ofTArgs
. This change is consistent with the PR objectives and the AI-generated summary.packages/contract/src/read/readFactory.js (1)
- 12-50: The
readFactory
function is correctly implemented to create read action creators from parameters. The internal TODO comments suggest areas for future improvement, which is good for maintainability.bundler/runtime/src/generateTevmBodyDts.js (1)
- 23-35: The
generateDtsBody
function now conditionally exports a different type of script based on theincludeBytecode
parameter, which is a good example of conditional logic to handle different scenarios and improves the flexibility of the code.packages/contract/src/write/writeFactory.js (1)
- 12-51: The
writeFactory
function is correctly implemented to create write action creators from parameters. The internal TODO comments suggest areas for future improvement, which is good for maintainability.packages/contract/src/createContract.js (1)
- 12-46: The
createContract
function is correctly implemented to create a contract instance from a human-readable ABI. ThewithAddress
method is a new feature that aligns with the PR objectives and the AI-generated summary.packages/contract/src/event/eventFactory.spec.ts (1)
- 7-7: The test file reflects the change from
createTevmContract
tocreateContract
, which is consistent with the changes described in the PR objectives and the AI-generated summary.vm/predeploys/docs/classes/Predeploy.md (2)
- 3-3: The documentation for the
Predeploy
class correctly reflects the removal ofTBytecode
andTDeployedBytecode
from the type parameters, aligning with the changes in the codebase.- 59-59: The
contract
property type has been updated toScript
with onlyTName
andTHumanReadableAbi
type parameters, which is consistent with the changes in the codebase.bundler/runtime/src/generateTevmBody.js (2)
- 21-27: The
generateTevmBody
function has been modified to conditionally include bytecode generation based on theincludeBytecode
parameter. This change is consistent with the PR objectives and the AI-generated summary.- 44-46: The conditional logic to handle different module types and whether to include bytecode is correctly implemented, improving the flexibility of the code.
packages/contract/src/createScript.js (2)
- 7-16: The function
createScript
is well-documented with a JSDoc comment, which is good for maintainability.- 39-66: The
withAddress
method is a good example of a fluent interface, allowing for chaining method calls. However, ensure that thegetAddress
function has proper error handling for invalid addresses.Verification successful
The
getAddress
function in thegetAddress.js
file checks if the provided address is valid using theisAddress
function. If the address is not valid, it throws anInvalidAddressError
. This indicates that thegetAddress
function does indeed have proper error handling for invalid addresses.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify getAddress handles errors gracefully rg --type js "getAddress"Length of output: 9107
Script:
#!/bin/bash # Inspect the implementation of getAddress to verify error handling cat packages/viem-effect/src-viem/_esm/utils/address/getAddress.jsLength of output: 1070
packages/contract/src/event/Event.ts (2)
- 32-33: The type alias
TAddressArgs
is a conditional type that provides an empty object or an object with anaddress
property based onTAddress
. This is a good use of TypeScript's type system to enforce function parameter requirements conditionally.- 73-73: The spread operator
...TAddressArgs
is used correctly to conditionally add theaddress
property to the event filter parameters. This maintains type safety and flexibility.bundler/runtime/src/generateTevmBodyDts.spec.ts (2)
- 57-57: The JSDoc comment correctly documents the
MyContract
object, which is helpful for developers to understand the purpose and usage of the contract.- 61-61: The export statement for
MyContract
is clear and concise, correctly exporting the contract as a constant.tevm/docs/modules/vm.md (1)
- 38-38: The
customPredeploys
property in theCreateEVMOptions
type alias has been simplified to accept an array ofCustomPredeploy
with two generic types instead of four. This change should be verified to ensure it aligns with the intended use ofcustomPredeploys
.Verification successful
The
CustomPredeploy
type and thedefinePredeploy
function have been verified. The change tocustomPredeploys
accepting two generic types is consistent with its usage in the codebase, as seen in the test filepredeploy.spec.ts
. The simplification aligns with the intended use ofcustomPredeploys
.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the usage of customPredeploys throughout the codebase rg --type ts "customPredeploys"Length of output: 188
Script:
#!/bin/bash # Examine the definition of CustomPredeploy in CreateEVMOptions.ts cat vm/vm/src/CreateEVMOptions.ts # Look at the usage of customPredeploys in predeploy.spec.ts cat vm/vm/src/test/predeploy.spec.tsLength of output: 1876
Script:
#!/bin/bash # Verify the definition of CustomPredeploy rg --type ts "CustomPredeploy" # Verify the definePredeploy function rg --type ts "definePredeploy"Length of output: 856
Script:
#!/bin/bash # Examine the definition of CustomPredeploy and the implementation of definePredeploy cat vm/predeploys/src/definePredeploy.tsLength of output: 1184
bundler/base/TestContract.d.ts (1)
- 125-125: The export of
TestContract
is updated to use theContract
type instead ofTevmContract
. This change should be consistent across all related files and usages.Verification successful
The output from the script indicates that the mention of
TevmContract
inexamples/vite/src/wagmi/WagmiEvents.tsx
is within a comment. Since it's not part of the code that would affect the functionality or type definitions, it doesn't contradict the review comment thatTestContract
should use theContract
type consistently across all related files and usages.Therefore, the review comment is verified as the actual code has been updated to use
Contract
instead ofTevmContract
, and the remaining instance is simply a comment that does not impact the code's operation.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that all instances of TevmContract have been updated to Contract rg --type ts "TevmContract"Length of output: 107
Script:
#!/bin/bash # Check the context of TevmContract usage in WagmiEvents.tsx rg "TevmContract" examples/vite/src/wagmi/WagmiEvents.tsxLength of output: 97
packages/contract/src/write/writeFactory.spec.ts (2)
- 7-7: The
contract
object is created using thecreateContract
function with the correct properties. This setup is crucial for the subsequent tests.- 1-12: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [57-57]
The inline snapshot for
writeInfo.args
is a good practice for testing, ensuring that the function returns the expected arguments.bundler/runtime/src/generateTevmBody.spec.ts (1)
- 46-46: The commonjs export of
MyContract
usingcreateContract
is correct and aligns with the changes in the rest of the codebase.packages/contract/src/read/readFactory.spec.ts (2)
- 7-7: The
contract
object is created using thecreateContract
function with the correct properties. This setup is crucial for the subsequent tests.- 1-12: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [57-57]
The inline snapshot for
readInfo.args
is a good practice for testing, ensuring that the function returns the expected arguments.vm/vm/docs/modules.md (1)
- 38-38: The
customPredeploys
property in theCreateEVMOptions
type alias has been simplified to accept an array ofCustomPredeploy
with two generic types instead of four. This change should be verified to ensure it aligns with the intended use ofcustomPredeploys
.Verification successful
The output from the shell script indicates that the
customPredeploys
property is used in two TypeScript files:CreateEVMOptions.ts
andpredeploy.spec.ts
. The change inCreateEVMOptions.ts
reflects the update mentioned in the PR summary, wherecustomPredeploys
now accepts an array ofCustomPredeploy
with two generic types.To verify the alignment of this change with the intended use of
customPredeploys
, we should examine howcustomPredeploys
is utilized inpredeploy.spec.ts
. This will help us understand if the simplification from four generic types to two is consistent with its usage in tests, which can be indicative of general usage patterns.
The contents of
predeploy.spec.ts
show a test case that uses thecustomPredeploys
property. The test creates apredeploy
object usingdefinePredeploy
and then passes an array containing this object to thecustomPredeploys
property when creating atevm
instance.The
predeploy
object is constructed with acontract
that is created bycreateScript
, which suggests that theCustomPredeploy
type is expected to work with a script-like object. This aligns with the change inCreateEVMOptions.ts
wherecustomPredeploys
now accepts an array ofCustomPredeploy
with two generic types.Given the usage in the test file, it seems that the simplification of the
CustomPredeploy
type to two generic types is consistent with its intended use, at least in the context of this test. The test does not appear to require four generic types for theCustomPredeploy
objects, supporting the change made in the PR.Based on the information gathered, the review comment is addressed, and the change to
customPredeploys
aligns with the intended use as evidenced by the test case.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the usage of customPredeploys throughout the codebase rg --type ts "customPredeploys"Length of output: 188
Script:
#!/bin/bash # Examine the usage of customPredeploys in predeploy.spec.ts cat vm/vm/src/test/predeploy.spec.tsLength of output: 1426
lsp/ts-plugin/src/decorators/getDefinitionAtPosition.ts (6)
- 38-38: The variable
tevmContractPath
has been renamed toContractPath
. Ensure that all references to this variable have been updated accordingly.- 41-41: The check for
ContractPath
being falsy is correct. It ensures that if the path is not found, the original definition is returned without further processing.- 47-47: The
ContractPath
is used correctly to resolve the.d.ts
files. This is consistent with the renaming oftevmContractPath
toContractPath
.- 54-54: The error message correctly reflects the new variable name
ContractPath
. It's good practice to have descriptive error messages that aid in debugging.- 83-83: The error message is consistent with the new variable naming and provides clear feedback when definitions cannot be found.
- 88-88: The default contract name is set to 'Contract' if the filename cannot be derived from
ContractPath
. This is a sensible default and aligns with the renaming changes.packages/contract/src/createContract.spec.ts (8)
- 1-10: The test setup for
createContract
looks correct and uses thedummyAbi
fixture as expected.- 13-13: The test for the contract name is simple and effective, ensuring that the
name
property is set correctly.- 17-17: The test for ABI containment is correct, verifying that the contract's ABI matches the expected format.
- 21-21: The test for generating a human-readable ABI is good, ensuring that the property is defined.
- 25-34: The snapshot test for the
read
function is appropriate, capturing the expected structure of the contract's read functions.- 37-46: The snapshot test for the
write
function is similar to theread
function test and is correctly implemented.- 50-54: The snapshot test for the
events
function is correct, ensuring that the contract's events are captured as expected.- 59-164: The tests for
read
,write
, andevents
with an address are comprehensive and use inline snapshots to verify the behavior.lsp/ts-plugin/src/decorators/getScriptSnapshot.spec.ts (1)
- 135-147: The generated
.d.ts
file for solidity files includes the correct import from@tevm/contract
and the correct contract types forHelloWorld
andHelloWorld2
.packages/contract/src/createScript.spec.ts (9)
- 1-11: The setup for
createScript
is correct, including the new propertiesbytecode
anddeployedBytecode
.- 14-16: The tests for
bytecode
anddeployedBytecode
are correct, ensuring that the properties are set as expected.- 18-19: The test for the contract name is consistent with the previous test in
createContract.spec.ts
and is correct.- 22-23: The test for ABI containment is correct and mirrors the test in
createContract.spec.ts
.- 26-27: The test for generating a human-readable ABI is correct and consistent with the
createContract
tests.- 30-39: The snapshot test for the
read
function is correct and captures the expected structure of the script's read functions.- 43-52: The snapshot test for the
write
function is correct and consistent with theread
function test.- 56-60: The snapshot test for the
events
function is correct, ensuring that the script's events are captured as expected.- 65-169: The tests for
read
,write
, andevents
with an address are comprehensive and use inline snapshots to verify the behavior, including thebytecode
anddeployedBytecode
.extensions/viem/src/tests/ERC20.sol.ts (2)
- 2-2: The import statement has been updated to use
createScript
instead ofcreateTevmContract
, which is consistent with the PR's objectives.- 292-294: The
ERC20
export has been updated to usecreateScript
with a placeholderbytecode
value of'0x0'
. This change is consistent with the PR's objectives and the AI-generated summary.vm/client/src/test/ERC20.sol.ts (1)
- 2-2: The import statement has been updated to reflect the renaming of
createTevmContract
tocreateScript
. This change is consistent with the PR objectives and the AI-generated summary.tevm/docs/modules/index.md (4)
- 15-15: The addition of the
Contract
type alias is consistent with the PR objectives and the AI-generated summary, which mentions the introduction of aContract
entity.- 28-28: The addition of the
createContract
function is consistent with the PR objectives and the AI-generated summary, which mentions the addition of thecreateContract
function.- 179-202: The
Contract
type alias has been added with a comprehensive set of properties and methods. This change is consistent with the PR objectives and the AI-generated summary, which mentions the introduction of aContract
entity.- 360-362: The
createContract
function has been added to the documentation. This change is consistent with the PR objectives and the AI-generated summary, which mentions the addition of thecreateContract
function.packages/contract/docs/modules.md (6)
- 9-15: The type aliases section has been updated to reflect the new naming conventions and additional types. This change aligns with the PR objectives and the AI-generated summary.
- 19-28: New functions
createScript
,formatEther
,formatGwei
, andformatLog
have been added to the documentation. Ensure that these functions are properly implemented and tested in the codebase.Verification successful
The search results confirm the implementation of the functions
createScript
,formatEther
,formatGwei
, andformatLog
in various.js
and.ts
files within the codebase. Additionally, there are test files such asformatEther.test.ts
,formatGwei.test.ts
, andlog.test.ts
that contain tests for these functions, indicating that they have been tested.Based on the provided output, it is evident that the new functions added to the documentation are implemented and tested in the codebase.
* 39-60: The `Contract` type alias has been updated. The optional `bytecode` and `deployedBytecode` properties are now marked as potentially `undefined`, which is a significant change. Ensure that all usages of the `Contract` type are checked for compatibility with this change. * 144-165: The `Script` type alias has been introduced with properties including `bytecode` and `deployedBytecode`. This change is consistent with the PR objectives to separate concerns between `Contract` and `Script`. * 195-215: The `createContract` function has been updated in the documentation. Ensure that the implementation of this function matches the updated signature and that all references to the old `createTevmContract` function have been updated.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the implementation of new functions in the codebase rg --type md 'createScript|formatEther|formatGwei|formatLog'Length of output: 5193
Script:
#!/bin/bash # Search for the implementation of the functions in JavaScript or TypeScript files rg 'createScript|formatEther|formatGwei|formatLog' --type js --type ts # Search for test cases involving these functions rg 'createScript|formatEther|formatGwei|formatLog' --type js --type ts --glob '*.{test,spec}.{js,ts}'Length of output: 52154
Verification successful
The output from the
rg
command has provided us with several files that contain thecreateContract
export. However, the actual implementation details of thecreateContract
function are not fully visible in the provided output. The filepackages/contract/src/index.ts
seems to be exportingcreateContract
, which is a strong indication that the actual function definition would be in thepackages/contract/src/createContract.js
file.To verify the implementation of the
createContract
function, we need to view the contents of thecreateContract.js
file. Let's proceed with that.
The contents of
createContract.js
show that thecreateContract
function is indeed implemented and matches the documentation provided in themodules.md
file. The function takes an object withname
andhumanReadableAbi
properties, processes the ABI, and returns a contract object with methods for events, write, and read operations. It also includes awithAddress
method that allows setting an address for the contract.Based on the provided output, the implementation of
createContract
matches the updated signature in the documentation, and there are no references to the oldcreateTevmContract
function, which suggests that the PR's changes have been correctly implemented and the documentation has been updated accordingly.* 225-244: The `createScript` function has been added to the documentation. Verify that this function is implemented and used correctly in the codebase.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for the correct implementation and usage of createContract rg --type ts 'createContract' # Ensure no references to the old createTevmContract remain rg --type ts 'createTevmContract'Length of output: 24181
Script:
#!/bin/bash # Search for the definition of `createContract` to verify its signature ast-grep --lang typescript --pattern $'function createContract($_, $_) { $$$ }'Length of output: 80
Script:
#!/bin/bash # Adjust the search pattern to account for different ways `createContract` could be defined or exported ast-grep --lang typescript --pattern $'export function createContract($_, $_) { $$$ }' ast-grep --lang typescript --pattern $'export const createContract = ($_,$_,$$$) => $$$' ast-grep --lang typescript --pattern $'export class $_ { $$$ createContract($_, $_) { $$$ } $$$ }'Length of output: 277
Script:
#!/bin/bash # Find the file that likely contains the definition of `createContract` rg --type ts --files-with-matches 'export.*createContract' | xargs head -n 30Length of output: 5807
Script:
#!/bin/bash # Display the contents of the createContract.js file to verify the implementation cat packages/contract/src/createContract.jsLength of output: 1578
Verification successful
The
createScript
function is implemented inpackages/contract/src/createScript.js
and is used correctly across various test files, such asvm/vm/src/test/predeploy.spec.ts
. The function includes awithAddress
method, and there are tests inpackages/contract/src/createScript.spec.ts
that verify its functionality. Based on the provided context, the implementation and usage ofcreateScript
in the codebase are verified.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the implementation and usage of createScript rg --type ts 'createScript'Length of output: 1171
Script:
#!/bin/bash # Check the implementation of createScript cat packages/contract/src/createScript.js # Review the test cases for createScript cat packages/contract/src/createScript.spec.ts # Examine usage in vm/vm/src/test/predeploy.spec.ts as an example cat vm/vm/src/test/predeploy.spec.tsLength of output: 7334
bundler/base/src/bundler.spec.ts (8)
- 302-308: The test code has been updated to use the new
Contract
type instead ofTevmContract
. This change is consistent with the PR objectives and the AI-generated summary.- 387-393: The test code has been updated to use the new
Contract
type instead ofTevmContract
. This change is consistent with the PR objectives and the AI-generated summary.- 481-483: The test code has been updated to use the new
createContract
function instead ofcreateTevmContract
. This change is consistent with the PR objectives and the AI-generated summary.- 571-573: The test code has been updated to use the new
createContract
function instead ofcreateTevmContract
. This change is consistent with the PR objectives and the AI-generated summary.- 661-663: The test code has been updated to use CommonJS require syntax for importing
createContract
from@tevm/contract
. Ensure that this change is consistent with the module system used in the project.Verification successful
The project uses a mixed module system, with both CommonJS
require
and ES moduleimport
syntax present, particularly in thegenerateRuntime.js
file. This indicates that the use of CommonJSrequire
syntax in thebundler.spec.ts
file is consistent with the project's approach to handling module systems.* 751-753: The test code has been updated to use CommonJS require syntax for importing `createContract` from `@tevm/contract`. Ensure that this change is consistent with the module system used in the project.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that CommonJS require syntax is appropriate for the project rg --type js 'require\(.@tevm/contract.\)'Length of output: 246
Script:
#!/bin/bash # Verify if ES module import syntax is also used for @tevm/contract rg --type js 'import .* from .@tevm/contract.'Length of output: 610
Verification successful
The output from the latest script indicates that both CommonJS
require
syntax and ES moduleimport
syntax are used in the project when importing from@tevm/contract
. This suggests that the project may support both module systems or is in the process of transitioning between them. Given this context, the use of CommonJSrequire
syntax in thebundler.spec.ts
file is consistent with other parts of the project.* 841-843: The test code has been updated to use ES module syntax for importing `createContract` from `@tevm/contract`. This change is consistent with the PR objectives and the AI-generated summary. * 931-933: The test code has been updated to use ES module syntax for importing `createContract` from `@tevm/contract`. This change is consistent with the PR objectives and the AI-generated summary.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that CommonJS require syntax is appropriate for the project rg --type js 'require\(.@tevm/contract.\)'Length of output: 246
Script:
#!/bin/bash # Check for any ES module import syntax for @tevm/contract to verify consistency rg --type js 'import .* from .@tevm/contract.'Length of output: 610
export const ERC20 = createScript({ | ||
humanReadableAbi: formatAbi(ERC20_ABI), | ||
bytecode: undefined, | ||
bytecode: '0x0', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ERC20
export has been updated to use createScript
instead of createTevmContract
, and the bytecode
property has been changed from undefined
to '0x0'
. The change to createScript
aligns with the PR objectives and the AI-generated summary. However, setting the bytecode
to '0x0'
may not be correct if the intention is to indicate that there is no bytecode. Typically, a non-deployed contract would have undefined
bytecode, while '0x0'
suggests a bytecode that is simply empty, which could have different implications in the context of Ethereum smart contracts.
Consider reverting the bytecode
property to undefined
if the intention is to indicate a non-deployed contract, or clarify the intention behind setting it to '0x0'
.
bytecode, | ||
deployedBytecode, | ||
}) => { | ||
const abi = parseAbi(/**@type any*/ (humanReadableAbi)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of /**@type any*/
to cast humanReadableAbi
to any
bypasses TypeScript's type checking. Consider using a more specific type to benefit from type safety.
- const abi = parseAbi(/**@type any*/ (humanReadableAbi))
+ // Assuming parseAbi can accept the type returned by humanReadableAbi
+ const abi = parseAbi(humanReadableAbi)
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.
const abi = parseAbi(/**@type any*/ (humanReadableAbi)) | |
// Assuming parseAbi can accept the type returned by humanReadableAbi | |
const abi = parseAbi(humanReadableAbi) |
events: eventsFactory({ abi, bytecode, deployedBytecode }), | ||
// TODO make this more internally typesafe | ||
write: writeFactory({ methods, bytecode, deployedBytecode }), | ||
// TODO make this more internally typesafe | ||
read: readFactory({ methods, bytecode, deployedBytecode }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO comments indicate a need to make the code more internally typesafe. It's important to address these TODOs to avoid potential runtime errors due to type mismatches.
Would you like me to help with making the code more internally typesafe?
* @notice MyContract | ||
* @property balanceOf(address) Returns the amount of tokens owned by account | ||
*/ | ||
export const MyContract: TevmContract<typeof _nameMyContract, typeof _abiMyContract, undefined, undefined>; | ||
export const MyContract: Contract<typeof _nameMyContract, typeof _abiMyContract>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shell script output indicates that there is at least one instance where TevmContract
is still mentioned in the codebase, specifically within the file examples/vite/src/wagmi/WagmiEvents.tsx
. This suggests that not all instances of TevmContract
have been updated to Contract
, which is inconsistent with the PR's objective of standardizing the naming convention across the codebase.
Analysis chain
The TypeScript declaration for MyContract
is updated to use the Contract
type, which should be verified for consistency across the codebase.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Verify that all instances of TevmContract have been updated to Contract
rg --type ts "TevmContract"
Length of output: 107
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tevm/contract/index.ts (1 hunks)
Additional comments: 1
tevm/contract/index.ts (1)
- 2-20: The changes in the export declarations align with the PR objectives and AI-generated summary, which indicate a renaming and addition of types and functions to enhance the smart contract API. Ensure that all dependent modules that import these entities are updated to reflect the new names and additions.
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`.⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ # Releases ## @tevm/[email protected] ### Major Changes - [#828](#828) [`3b5f6729`](3b5f672) Thanks [@roninjin10](https://github.com/roninjin10)! - - Changed name of `TevmContract` to `Contract` - Changed name of `createTevmContract` to `createContract` - Added `Script` to be a Contract with bytecode - Removed bytecode from `Contract` - Added a new `withAddress` method for adding an address to a contract - Removed need to explicitly pass in undefined for optional params ## withAddress Before we had to spred contracts like this: ```typescript client.readContract({ address: contractAddress, ...Erc20Contract.read.balanceOf(userAddress), }); ``` Now Tevm can create a contract with an address attatched ```typescript client.readContract( Erc20Contract.withAddress(contractAddress).read.balanceOf(userAddress) ); ``` ## @tevm/[email protected] ### Minor Changes - [#822](#822) [`39a5b5e5`](39a5b5e) Thanks [@roninjin10](https://github.com/roninjin10)! - Added eth methods such as chainId getCode and getStorageAt to Tevm.eth. ### Patch Changes - [#804](#804) [`d514d111`](d514d11) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug with viem extension not decoding rawData into data - Updated dependencies \[[`8b3218b1`](8b3218b), [`39a5b5e5`](39a5b5e), [`98d76506`](98d7650)]: - @tevm/[email protected] ## [email protected] ### Minor Changes - [#822](#822) [`39a5b5e5`](39a5b5e) Thanks [@roninjin10](https://github.com/roninjin10)! - Added eth methods such as chainId getCode and getStorageAt to Tevm.eth. ### Patch Changes - [#804](#804) [`d514d111`](d514d11) Thanks [@roninjin10](https://github.com/roninjin10)! - Update tevm package to export all of tevm. Now users only need to `npm install tevm` to use all of tevm - Updated dependencies \[[`87427f30`](87427f3), [`8b3218b1`](8b3218b), [`cae17b7d`](cae17b7), [`39a5b5e5`](39a5b5e), [`3b5f6729`](3b5f672), [`0ee22d0a`](0ee22d0), [`0ee22d0a`](0ee22d0), [`d514d111`](d514d11), [`941a630a`](941a630), [`98d76506`](98d7650)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Minor Changes - [#820](#820) [`cae17b7d`](cae17b7) Thanks [@roninjin10](https://github.com/roninjin10)! - Added all eth_\* debug_\_ and anvil\_\_ JSON-rpc methods and handlers to API. - [#822](#822) [`39a5b5e5`](39a5b5e) Thanks [@roninjin10](https://github.com/roninjin10)! - Added eth methods such as chainId getCode and getStorageAt to Tevm.eth. ### Patch Changes - [#811](#811) [`87427f30`](87427f3) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug with EVM errors requiring importing ethereumjs enum to typematch - [#800](#800) [`0ee22d0a`](0ee22d0) Thanks [@roninjin10](https://github.com/roninjin10)! - Renamed TevmClient type to Tevm - [#800](#800) [`0ee22d0a`](0ee22d0) Thanks [@roninjin10](https://github.com/roninjin10)! - Added JSDOC to @tevm/api - [#808](#808) [`941a630a`](941a630) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug with 'to' and 'error' properties not quite working correctly for tevm. To was listed as require instead of only existing when no errors. ## @tevm/[email protected] ### Minor Changes - [#805](#805) [`8b3218b1`](8b3218b) Thanks [@0xNonCents](https://github.com/0xNonCents)! - Enable State Load and Dump actions - [#822](#822) [`39a5b5e5`](39a5b5e) Thanks [@roninjin10](https://github.com/roninjin10)! - Added eth methods such as chainId getCode and getStorageAt to Tevm.eth. - [#823](#823) [`f7865314`](f786531) Thanks [@roninjin10](https://github.com/roninjin10)! - Added support for debug_traceCall handler ### Patch Changes - [#804](#804) [`d514d111`](d514d11) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug with tevm account not updating code hash when deployedBytecode is put into state - Updated dependencies \[[`3b4a347d`](3b4a347), [`39a5b5e5`](39a5b5e), [`d514d111`](d514d11), [`d514d111`](d514d11), [`aec294ba`](aec294b)]: - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Minor Changes - [#805](#805) [`8b3218b1`](8b3218b) Thanks [@0xNonCents](https://github.com/0xNonCents)! - Enable State Load and Dump actions ## @tevm/[email protected] ### Minor Changes - [#805](#805) [`8b3218b1`](8b3218b) Thanks [@0xNonCents](https://github.com/0xNonCents)! - Enable State Load and Dump actions - [#822](#822) [`39a5b5e5`](39a5b5e) Thanks [@roninjin10](https://github.com/roninjin10)! - Added eth methods such as chainId getCode and getStorageAt to Tevm.eth. - [#818](#818) [`98d76506`](98d7650) Thanks [@roninjin10](https://github.com/roninjin10)! - Added blockchain to the Tevm VM so anvil, hardhat, and eth_json_rpc requests can be handled ### Patch Changes - Updated dependencies \[[`87427f30`](87427f3), [`d514d111`](d514d11), [`39a5b5e5`](39a5b5e), [`8b3218b1`](8b3218b), [`d514d111`](d514d11), [`cae17b7d`](cae17b7), [`39a5b5e5`](39a5b5e), [`3b5f6729`](3b5f672), [`0ee22d0a`](0ee22d0), [`0ee22d0a`](0ee22d0), [`941a630a`](941a630), [`f7865314`](f786531)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`3b5f6729`](3b5f672)]: - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - [#822](#822) [`39a5b5e5`](39a5b5e) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug with swallowing errors that didn't return text - [#804](#804) [`d514d111`](d514d11) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug with checking method falsely ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`8b3218b1`](8b3218b), [`39a5b5e5`](39a5b5e), [`3b5f6729`](3b5f672), [`d514d111`](d514d11), [`98d76506`](98d7650)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`3b5f6729`](3b5f672)]: - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - [#809](#809) [`0efe3b03`](0efe3b0) Thanks [@roninjin10](https://github.com/roninjin10)! - Added jsdoc to createHttpHandler - Updated dependencies \[[`3b4a347d`](3b4a347), [`d514d111`](d514d11), [`aec294ba`](aec294b)]: - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - [#807](#807) [`3b4a347d`](3b4a347) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug with zod validator swallowing missing `to` parameter errors - [#804](#804) [`d514d111`](d514d11) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug with JsonRpcRequest throwing for requests with no params - [#806](#806) [`aec294ba`](aec294b) Thanks [@roninjin10](https://github.com/roninjin10)! - Fixed bug in zod validators for contract params which falsely listed `to` as optional - Updated dependencies \[[`87427f30`](87427f3), [`cae17b7d`](cae17b7), [`39a5b5e5`](39a5b5e), [`0ee22d0a`](0ee22d0), [`0ee22d0a`](0ee22d0), [`941a630a`](941a630)]: - @tevm/[email protected] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
"@tevm/contract": major
TevmContract
toContract
createTevmContract
tocreateContract
Script
to be a Contract with bytecodeContract
withAddress
method for adding an address to a contractwithAddress
Before we had to spred contracts like this:
Now Tevm can create a contract with an address attatched
Summary by CodeRabbit
New Features
Script
as a new contract type with bytecode.withAddress
method to associate an address with a contract.Enhancements
Documentation
Refactor
TevmContract
toContract
across the platform for clarity.Bug Fixes
undefined
.Chores
vitest.config.ts
coverage configuration.Tests