warden-protocol / wardenprotocol

Monorepo for the Warden Protocol.
https://wardenprotocol.org
Apache License 2.0
1.09k stars 99 forks source link

Ethereum analyzer #300

Closed Pitasi closed 1 month ago

Pitasi commented 1 month ago

Replace the current SignMethod.Ethereum with an analyzer (CosmWasm contract). The code cleanup in wardend will come in a later PR, for now I'm only adding the contract and fixing SpaceWard to use it.

This initial analyzer version only returns the hash of the unsigned transaction. It's easily extendable to also return some information about the transaction itself.

The address of the contract must be set in the env variables of SpaceWard (we could consider letting users decide which contract they want to use) or sending ethereum transactions will be disabled.

depends on #279

closes #266

Summary by CodeRabbit

coderabbitai[bot] commented 1 month ago
Walkthrough ## Walkthrough The recent changes introduce an analyzers smart contract system, enabling third-party builders to provide metadata to shield's intents during new signature requests. This includes the addition of an initial Ethereum analyzer for processing Ethereum transactions. Various configurations, scripts, and dependencies have been updated or added to support these new features across multiple files and modules. ## Changes | Files/Paths | Change Summary | | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `CHANGELOG.md` | Added features for analyzers smart contract and Ethereum analyzer. | | `Dockerfile` | Added environment variable `VITE_WARDEN_ETHEREUM_ANALYZER_CONTRACT`. | | `contracts/contracts/basic-analyzer/.cargo/config`, `contracts/contracts/ethereum-analyzer/.cargo/config` | Introduced aliases for build and test commands related to Wasm development. | | `contracts/contracts/basic-analyzer/Cargo.toml`, `contracts/contracts/ethereum-analyzer/Cargo.toml` | Updated dependencies and configurations for basic-analyzer and ethereum-analyzer packages. | | `contracts/contracts/basic-analyzer/src/bin/schema.rs`, `contracts/contracts/ethereum-analyzer/src/bin/schema.rs` | Introduced Rust scripts defining `execute` and `query` functions for respective analyzers. | | `contracts/contracts/basic-analyzer/src/contract.rs`, `contracts/contracts/ethereum-analyzer/src/contract.rs` | Introduced functionality for basic and Ethereum analyzer contracts, including instantiation, execution, querying, and analysis functions. | | `contracts/contracts/basic-analyzer/src/error.rs`, `contracts/contracts/ethereum-analyzer/src/error.rs` | Introduced `ContractError` enum for handling errors in respective analyzer contracts. | | `contracts/contracts/basic-analyzer/src/lib.rs`, `contracts/contracts/ethereum-analyzer/src/lib.rs` | Introduced modules for contracts, errors, and messages with public export of `ContractError`. | | `contracts/contracts/ethereum-analyzer/src/ethereum.rs` | Introduced function to parse EIP1559 transactions and test function for validation. | | `proto/warden/warden/v1beta2/tx.proto` | Renamed field `data_for_signing` to `input` and added `analyzers` field in `MsgNewSignatureRequest`. | | `spaceward/entrypoint.sh` | Added replacement of `WARDEN_ETHEREUM_ANALYZER_CONTRACT` variable in the script for `nginx-fe` case. | | `spaceward/pnpm-lock.yaml` | Updated versions and dependencies of `axios` package. | | `spaceward/src/components/SendEth.tsx` | Replaced `useRequestSignature` with `useEthereumTx` for signing Ethereum transactions. | | `spaceward/src/env.ts` | Added new variable `ethereumAnalyzerContract` to the `env` object. | | `spaceward/src/features/metamask/MetaMaskRequests.tsx` | Updated logic for signing transactions and replaced `useRequestSignature` with `useEthereumTx`. | | `spaceward/src/features/walletconnect/WalletConnect.tsx` | Reorganized logic for handling different types of requests and introduced `handleApprove` function and `SignatureRequestDialog` component. | | `spaceward/src/hooks/useClient.ts` | Updated transaction broadcasting logic in `useTx` function with improved error handling. | | `spaceward/src/hooks/useEthereumTx.tsx` | Introduced `useEthereumTx` hook for signing Ethereum transactions using cryptographic keys. | | `spaceward/src/hooks/useRequestSignature.ts` | Refactored imports and updated method calls related to transaction monitoring and signature requests. | | `warden/x/warden/keeper/msg_server_new_signature_request.go` | Added logic for executing analyzers before adding an action and updated function signatures for handling analyzer execution. | ## Sequence Diagram(s) (Beta) ```mermaid sequenceDiagram participant User participant Frontend participant EthereumAnalyzer participant Backend User->>Frontend: Initiates Ethereum transaction Frontend->>EthereumAnalyzer: Sends transaction data EthereumAnalyzer->>Backend: Analyzes transaction Backend->>EthereumAnalyzer: Returns analysis result EthereumAnalyzer->>Frontend: Provides DataForSigning Frontend->>User: Displays signature request User->>Frontend: Approves signature Frontend->>Backend: Submits signed transaction Backend->>Frontend: Confirms transaction Frontend->>User: Displays confirmation ``` ## Assessment against linked issues | Objective (Issue #266) | Addressed | Explanation | | ----------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------- | | Implement Ethereum Metadata Provider | ✅ | | | Provide recipient address (to) for Ethereum txs | ✅ | | | Remove Ethereum-specific code from wardend | ❓ | The PR does not explicitly mention the removal of Ethereum-specific code from wardend. |

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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@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.` 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) - `@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 full the 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 help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
github-actions[bot] commented 1 month ago

Hey @Pitasi and thank you for opening this pull request! 👋🏼

It looks like you forgot to add a changelog entry for your changes. Make sure to add a changelog entry in the 'CHANGELOG.md' file.