Skip to content

[TASK-9940] feat: granular functions#177

Merged
jjramirezn merged 1 commit intomainfrom
develop
Mar 25, 2025
Merged

[TASK-9940] feat: granular functions#177
jjramirezn merged 1 commit intomainfrom
develop

Conversation

@jjramirezn
Copy link
Copy Markdown
Contributor

For getting contract abi and the link details

For getting contract abi and the link details
@jjramirezn jjramirezn requested a review from Hugo0 March 25, 2025 19:19
@notion-workspace
Copy link
Copy Markdown

Improve claim flow speed

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2025

Walkthrough

The changes add two new functions to the module. The first function, getContractAbi, accepts a version string and returns the corresponding contract ABI via a set of case statements. It includes error handling to ensure only supported versions return a valid ABI. The second function, extractLinkDetails, extracts and returns various pieces of metadata from a link, such as token address, claim status, sender address, and deposit details. It evaluates the contract version to determine the claim status and includes error handling for cases when token details are missing. Both functions are added to the exported peanut object, updating the module’s public interface accordingly.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Copy Markdown

@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

🧹 Nitpick comments (3)
src/index.ts (3)

246-283: Duplicated contract ABI selection logic introduces maintenance risk.

The getContractAbi function duplicates the switch statement logic that's already present in the getContract function (lines 295-331). This duplication could lead to maintenance issues if one is updated but the other is not.

Consider extracting the switch statement into a shared helper function that both getContractAbi and getContract can use:

+function getContractAbiForVersion(version: string): any {
+  let contractAbi: any
+  switch (version) {
+    case 'v4':
+      contractAbi = PEANUT_ABI_V4
+      break
+    case 'v4.2':
+      contractAbi = PEANUT_ABI_V4_2
+      break
+    // ... other cases
+    default:
+      throw new Error('Unable to find Peanut contract for this version, check for correct version or updated SDK')
+  }
+  return contractAbi
+}

function getContractAbi(version: string): any {
-  let contractAbi: any
-  switch (version) {
-    case 'v4':
-      contractAbi = PEANUT_ABI_V4
-      break
-    // ... other cases
-    default:
-      throw new Error('Unable to find Peanut contract for this version, check for correct version or updated SDK')
-  }
-  return contractAbi
+  return getContractAbiForVersion(version)
}

// Later in getContract function
-let CONTRACT_ABI: any
-switch (version) {
-  case 'v4':
-    CONTRACT_ABI = PEANUT_ABI_V4
-    break
-  // ... other cases
-}
+const CONTRACT_ABI = getContractAbiForVersion(version)

2053-2055: Function lacks proper type definitions and documentation.

The function uses any type for its parameters and doesn't have JSDoc comments explaining what each parameter represents.

Add appropriate type definitions and documentation:

/**
+ * Extracts details from a link based on deposit information and token details.
+ * 
+ * @param params - The parameters extracted from the link URL
+ * @param deposit - The on-chain deposit data
+ * @param tokenDetails - The details of the token (symbol, name, decimals)
+ * @returns An object containing all extracted link details
+ */
-function extractLinkDetails({ params, deposit, tokenDetails }: any) {
+function extractLinkDetails({ 
+  params, 
+  deposit, 
+  tokenDetails 
+}: {
+  params: {
+    chainId: string;
+    contractVersion: string;
+    depositIdx: number;
+  };
+  deposit: {
+    tokenAddress: string;
+    contractType: number;
+    senderAddress: string;
+    pubKey20?: string;
+    claimed?: boolean;
+    timestamp?: number;
+    amount: ethers.BigNumber;
+    tokenId: ethers.BigNumber;
+    recipient?: string;
+    reclaimableAfter?: number;
+  };
+  tokenDetails: {
+    symbol: string;
+    name: string;
+    decimals: number;
+    tokenURI?: string;
+    metadata?: any;
+  };
+}) {
  // Function implementation

2086-2087: Use const for variables that aren't reassigned.

The variables tokenURI and metadata are never reassigned after their initial declaration as null, so they should use const instead of let.

-  let tokenURI = null
-  let metadata = null
+  const tokenURI = null
+  const metadata = null
🧰 Tools
🪛 ESLint

[error] 2086-2086: 'tokenURI' is never reassigned. Use 'const' instead.

(prefer-const)


[error] 2087-2087: 'metadata' is never reassigned. Use 'const' instead.

(prefer-const)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d7d3b7 and 7039580.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • src/index.ts (4 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/index.ts (1)
src/data.ts (11)
  • PEANUT_ABI_V4 (51-51)
  • PEANUT_ABI_V4_2 (52-52)
  • PEANUT_ABI_V4_3 (53-53)
  • PEANUT_ABI_V4_4 (54-54)
  • PEANUT_BATCHER_ABI_V4 (55-55)
  • PEANUT_BATCHER_ABI_V4_3 (57-57)
  • PEANUT_BATCHER_ABI_V4_4 (58-58)
  • PEANUT_BATCHER_ABI_V4_2 (56-56)
  • PEANUT_ROUTER_ABI_V4_2 (59-59)
  • VAULT_CONTRACTS_V4_ANDUP (77-77)
  • TOKEN_DETAILS (66-66)
🪛 ESLint
src/index.ts

[error] 2086-2086: 'tokenURI' is never reassigned. Use 'const' instead.

(prefer-const)


[error] 2087-2087: 'metadata' is never reassigned. Use 'const' instead.

(prefer-const)

@jjramirezn jjramirezn merged commit c44e56c into main Mar 25, 2025
1 check failed
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.

1 participant