Skip to content

Fixes for borrow recipes#22

Open
0xYoki wants to merge 8 commits intomainfrom
fixes-for-borrow-recipes
Open

Fixes for borrow recipes#22
0xYoki wants to merge 8 commits intomainfrom
fixes-for-borrow-recipes

Conversation

@0xYoki
Copy link
Contributor

@0xYoki 0xYoki commented Mar 3, 2026

Added

Description of new functionality, feature, or content that has been added in this pull request.

Changed

Description of the modifications made to existing functionality, feature, or content in this pull request. This could include changes to code, CI, documentation, etc.

Summary by CodeRabbit

  • Refactor

    • Improved internal argument handling and payload sanitization for more consistent behavior across actions and edits.
    • Adjusted prompt initialization so required fields use placeholders/defaults while optional fields stay unset until needed.
  • New Features

    • UI now auto-populates token identifiers when available, reducing extra user input.
    • Prompts skip raw/duplicate variants when a human-readable value exists, cutting redundant questions.

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

Adds internal helpers to sanitize action arguments and detect value presence; updates prompt generation to prefer human-readable amount fields; enriches pending actions with inferred tokenAddress; and ensures sanitized payloads (dropping network and raw variants) are used when creating or editing borrow actions.

Changes

Cohort / File(s) Summary
Borrow recipe
recipes/borrow.ts
Adds sanitizeActionArgs() and hasValue(); modifies promptFromSchema to skip raw variants when human-readable values exist; adjusts initial prompt values; enriches pending actions with inferred tokenAddress; includes network/tokenAddress in initial args and omits them from prompts when inferred; ensures sanitized payloads are used for action creation and edits.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested reviewers

  • Philippoes
  • jdomingos

Poem

🐰 I hop through args both raw and neat,
Dropping networks and choosing which amounts to keep,
I tuck a tokenAddress into pending plans,
So prompts stay simple and actions land,
A tidy borrow flow — quiet paws, light leaps.

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description contains only the template structure with empty sections; no actual content describing what was added or changed is provided. Fill in the "Added" and "Changed" sections with specific details about the new sanitization helpers, enhanced prompting logic, and token address inference improvements mentioned in the summary.
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "Fixes for borrow recipes" is vague and generic, using non-descriptive language that doesn't convey what specific issues were fixed or the primary changes made. Replace with a more specific title that describes the actual fixes, such as "Improve borrow recipe argument sanitization and token auto-inference" or "Add argument sanitization and token address inference to borrow recipes."

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fixes-for-borrow-recipes

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@recipes/borrow.ts`:
- Around line 1179-1182: The current preFilledFields calculation treats empty
strings as valid values, allowing blank inputs to bypass prompts; update the
filter for preFilledArgs used in preFilledFields (derived from
pendingAction.args and network) to also exclude values that are empty strings
(e.g., value === "" or value.trim() === "" for strings) so only non-null,
non-undefined, non-empty-string entries are considered prefilled.
- Around line 425-429: The skip logic only checks result
(hasValue(result.amount)) so prefilled or skipped fields upstream still allow
their raw counterparts (e.g., amountRaw) to be prompted; update the conditions
in the block that inspects name/result to also consider
upstream/skipped/prefilled inputs by checking skipFields (or the original
prefill/initialValues) in addition to result—e.g., change the checks for
amount/amountRaw and collateralAmount/collateralAmountRaw to skip when
hasValue(result.amount) || skipFields.includes("amount") ||
hasValue(initialValues?.amount) (and the analogous checks for collateralAmount),
keeping the same name, result, skipFields and hasValue symbols to locate and
update the conditions.
- Around line 1094-1115: The current logic unconditionally infers
args.tokenAddress from market.loanToken.address and adds "tokenAddress" to
skipFields, which wrongly prevents users from selecting collateral-sensitive
tokens for actions like withdraw or collateral toggles; update the conditional
around setting args.tokenAddress and pushing "tokenAddress" so it only
auto-infers for action types where the token must be the loan token (e.g.,
BorrowActionType.BORROW, BorrowActionType.REPAY, and pool-based SUPPLY), and
ensure for isolated markets and non-supply actions (like WITHDRAW or collateral
toggles) you do not set args.tokenAddress or skip the field; adjust the checks
around market.type, actionType, market.collateralTokens, and market.loanToken
before calling promptFromSchema(actionDef.schema, skipFields) so
promptFromSchema still asks for tokenAddress when user selection is required.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cb89d52 and f7d8339.

📒 Files selected for processing (1)
  • recipes/borrow.ts

Comment on lines +1179 to 1182
const preFilledArgs: ArgumentsDto = { ...pendingAction.args, network };
const preFilledFields = Object.keys(preFilledArgs).filter(
(k) => preFilledArgs[k] !== undefined && preFilledArgs[k] !== null,
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Treat empty-string prefilled values as missing.

Line 1180-Line 1182 currently marks "" as prefilled, which can skip required prompts and forward invalid blanks.

Suggested fix
-  const preFilledFields = Object.keys(preFilledArgs).filter(
-    (k) => preFilledArgs[k] !== undefined && preFilledArgs[k] !== null,
-  );
+  const preFilledFields = Object.keys(preFilledArgs).filter((k) => hasValue(preFilledArgs[k]));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@recipes/borrow.ts` around lines 1179 - 1182, The current preFilledFields
calculation treats empty strings as valid values, allowing blank inputs to
bypass prompts; update the filter for preFilledArgs used in preFilledFields
(derived from pendingAction.args and network) to also exclude values that are
empty strings (e.g., value === "" or value.trim() === "" for strings) so only
non-null, non-undefined, non-empty-string entries are considered prefilled.

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.

♻️ Duplicate comments (1)
recipes/borrow.ts (1)

1192-1194: ⚠️ Potential issue | 🟡 Minor

Use hasValue for preFilledFields to avoid skipping prompts on empty strings.

Line 1192 still treats "" as prefilled, which can suppress required prompts and forward blank values.

Suggested fix
-  const preFilledFields = Object.keys(preFilledArgs).filter(
-    (k) => preFilledArgs[k] !== undefined && preFilledArgs[k] !== null,
-  );
+  const preFilledFields = Object.keys(preFilledArgs).filter((k) =>
+    hasValue(preFilledArgs[k]),
+  );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@recipes/borrow.ts` around lines 1192 - 1194, preFilledFields currently treats
empty strings as filled because it filters preFilledArgs by !== undefined && !==
null; change the filtering to use the existing hasValue predicate so "" is
considered empty and won't skip prompts — update the declaration of
preFilledFields (which references preFilledArgs) to filter with
hasValue(preFilledArgs[k]) instead of the current null/undefined checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@recipes/borrow.ts`:
- Around line 1192-1194: preFilledFields currently treats empty strings as
filled because it filters preFilledArgs by !== undefined && !== null; change the
filtering to use the existing hasValue predicate so "" is considered empty and
won't skip prompts — update the declaration of preFilledFields (which references
preFilledArgs) to filter with hasValue(preFilledArgs[k]) instead of the current
null/undefined checks.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f7d8339 and bfa7b9e.

📒 Files selected for processing (1)
  • recipes/borrow.ts

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