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

add txServiceUrl in safe config #253

Merged
merged 1 commit into from
Nov 13, 2024
Merged

Conversation

RnkSngh
Copy link
Collaborator

@RnkSngh RnkSngh commented Nov 8, 2024

PR to add support for directly integrating wiht tx service urls that aren't the default operated by safe.

this is required for adding multisig to bob & mode

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced an optional txServiceUrl property in multisig configuration schemas for enhanced flexibility.
  • Improvements

    • Streamlined function signatures for proposeTransaction and executeMultisigTx, consolidating multisig configuration into a single object.
    • Updated transaction execution process to handle multisig account information more efficiently.
    • Enhanced account object structure by including the transaction service URL.
  • Bug Fixes

    • Maintained consistent error handling in the transaction sending process, ensuring robust performance.

Copy link

coderabbitai bot commented Nov 8, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request encompass updates to several files, primarily focusing on the package.json version increment from 4.0.9 to 4.0.10. Additionally, the src/evm/schemas/multisig.ts file has been modified to include an optional txServiceUrl property in relevant schemas. The src/multisig/safe.ts file has undergone significant alterations to function signatures, consolidating parameters into a single InitializedMultisig object. Related updates were made in src/scripts/execute-multisig-tx.ts and src/tx.ts, refining how multisig accounts are handled in transaction proposals.

Changes

File Change Summary
package.json Version updated from 4.0.9 to 4.0.10.
src/evm/schemas/multisig.ts Added optional property txServiceUrl to uninitializedMultisigConfig, initializedMultisigConfig, and initializedMultisig schemas.
src/multisig/safe.ts Updated function signatures for proposeTransaction and executeMultisigTx to accept InitializedMultisig object. Imported MetaTransactionData and InitializedMultisig.
src/scripts/execute-multisig-tx.ts Removed private key retrieval; updated parameters for executeMultisigTx to use multisigAccount object.
src/tx.ts Updated sendTx function to modify parameters for proposeTransaction call, using account object instead of separate parameters.
src/utils/io.ts Updated saveMultisigAddressToAccountsSpec to include txServiceUrl in the returned account object.

Possibly related PRs

Suggested reviewers

  • dshiell

🐰 "In the garden where the code does bloom,
A version hops from nine to ten,
With multisig's new URL,
Our functions dance, and all is well!
Hooray for changes, let's all cheer,
For every hop brings progress near!" 🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/evm/schemas/multisig.ts

(node:10249) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///eslint.config.js?mtime=1731520853630 is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /package.json.
(Use node --trace-warnings ... to show where the warning was created)

Oops! Something went wrong! :(

ESLint: 8.57.1

TypeError: Key "rules": Key "@typescript-eslint/quotes": Could not find "quotes" in plugin "@typescript-eslint". Did you mean "@/quotes"?
at throwRuleNotFoundError (/node_modules/eslint/lib/config/rule-validator.js:66:11)
at RuleValidator.validate (/node_modules/eslint/lib/config/rule-validator.js:128:17)
at [finalizeConfig] (/node_modules/eslint/lib/config/flat-config-array.js:337:23)
at FlatConfigArray.getConfig (/node_modules/@humanwhocodes/config-array/api.js:1036:55)
at /node_modules/eslint/lib/eslint/flat-eslint.js:812:40
at Array.map ()
at FlatESLint.lintFiles (/node_modules/eslint/lib/eslint/flat-eslint.js:810:23)
at async Object.execute (/node_modules/eslint/lib/cli.js:421:23)
at async main (/node_modules/eslint/bin/eslint.js:152:22)


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (9)
src/scripts/execute-multisig-tx.ts (1)

24-27: Consider adding logging for better operational visibility.

Since this is a CLI script handling critical multisig operations, it would be helpful to add logging statements that indicate:

  • The transaction being executed (txIndex)
  • The multisig account being used
  • The RPC endpoint being used

Example addition:

+ console.log(`Executing transaction ${txIndex} for multisig ${multisigAccount.address} via RPC ${rpcUrl}`);
  executeMultisigTx(
    multisigAccount,
    rpcUrl,
    txIndex
  );
src/evm/schemas/multisig.ts (2)

21-21: Consider adding URL validation and documentation.

While the txServiceUrl addition is well-typed, consider enhancing it with:

  1. URL format validation using Zod's string validation
  2. JSDoc comments describing the expected URL format and usage
-    txServiceUrl: z.string().optional(),
+    /** Safe transaction service URL (e.g., https://safe-transaction-mainnet.safe.global)
+     * @see https://docs.safe.global/safe-core-api/available-services
+     */
+    txServiceUrl: z.string().url().optional(),

41-41: Maintain consistent validation with config schema.

The txServiceUrl validation should match the config schema for consistency.

-  txServiceUrl: z.string().optional(),
+  /** Safe transaction service URL (e.g., https://safe-transaction-mainnet.safe.global)
+   * @see https://docs.safe.global/safe-core-api/available-services
+   */
+  txServiceUrl: z.string().url().optional(),
src/multisig/safe.ts (4)

60-60: Fix console.log output.

The log statement will print [object Object] for txProposer. Consider logging relevant properties instead.

- `proposing transaction from ${txProposer} @safe ${initializedMultisig.safeAddress}
+ `proposing transaction from safe ${initializedMultisig.safeAddress}

99-103: Remove redundant return type annotation.

The Promise return type annotation is redundant as TypeScript can infer it from the async function.

- ):Promise<TransactionResult> => {
+ ) => {

104-105: Consider adding error handling for API initialization.

The code assumes the Safe API kit initialization will always succeed. Consider adding error handling to provide better feedback when the service is unavailable.

+ try {
    const apiKit = new SafeApiKit({
      chainId: BigInt(initializedMultisig.chainId),
      txServiceUrl: initializedMultisig.txServiceUrl,
    });
+  } catch (error) {
+    throw new Error(`Failed to initialize Safe API kit: ${error.message}`);
+  }

Also applies to: 110-111, 114-114


42-50: Add JSDoc documentation for txServiceUrl.

Since this PR introduces support for custom transaction service URLs, consider adding documentation explaining the purpose and expected format of txServiceUrl.

/**
 *
- * @param data Propose a transaction from a signer account
+ * @param initializedMultisig Configuration object containing Safe details
+ * @param initializedMultisig.txServiceUrl Optional URL for the transaction service. 
+ *        If not provided, defaults to Safe's transaction service.
 * @param toAddress Destination address for the transaction
 * @param txData Transaction data
 */
src/tx.ts (2)

79-84: Consider adding URL validation for txServiceUrl.

Since we're now supporting custom transaction service URLs through the account object, it would be good to validate the URL format before attempting to use it.

      proposeTransaction(
        account,
        deployedContractAddress,
        callData,
        chain.rpc,
        updatedNonces[account.safeAddress]
+     ).catch(error => {
+       if (error.message.includes('txServiceUrl')) {
+         throw new Error(`Invalid transaction service URL in account config: ${error.message}`);
+       }
+       throw error;
+     });

Line range hint 78-85: Add documentation for txServiceUrl configuration.

Since this change introduces support for custom transaction service URLs, it would be helpful to add code comments explaining:

  • The purpose of custom txServiceUrl
  • When and why it might be needed
  • Example configuration
+     // Propose the transaction using the Safe transaction service.
+     // If a custom txServiceUrl is configured in the account, it will be used instead of
+     // the default Safe transaction service. This is useful when working with custom
+     // deployments of the Safe infrastructure.
      proposeTransaction(
        account,
        deployedContractAddress,
        callData,
        chain.rpc,
        updatedNonces[account.safeAddress]
      );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4970243 and 2e4b040.

📒 Files selected for processing (5)
  • package.json (1 hunks)
  • src/evm/schemas/multisig.ts (2 hunks)
  • src/multisig/safe.ts (4 hunks)
  • src/scripts/execute-multisig-tx.ts (1 hunks)
  • src/tx.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (5)
src/scripts/execute-multisig-tx.ts (1)

24-27: LGTM! Parameter consolidation improves safety and extensibility.

The change to pass the entire multisigAccount object instead of individual parameters is a good improvement. It:

  • Encapsulates all multisig-related configuration
  • Enables the addition of custom txServiceUrl support
  • Reduces the risk of parameter mishandling
src/multisig/safe.ts (2)

4-4: LGTM! Import changes are well-structured.

The new imports for MetaTransactionData and InitializedMultisig are properly organized and align with the refactoring changes.

Also applies to: 10-10


42-42: Verify txServiceUrl availability before usage.

The function should validate that txServiceUrl is available before using it, as it's an optional property in the schema.

Also applies to: 50-50, 51-51

src/tx.ts (2)

79-84: LGTM! Good refactoring to improve encapsulation.

The change to pass the complete account object instead of individual parameters is a good improvement. This approach allows for better extensibility (like adding txServiceUrl) while maintaining type safety through isInitializedMultisig.


79-84: Verify consistent usage of new account object pattern.

Let's verify that all other files calling proposeTransaction have been updated to use the new pattern of passing the complete account object.

✅ Verification successful

Let me gather more context about these usages to verify the pattern.


Let me check the account object pattern by looking at the type definition and its usage.


Let me try a different approach to understand the account object structure.


Let me check one final thing to understand the relationship between the implementation and usage.


Based on the gathered information, I can now provide the final response:

The account object pattern is consistently implemented across the codebase

The verification shows that:

  • The proposeTransaction function in src/multisig/safe.ts is the main implementation that accepts InitializedMultisig type
  • The calling code in src/tx.ts correctly passes the account object with the expected properties (as seen in account.safeAddress usage)
  • There are no other direct calls to proposeTransaction in the codebase that would need updating
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all calls to proposeTransaction to ensure they use the new pattern
rg "proposeTransaction\(" --type ts

Length of output: 193


Script:

#!/bin/bash
# Get more context around proposeTransaction calls
rg "proposeTransaction\(" --type ts -B 5 -A 5

Length of output: 1535


Script:

#!/bin/bash
# Look for InitializedMultisig type definition and usage
ast-grep --pattern 'type InitializedMultisig = {
  $$$
}'

# Also get the context of the account parameter usage
rg "account: InitializedMultisig" --type ts -B 2 -A 2

Length of output: 115


Script:

#!/bin/bash
# Look for the account type/interface definition
rg "interface.*Multisig" --type ts -B 2 -A 5

# Also check the actual usage in tx.ts
rg "account\." --type ts -B 2 -A 2 src/tx.ts

Length of output: 503


Script:

#!/bin/bash
# Look at the full implementation of proposeTransaction in safe.ts
rg "export.*proposeTransaction" --type ts -B 10 -A 30 src/multisig/safe.ts

# And check for any type definitions related to the account
rg "type.*safe" --type ts -i

Length of output: 1185

src/evm/schemas/multisig.ts Show resolved Hide resolved
src/multisig/safe.ts Show resolved Hide resolved
Copy link
Collaborator

@dshiell dshiell left a comment

Choose a reason for hiding this comment

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

are txServiceUrls "trustworthy"?

@RnkSngh
Copy link
Collaborator Author

RnkSngh commented Nov 8, 2024

are txServiceUrls "trustworthy"?

I think they are, because they tend to be operated by chains themselves (e.g. the urls are superchain or gobob.xyz)

But also, we don't need a lot of trust assumptions here.

We only use this api service to sign and persist transactions which we can assume are public. So since there aren't any concerns with leaking the info we send them (in fact, the last step is broadcasting the signed tx publicly), the only way they could grief us is through losing our txs. But that seems unlikely

@RnkSngh RnkSngh force-pushed the raunak/hosted-signer-support branch from 2e4b040 to 0ca3824 Compare November 13, 2024 17:56
@RnkSngh RnkSngh merged commit 8e57e56 into main Nov 13, 2024
3 checks passed
@RnkSngh RnkSngh deleted the raunak/hosted-signer-support branch November 13, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants