Skip to content

feat: add slippageIncrement to routeForTargetAmount#176

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

feat: add slippageIncrement to routeForTargetAmount#176
jjramirezn merged 1 commit intomainfrom
develop

Conversation

@jjramirezn
Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2025

Walkthrough

The changes add a new optional numeric parameter, slippageIncrement, to the IPrepareXchainRequestFulfillmentTransactionProps type in src/request.ts. The prepareXchainRequestFulfillmentTransaction function now accepts this parameter and passes it through for further processing. In src/util.ts, the routeForTargetAmount function is updated to include slippageIncrement as an optional parameter, with a default value of 0.4 if not provided. This parameter is then used in the calculation of the slippage percentage, replacing a previously hardcoded value. Additionally, minor refactoring in the prepareXchainFromAmountCalculation function improves code readability by reformatting lines that convert token prices and amounts into BigNumber instances. These modifications expand the functionality to allow more flexible control over slippage handling without altering existing logic.

Possibly related PRs

  • Release smart slippage calculation #167: Introduces a slippageIncrement parameter in the routeForTargetAmount function, directly aligning with the changes made in the main PR.
  • [TASK-6918] Calculate minimum slippage needed for request #166: Adds the slippageIncrement parameter to the prepareXchainRequestFulfillmentTransaction function, which is then utilized by the modified routeForTargetAmount function.
  • Release  #163: Implements a new slippageIncrement parameter in the prepareXchainRequestFulfillmentTransaction function and reflects corresponding adjustments in the routeForTargetAmount, signifying a strong code-level connection.
✨ 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 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: 0

🧹 Nitpick comments (1)
src/request.ts (1)

53-53: Use const instead of let for slippageIncrement

The variable is never reassigned, so it's better to use const to prevent accidental reassignment.

-	let {
+	const {
 		senderAddress,
 		fromToken,
 		fromTokenDecimals,
 		fromChainId,
 		squidRouterUrl,
 		provider,
 		tokenType,
 		slippagePercentage,
 		slippageIncrement,
 		linkDetails,
 	} = props
🧰 Tools
🪛 ESLint

[error] 53-53: 'slippageIncrement' 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 1a42c00 and 26509a4.

📒 Files selected for processing (2)
  • src/request.ts (3 hunks)
  • src/util.ts (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: jjramirezn
PR: peanutprotocol/peanut-sdk#166
File: src/request.ts:260-264
Timestamp: 2025-03-20T16:52:53.176Z
Learning: Validation for `slippagePercentage` is already performed within the called functions in `prepareXchainRequestFulfillmentTransaction`, so additional validation in this function is unnecessary.
src/request.ts (1)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-sdk#166
File: src/request.ts:260-264
Timestamp: 2025-03-20T16:52:53.176Z
Learning: Validation for `slippagePercentage` is already performed within the called functions in `prepareXchainRequestFulfillmentTransaction`, so additional validation in this function is unnecessary.
🪛 ESLint
src/request.ts

[error] 53-53: 'slippageIncrement' is never reassigned. Use 'const' instead.

(prefer-const)

🔇 Additional comments (6)
src/request.ts (2)

25-25: Good addition of the slippageIncrement parameter

This new optional parameter will give users more control over slippage handling during cross-chain transactions. It's properly integrated in the type definition.


114-114: Good implementation of passing the slippageIncrement parameter

The parameter is correctly passed to the routeForTargetAmount function, maintaining consistency with the function's signature in util.ts.

src/util.ts (4)

751-762: Good code formatting improvement

The multi-line formatting of these BigNumber conversions improves readability while maintaining the same functionality. Each parameter is now clearly visible on its own line.


842-843: Appropriate addition of slippageIncrement parameter

Adding this parameter to the function signature and interface allows for configurable slippage increments, which provides better flexibility for different trading scenarios.

Also applies to: 851-852


891-891: Default value for slippageIncrement is higher than previous hardcoded value

The default value is now set to 0.4, which is higher than the previous hardcoded value of 0.1. This will make the slippage increase more aggressively by default, potentially reaching the target amount faster but with higher slippage.

Consider whether this more aggressive default is intentional. It may result in trades executing with higher slippage than before, which could affect users who don't explicitly provide a slippageIncrement value.


905-905: Good implementation of dynamic slippage increment

Replacing the hardcoded 0.1 increment with the configurable slippageIncrement parameter correctly implements the intended functionality.

@jjramirezn jjramirezn merged commit 2d7d3b7 into main Mar 20, 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