-
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
add contract setup script #144
Conversation
WalkthroughThe recent changes enhance smart contract management by transitioning from "upgrade" to "update," refining deployment and transaction handling processes. New schemas for contract updates are introduced, streamlining script functionalities and improving organization. This update broadens the capabilities for managing contract versions while enhancing user experience with clearer code structure and better-defined processes. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Script
participant ContractRegistry
participant Logger
User->>Script: Execute contract update command
Script->>ContractRegistry: Fetch existing contracts
Script->>Logger: Log the update process
Script->>ContractRegistry: Update contracts
Logger-->>User: Display update status
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 Configuration 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.
Actionable comments posted: 26
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (13)
- package.json (1 hunks)
- specs/update.spec.yaml (1 hunks)
- specs/upgrade.spec.yaml (1 hunks)
- src/deploy.ts (6 hunks)
- src/evm/account.ts (1 hunks)
- src/evm/schemas/contract.ts (2 hunks)
- src/evm/schemas/contractUpdate.ts (1 hunks)
- src/evm/schemas/tx.ts (1 hunks)
- src/scripts/update-contracts-script.ts (1 hunks)
- src/tx.ts (3 hunks)
- src/updateContract.ts (1 hunks)
- src/utils/constants.ts (1 hunks)
- tsup.config.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- package.json
Additional context used
yamllint
specs/upgrade.spec.yaml
[error] 28-28: trailing spaces
(trailing-spaces)
[error] 30-30: trailing spaces
(trailing-spaces)
[error] 32-32: trailing spaces
(trailing-spaces)
[error] 34-34: trailing spaces
(trailing-spaces)
[error] 35-35: no new line character at the end of file
(new-line-at-end-of-file)
specs/update.spec.yaml
[error] 1-1: trailing spaces
(trailing-spaces)
[error] 11-11: trailing spaces
(trailing-spaces)
[error] 14-14: trailing spaces
(trailing-spaces)
[error] 29-29: trailing spaces
(trailing-spaces)
[error] 33-33: trailing spaces
(trailing-spaces)
[error] 34-34: trailing spaces
(trailing-spaces)
[error] 115-115: trailing spaces
(trailing-spaces)
[error] 116-116: trailing spaces
(trailing-spaces)
[error] 117-117: trailing spaces
(trailing-spaces)
[error] 118-118: trailing spaces
(trailing-spaces)
[error] 119-119: trailing spaces
(trailing-spaces)
[error] 120-120: trailing spaces
(trailing-spaces)
[error] 121-121: trailing spaces
(trailing-spaces)
[error] 122-122: trailing spaces
(trailing-spaces)
[error] 125-125: trailing spaces
(trailing-spaces)
[error] 126-126: trailing spaces
(trailing-spaces)
[error] 127-127: trailing spaces
(trailing-spaces)
[error] 128-128: trailing spaces
(trailing-spaces)
[error] 129-129: trailing spaces
(trailing-spaces)
[error] 130-130: trailing spaces
(trailing-spaces)
[error] 131-131: trailing spaces
(trailing-spaces)
[error] 134-134: trailing spaces
(trailing-spaces)
[error] 136-136: trailing spaces
(trailing-spaces)
[error] 138-138: trailing spaces
(trailing-spaces)
[error] 140-140: trailing spaces
(trailing-spaces)
[error] 145-145: trailing spaces
(trailing-spaces)
[error] 147-147: trailing spaces
(trailing-spaces)
[error] 149-149: trailing spaces
(trailing-spaces)
[error] 155-155: trailing spaces
(trailing-spaces)
[error] 157-157: trailing spaces
(trailing-spaces)
[error] 159-159: trailing spaces
(trailing-spaces)
[error] 161-161: no new line character at the end of file
(new-line-at-end-of-file)
Biome
src/tx.ts
[error] 30-30: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Additional comments not posted (18)
tsup.config.ts (1)
17-17
: Update script reference verified.The reference to
"src/scripts/update-contracts-script.ts"
replaces"src/scripts/upgrade-script.ts"
, aligning with the new script's purpose. Ensure the new script exists and functions as intended.src/scripts/update-contracts-script.ts (4)
1-1
: Ensure the script is executable.The shebang line
#!/usr/bin/env node
makes the script executable in a Unix-like environment. Ensure the script has the correct permissions.
10-26
: Ensure correct argument parsing and contract updating.The
main
function parses CLI arguments, loads contract update specifications, and invokesupdateContractForChain
. Ensure the logic is correct and handles errors appropriately.
2-4
: Verify import paths and functionality.The imports from relative paths should be verified to ensure they exist and function as expected.
Verification successful
Import paths and functionality verified successfully.
The imported modules
ContractRegistryLoader
,parseObjFromFile
,loadContractUpdateRegistry
, andupdateContractForChain
exist and are defined correctly in the codebase.
ContractRegistryLoader
: Defined insrc/evm/schemas/contract.ts
parseObjFromFile
: Defined insrc/utils/io.ts
loadContractUpdateRegistry
: Defined insrc/evm/schemas/contractUpdate.ts
updateContractForChain
: Defined insrc/updateContract.ts
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence of imported modules. # Test: Check if the imported modules exist. Expect: All modules should be found. fd 'ContractRegistryLoader' src --exec echo "Found: {}" fd 'parseObjFromFile' src --exec echo "Found: {}" fd 'loadContractUpdateRegistry' src --exec echo "Found: {}" fd 'updateContractForChain' src --exec echo "Found: {}"Length of output: 221
Script:
#!/bin/bash # Description: Verify the existence of imported modules using ripgrep. # Test: Check if the imported modules exist. Expect: All modules should be found. rg 'ContractRegistryLoader' -t js -A 3 rg 'parseObjFromFile' -t js -A 3 rg 'loadContractUpdateRegistry' -t js -A 3 rg 'updateContractForChain' -t js -A 3Length of output: 749
Script:
#!/bin/bash # Description: Verify the existence of imported modules using ripgrep and ast-grep. # Test: Check if the imported modules exist. Expect: All modules should be found. rg 'ContractRegistryLoader' -A 3 rg 'parseObjFromFile' -A 3 rg 'loadContractUpdateRegistry' -A 3 rg 'updateContractForChain' -A 3 # Using ast-grep to search for the definitions ast-grep --lang typescript --pattern 'class ContractRegistryLoader { $$$ }' ast-grep --lang typescript --pattern 'function parseObjFromFile($_) { $$$ }' ast-grep --lang typescript --pattern 'function loadContractUpdateRegistry($_) { $$$ }' ast-grep --lang typescript --pattern 'function updateContractForChain($_) { $$$ }'Length of output: 13415
6-8
: Verify utility imports.The utility imports from relative paths should be verified to ensure they exist and function as expected.
Verification successful
Utility imports verified.
The imported utility modules have been verified and exist in the codebase:
getOutputLogger
is defined insrc/utils/cli.ts
.UPDATE_SPECS_PATH
is defined insrc/utils/constants.ts
.parseArgsFromCLI
is defined insrc/utils/io.ts
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence of imported utility modules. # Test: Check if the utility modules exist. Expect: All modules should be found. fd 'getOutputLogger' src --exec echo "Found: {}" fd 'UPDATE_SPECS_PATH' src --exec echo "Found: {}" fd 'parseArgsFromCLI' src --exec echo "Found: {}"Length of output: 149
Script:
#!/bin/bash # Description: Verify the existence of imported utility modules using ast-grep. # Test: Check if the utility function getOutputLogger exists. Expect: The function should be found. ast-grep --lang typescript --pattern 'function getOutputLogger($_) { $$$ }' # Test: Check if the constant UPDATE_SPECS_PATH exists. Expect: The constant should be found. ast-grep --lang typescript --pattern 'const UPDATE_SPECS_PATH = $_' # Test: Check if the function parseArgsFromCLI exists. Expect: The function should be found. ast-grep --lang typescript --pattern 'function parseArgsFromCLI($_) { $$$ }'Length of output: 459
Script:
#!/bin/bash # Description: Verify the existence of imported utility modules using rg. # Test: Check if the utility function getOutputLogger exists. Expect: The function should be found. rg 'function getOutputLogger' -A 5 # Test: Check if the function parseArgsFromCLI exists. Expect: The function should be found. rg 'function parseArgsFromCLI' -A 5Length of output: 828
src/evm/schemas/tx.ts (3)
5-6
: ExportTxItemSchema
for reusability.The export of
TxItemSchema
enhances modularity and reusability across the application.
22-22
: Enforce strict validation with.strict()
.Adding
.strict()
to the schema ensures only specified fields are allowed, improving data integrity.
24-24
: ExportTxItem
for type safety.The export of
TxItem
promotes type safety and consistency when working with transaction items.src/evm/schemas/contractUpdate.ts (2)
1-13
: LGTM!The
UpdateContractConfigSchema
correctly combinesTxItemSchema
andContractItemSchema
usingz.union
. TheUpdateContractRegistry
class extendsRegistry
with the appropriate type.
14-29
: LGTM!The function
loadContractUpdateRegistry
correctly parses the config file and handles errors usingsafeParse
. It returns anUpdateContractRegistry
instance with the parsed data.src/utils/constants.ts (1)
49-52
: LGTM!The new constant
UPDATE_SPECS_PATH
is correctly defined and follows the existing pattern for constants.src/evm/schemas/contract.ts (3)
6-6
: LGTM! ExportingContractItemSchema
improves reusability.The change enhances the schema's accessibility across different modules.
15-16
: LGTM! Stricter validation for libraries improves data integrity.The schema now ensures that each library has a non-empty
name
andaddress
.
25-26
: LGTM! Stricter validation for initialization data improves data integrity.The schema now ensures that the
signature
andargs
fields are non-empty strings.src/updateContract.ts (1)
15-25
: LGTM! TheupdateContractForChain
function is comprehensive and well-structured.The function handles contract updates, including deployment and transaction sending, with logging and error handling.
src/tx.ts (1)
15-23
: LGTM! ThesendTx
function encapsulates transaction logic effectively.The function handles ABI retrieval, transaction sending, and error management.
src/evm/account.ts (1)
105-117
: LGTM! But verify the function usage in the codebase.The function
connectProviderAccounts
correctly connects all accounts in theAccountRegistry
to the specified Ethereum provider. The logic and syntax appear correct.However, ensure that all function calls to
connectProviderAccounts
are correctly implemented across the codebase.Verification successful
The function usage is correctly implemented.
The function
connectProviderAccounts
is used appropriately across the codebase in the following files:
src/tx.ts
src/updateContract.ts
src/deploy.ts
The function is called with the correct parameters, ensuring that all accounts in the
AccountRegistry
are connected to the specified Ethereum provider.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `connectProviderAccounts` are correctly implemented. # Test: Search for the function usage. Expect: Correct implementation. rg --type typescript -A 5 $'connectProviderAccounts'Length of output: 86
Script:
#!/bin/bash # Description: Verify all function calls to `connectProviderAccounts` are correctly implemented. # Test: Search for the function usage. Expect: Correct implementation. rg --type ts -A 5 $'connectProviderAccounts'Length of output: 2310
src/deploy.ts (1)
Line range hint
156-206
:
LGTM!The function
deployToChain
is well-structured and includes necessary error handling.
fcb8f1d
to
b09dcbc
Compare
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.
Actionable comments posted: 4
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- package.json (1 hunks)
- specs/update.spec.yaml (1 hunks)
- specs/upgrade.spec.yaml (1 hunks)
- src/deploy.ts (6 hunks)
- src/evm/account.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- package.json
Files skipped from review as they are similar to previous changes (1)
- src/evm/account.ts
Additional context used
yamllint
specs/upgrade.spec.yaml
[error] 28-28: trailing spaces
(trailing-spaces)
[error] 30-30: trailing spaces
(trailing-spaces)
[error] 32-32: trailing spaces
(trailing-spaces)
[error] 34-34: trailing spaces
(trailing-spaces)
[error] 35-35: no new line character at the end of file
(new-line-at-end-of-file)
specs/update.spec.yaml
[error] 1-1: trailing spaces
(trailing-spaces)
[error] 11-11: trailing spaces
(trailing-spaces)
[error] 14-14: trailing spaces
(trailing-spaces)
[error] 29-29: trailing spaces
(trailing-spaces)
[error] 33-33: trailing spaces
(trailing-spaces)
[error] 34-34: trailing spaces
(trailing-spaces)
[error] 115-115: trailing spaces
(trailing-spaces)
[error] 116-116: trailing spaces
(trailing-spaces)
[error] 117-117: trailing spaces
(trailing-spaces)
[error] 118-118: trailing spaces
(trailing-spaces)
[error] 119-119: trailing spaces
(trailing-spaces)
[error] 120-120: trailing spaces
(trailing-spaces)
[error] 121-121: trailing spaces
(trailing-spaces)
[error] 122-122: trailing spaces
(trailing-spaces)
[error] 125-125: trailing spaces
(trailing-spaces)
[error] 126-126: trailing spaces
(trailing-spaces)
[error] 127-127: trailing spaces
(trailing-spaces)
[error] 128-128: trailing spaces
(trailing-spaces)
[error] 129-129: trailing spaces
(trailing-spaces)
[error] 130-130: trailing spaces
(trailing-spaces)
[error] 131-131: trailing spaces
(trailing-spaces)
[error] 134-134: trailing spaces
(trailing-spaces)
[error] 136-136: trailing spaces
(trailing-spaces)
[error] 138-138: trailing spaces
(trailing-spaces)
[error] 140-140: trailing spaces
(trailing-spaces)
[error] 145-145: trailing spaces
(trailing-spaces)
[error] 147-147: trailing spaces
(trailing-spaces)
[error] 149-149: trailing spaces
(trailing-spaces)
[error] 155-155: trailing spaces
(trailing-spaces)
[error] 157-157: trailing spaces
(trailing-spaces)
[error] 159-159: trailing spaces
(trailing-spaces)
[error] 161-161: no new line character at the end of file
(new-line-at-end-of-file)
Additional comments not posted (1)
src/deploy.ts (1)
Line range hint
156-204
:
LGTM!The function
deployToChain
is well-structured and effectively leverages the newdeployContract
function.
b09dcbc
to
40bb42a
Compare
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.
Actionable comments posted: 18
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (13)
- package.json (1 hunks)
- specs/update.spec.yaml (1 hunks)
- specs/upgrade.spec.yaml (1 hunks)
- src/deploy.ts (6 hunks)
- src/evm/account.ts (1 hunks)
- src/evm/schemas/contract.ts (2 hunks)
- src/evm/schemas/contractUpdate.ts (1 hunks)
- src/evm/schemas/tx.ts (1 hunks)
- src/scripts/update-contracts-script.ts (1 hunks)
- src/tx.ts (3 hunks)
- src/updateContract.ts (1 hunks)
- src/utils/constants.ts (1 hunks)
- tsup.config.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- package.json
Files skipped from review as they are similar to previous changes (7)
- src/evm/schemas/contract.ts
- src/evm/schemas/contractUpdate.ts
- src/evm/schemas/tx.ts
- src/scripts/update-contracts-script.ts
- src/updateContract.ts
- src/utils/constants.ts
- tsup.config.ts
Additional context used
yamllint
specs/upgrade.spec.yaml
[error] 28-28: trailing spaces
(trailing-spaces)
[error] 30-30: trailing spaces
(trailing-spaces)
[error] 32-32: trailing spaces
(trailing-spaces)
[error] 34-34: trailing spaces
(trailing-spaces)
[error] 35-35: no new line character at the end of file
(new-line-at-end-of-file)
specs/update.spec.yaml
[error] 1-1: trailing spaces
(trailing-spaces)
[error] 11-11: trailing spaces
(trailing-spaces)
[error] 14-14: trailing spaces
(trailing-spaces)
[error] 29-29: trailing spaces
(trailing-spaces)
[error] 33-33: trailing spaces
(trailing-spaces)
[error] 34-34: trailing spaces
(trailing-spaces)
[error] 115-115: trailing spaces
(trailing-spaces)
[error] 116-116: trailing spaces
(trailing-spaces)
[error] 117-117: trailing spaces
(trailing-spaces)
[error] 118-118: trailing spaces
(trailing-spaces)
[error] 119-119: trailing spaces
(trailing-spaces)
[error] 120-120: trailing spaces
(trailing-spaces)
[error] 121-121: trailing spaces
(trailing-spaces)
[error] 122-122: trailing spaces
(trailing-spaces)
[error] 125-125: trailing spaces
(trailing-spaces)
[error] 126-126: trailing spaces
(trailing-spaces)
[error] 127-127: trailing spaces
(trailing-spaces)
[error] 128-128: trailing spaces
(trailing-spaces)
[error] 129-129: trailing spaces
(trailing-spaces)
[error] 130-130: trailing spaces
(trailing-spaces)
[error] 131-131: trailing spaces
(trailing-spaces)
[error] 134-134: trailing spaces
(trailing-spaces)
[error] 136-136: trailing spaces
(trailing-spaces)
[error] 138-138: trailing spaces
(trailing-spaces)
[error] 140-140: trailing spaces
(trailing-spaces)
[error] 145-145: trailing spaces
(trailing-spaces)
[error] 147-147: trailing spaces
(trailing-spaces)
[error] 149-149: trailing spaces
(trailing-spaces)
[error] 155-155: trailing spaces
(trailing-spaces)
[error] 157-157: trailing spaces
(trailing-spaces)
[error] 159-159: trailing spaces
(trailing-spaces)
[error] 161-161: no new line character at the end of file
(new-line-at-end-of-file)
Biome
src/tx.ts
[error] 30-30: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Additional comments not posted (7)
src/tx.ts (5)
2-4
: LGTM! Imports are necessary for new functionality.The new imports for
connectProviderAccounts
,TxItem
, andTxRegistry
are necessary for the new functionality introduced in the file.
15-75
: LGTM! The new functionsendTx
is well-structured and includes necessary error handling.The function encapsulates the logic for sending transactions to existing contracts, including ABI retrieval, transaction sending, and error handling, which improves code robustness.
Tools
Biome
[error] 30-30: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
82-84
: LGTM! The modification to usesendTx
improves code readability.The modification streamlines the transaction processing loop by delegating the logic to
sendTx
, leading to a cleaner separation of concerns.
97-97
: Suggestion: Add error handling for account connection.Consider adding error handling for the
connectProviderAccounts
function to manage potential connection issues.- accountRegistry = connectProviderAccounts(accountRegistry, chain.rpc); + try { + accountRegistry = connectProviderAccounts(accountRegistry, chain.rpc); + } catch (error) { + logger.error(`Failed to connect provider accounts: ${error.message}`); + throw error; + }
114-122
: LGTM! The function now usessendTx
for transaction processing.The change ensures that the new
sendTx
function is used for transaction processing, improving modularity and maintainability.src/evm/account.ts (1)
105-117
: LGTM! The new functionconnectProviderAccounts
is well-structured.The function connects all accounts in an
AccountRegistry
to an Ethereum provider using a provided RPC URL, facilitating blockchain interactions.src/deploy.ts (1)
150-153
: Improve error handling by providing more context.Consider providing more context in the error message to help with debugging.
- logger.error( - `[${chain.chainName}-${chain.deploymentEnvironment}] deploy ${contract.name} failed: ${err}` - ); + logger.error({ + message: `[${chain.chainName}-${chain.deploymentEnvironment}] deploy ${contract.name} failed`, + error: err, + contract, + chain, + });Likely invalid or redundant comment.
PR to allow for deploying & sending txs within a single script. This will help clean up the complexity in our contract deployment CI, by allowing us to have a single script for deploying & upgrading contracts
Summary by CodeRabbit
New Features
Bug Fixes
Enhancements
Chores