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

chore: fixed issues #783

Merged
merged 1 commit into from
Dec 2, 2024
Merged

chore: fixed issues #783

merged 1 commit into from
Dec 2, 2024

Conversation

fonstack
Copy link
Member

@fonstack fonstack commented Dec 2, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced payout transaction processing by integrating provider-based execution, improving robustness and error handling.
    • Introduced the useProvider hook to streamline provider URL retrieval for transaction execution.
  • Bug Fixes

    • Improved error handling for unsupported vault versions and missing parameters during payout transactions.
  • Documentation

    • Updated console log statements for better clarity during transaction execution.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

This pull request updates the @hats.finance/shared package by incrementing its version number from 1.1.122 to 1.1.124. It also modifies the getExecutePayoutSafeTransaction function in payouts.utils.ts to change its parameter from signer to providerUrl, affecting how transactions are executed. Additionally, the useProvider hook from the wagmi library is integrated into several components, including ExecutePayout.ts, useCreatePayoutProposal.ts, and useSignPayout.ts, streamlining the transaction process by utilizing the provider URL instead of the signer.

Changes

File Path Change Summary
packages/shared/package.json Version updated from 1.1.122 to 1.1.124.
packages/shared/src/utils/payouts.utils.ts Updated getExecutePayoutSafeTransaction function to change the parameter from signer: Signer to providerUrl: string. Enhanced error handling and refined payout logic for single and split payouts.
packages/web/src/contracts/write/ExecutePayout.ts Added useProvider hook from wagmi. Updated logic to derive providerUrl from the provider object instead of using signer. Enhanced error handling related to providerUrl.
packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useCreatePayoutProposal.ts Integrated useProvider hook from wagmi to obtain the provider instance. Updated create function to use providerUrl instead of signer. Maintained existing error handling.
packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useSignPayout.ts Added useProvider hook from wagmi. Changed logic in signTypedData to use providerUrl instead of signer. Enhanced error handling to check for the existence of providerUrl.

Possibly related PRs

  • feat: now user can create safe proposal for payout #764: The changes in this PR involve modifications to the useCreatePayoutProposal hook, which now uses providerUrl instead of signer, directly connecting to the changes made in the main PR regarding the getExecutePayoutSafeTransaction function's parameter update.
  • chore: safe sdk migration #781: This PR also updates the getExecutePayoutSafeTransaction function to use signer instead of provider, aligning with the changes in the main PR that reflect a shift in how the Safe transaction is constructed and executed.

Suggested reviewers

  • shayzluf

🐰 In the garden, a change we see,
From signer to provider, oh so free!
With payouts now clearer, and logic refined,
A hop and a skip, new paths we find.
Let’s celebrate this leap, with joy and cheer,
For smoother transactions, the future is near! 🌼✨


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

Deploying dapp with  Cloudflare Pages  Cloudflare Pages

Latest commit: cc16106
Status: ✅  Deploy successful!
Preview URL: https://fcf31068.dapp-a9y.pages.dev
Branch Preview URL: https://fix-fix-safe-sdk-migration.dapp-a9y.pages.dev

View logs

Copy link
Contributor

@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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8760bb0 and cc16106.

📒 Files selected for processing (5)
  • packages/shared/package.json (1 hunks)
  • packages/shared/src/utils/payouts.utils.ts (1 hunks)
  • packages/web/src/contracts/write/ExecutePayout.ts (3 hunks)
  • packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useCreatePayoutProposal.ts (2 hunks)
  • packages/web/src/pages/CommitteeTools/PayoutsTool/PayoutStatusPage/useSignPayout.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/shared/package.json
🔇 Additional comments (1)
packages/web/src/contracts/write/ExecutePayout.ts (1)

53-57: ⚠️ Potential issue

Consistent issue with providerUrl and Provider usage

Retrieving providerUrl from provider.chains will not work because provider lacks a chains property. Passing providerUrl as a string instead of a Provider instance will cause runtime errors.

Adjust the code to create a Provider instance correctly:

import { useNetwork, useProvider, useSigner } from "wagmi";

...

const send = async () => {
  if (!vault || !payout || !contractAddress || !signer) return;
  setError(undefined);
  setIsLoading(true);

  try {
    await switchNetworkAndValidate(chain!.id, vault.chainId as number);

-   const providerUrl = provider.chains?.find((c) => c.id === chain?.id)?.rpcUrls.default.http[0];
+   const providerUrl = ChainsConfig[vault.chainId]?.rpcUrl;
    if (!providerUrl) return;

+   const txProvider = new ethers.providers.JsonRpcProvider(providerUrl);

    const { tx: safeTransaction, txHash: safeTransactionHash } = await getExecutePayoutSafeTransaction(
-     providerUrl,
+     txProvider,
      vault.committee,
      payout
    );

Ensure getExecutePayoutSafeTransaction accepts a Provider instance as per prior suggestions.

Comment on lines +58 to +65
providerUrl: string,
committee: string,
payout: IPayoutResponse
): Promise<{ tx: SafeTransaction; txHash: string }> => {
const vaultInfo = payout.vaultInfo;

const protocolKit = await Safe.init({
provider: (signer.provider as any)?.provider as never,
provider: providerUrl,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect usage of provider in Safe.init

In the getExecutePayoutSafeTransaction function, you are passing providerUrl: string directly as the provider in Safe.init. However, the provider parameter expects a Provider instance, not a URL string. This will lead to runtime errors.

To fix this issue, initialize a Provider using ethers and pass it to Safe.init:

export const getExecutePayoutSafeTransaction = async (
  providerUrl: string,
  committee: string,
  payout: IPayoutResponse
): Promise<{ tx: SafeTransaction; txHash: string }> => {
  const vaultInfo = payout.vaultInfo;

+ const provider = new ethers.providers.JsonRpcProvider(providerUrl);

  const protocolKit = await Safe.init({
-   provider: providerUrl,
+   provider: provider,
    safeAddress: committee,
  });
📝 Committable suggestion

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

Suggested change
providerUrl: string,
committee: string,
payout: IPayoutResponse
): Promise<{ tx: SafeTransaction; txHash: string }> => {
const vaultInfo = payout.vaultInfo;
const protocolKit = await Safe.init({
provider: (signer.provider as any)?.provider as never,
provider: providerUrl,
providerUrl: string,
committee: string,
payout: IPayoutResponse
): Promise<{ tx: SafeTransaction; txHash: string }> => {
const vaultInfo = payout.vaultInfo;
const provider = new ethers.providers.JsonRpcProvider(providerUrl);
const protocolKit = await Safe.init({
provider: provider,

🛠️ Refactor suggestion

Refactor function to accept a Provider instance

For better flexibility and to adhere to best practices, consider modifying getExecutePayoutSafeTransaction to accept a Provider instance instead of a URL string. This allows callers to manage provider creation and reuse existing provider instances.

Update the function signature and usage:

- export const getExecutePayoutSafeTransaction = async (
-   providerUrl: string,
+ export const getExecutePayoutSafeTransaction = async (
+   provider: Provider,
    committee: string,
    payout: IPayoutResponse
  ): Promise<{ tx: SafeTransaction; txHash: string }> => {
    const vaultInfo = payout.vaultInfo;

    const protocolKit = await Safe.init({
-     provider: providerUrl,
+     provider: provider,
      safeAddress: committee,
    });

Ensure all calls to this function pass a Provider instance.

📝 Committable suggestion

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

Suggested change
providerUrl: string,
committee: string,
payout: IPayoutResponse
): Promise<{ tx: SafeTransaction; txHash: string }> => {
const vaultInfo = payout.vaultInfo;
const protocolKit = await Safe.init({
provider: (signer.provider as any)?.provider as never,
provider: providerUrl,
provider: Provider,
committee: string,
payout: IPayoutResponse
): Promise<{ tx: SafeTransaction; txHash: string }> => {
const vaultInfo = payout.vaultInfo;
const protocolKit = await Safe.init({
provider: provider,

Comment on lines +28 to +31
const providerUrl = provider.chains?.find((c) => c.id === vault.chainId)?.rpcUrls.default.http[0];
if (!providerUrl) return;

const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(providerUrl, vault.committee, payout);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential issue retrieving providerUrl

The providerUrl is obtained using provider.chains?.find((c) => c.id === vault.chainId)?.rpcUrls.default.http[0];. However, the Provider object from useProvider() does not have a chains property. This will result in providerUrl being undefined.

To resolve this, use the chains information from the useNetwork() hook or from your application's configuration:

import { useNetwork, useProvider, useSignTypedData, useSigner } from "wagmi";

...

const signTypedData = async () => {
  if (!vault || !payout || !signer) return;
  setIsLoading(true);

  try {
    await switchNetworkAndValidate(chain!.id, vault.chainId as number);

+   const providerUrl = ChainsConfig[vault.chainId]?.rpcUrl;
    if (!providerUrl) return;

+   const txProvider = new ethers.providers.JsonRpcProvider(providerUrl);

-   const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(providerUrl, vault.committee, payout);
+   const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(txProvider, vault.committee, payout);

Also, ensure getExecutePayoutSafeTransaction accepts a Provider instance as per the refactored function.

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

Comment on lines +42 to +45
const providerUrl = provider.chains?.find((c) => c.id === vault.chainId)?.rpcUrls.default.http[0];
if (!providerUrl) return;

const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(providerUrl, multisigAddress, payout);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect retrieval of providerUrl and usage

The providerUrl is being retrieved from provider.chains, but provider does not have a chains property. Additionally, passing providerUrl as a string to functions expecting a Provider instance will cause errors.

Refactor the code to obtain providerUrl correctly and create a Provider instance:

import { useAccount, useProvider, useSigner } from "wagmi";

...

const create = async () => {
  if (!vault || !payout || !account || !signer) return false;
  setIsLoading(true);

  try {
    ...

-   const providerUrl = provider.chains?.find((c) => c.id === vault.chainId)?.rpcUrls.default.http[0];
+   const providerUrl = ChainsConfig[vault.chainId]?.rpcUrl;
    if (!providerUrl) return;

+   const txProvider = new ethers.providers.JsonRpcProvider(providerUrl);

-   const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(providerUrl, multisigAddress, payout);
+   const { tx: safeTransaction } = await getExecutePayoutSafeTransaction(txProvider, multisigAddress, payout);

Ensure getExecutePayoutSafeTransaction accepts a Provider instance.

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

@shayzluf shayzluf merged commit ea42172 into develop Dec 2, 2024
4 checks passed
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