-
Notifications
You must be signed in to change notification settings - Fork 0
Fixes for borrow recipes #22
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
Open
0xYoki
wants to merge
8
commits into
main
Choose a base branch
from
fixes-for-borrow-recipes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ba1fba
chore: drop network in args, no prompting for amount, infer the token…
0xYoki 3c8eaee
chore: add network to skipped fields and pre-set in args
0xYoki 5e38fe1
chore: skip the second network prompt
0xYoki 015d5d0
chore: stop suggestions on optional fields
0xYoki 4f886b3
chore: prefill the address of the token selected to be rapid
0xYoki f7d8339
chore: skip token address prompt each time you already select the asset
0xYoki 6c72f14
chore: fix prefilled amount triggering amountRaw prompts
0xYoki bfa7b9e
chore: update token auto-inference
0xYoki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -382,6 +382,35 @@ function formatHealthFactor(value: string | null): string { | |
| return `${num.toFixed(2)}${indicator}`; | ||
| } | ||
|
|
||
| /** | ||
| * Sanitize action args before sending to the API: | ||
| * - Remove `network` (API infers it from marketId; sending it causes validation error). | ||
| * - When both `amount` and `amountRaw` are present, send only `amount` so the user | ||
| * can provide human-readable amount without being forced to also send amountRaw. | ||
| */ | ||
| function sanitizeActionArgs(args: ArgumentsDto): ArgumentsDto { | ||
| const { network: _n, amount, amountRaw, collateralAmount, collateralAmountRaw, ...rest } = args; | ||
| const out: ArgumentsDto = { ...rest }; | ||
|
|
||
| if (hasValue(amount)) { | ||
| out.amount = amount; | ||
| } else if (hasValue(amountRaw)) { | ||
| out.amountRaw = amountRaw; | ||
| } | ||
|
|
||
| if (hasValue(collateralAmount)) { | ||
| out.collateralAmount = collateralAmount; | ||
| } else if (hasValue(collateralAmountRaw)) { | ||
| out.collateralAmountRaw = collateralAmountRaw; | ||
| } | ||
|
|
||
| return out; | ||
| } | ||
|
|
||
| function hasValue(v: any): boolean { | ||
| return v !== undefined && v !== null && v !== ""; | ||
| } | ||
|
|
||
| async function promptFromSchema( | ||
| schema: ArgumentSchemaDto, | ||
| skipFields: string[] = [], | ||
|
|
@@ -393,6 +422,13 @@ async function promptFromSchema( | |
| for (const [name, prop] of Object.entries(properties)) { | ||
| if (skipFields.includes(name)) continue; | ||
|
|
||
| // "Provide either X or XRaw" — skip the raw variant when the human-readable one is set, and vice versa. | ||
| // Also check skipFields to handle values pre-filled upstream (which bypass result). | ||
| if (name === "amountRaw" && (hasValue(result.amount) || skipFields.includes("amount"))) continue; | ||
| if (name === "amount" && (hasValue(result.amountRaw) || skipFields.includes("amountRaw"))) continue; | ||
| if (name === "collateralAmountRaw" && (hasValue(result.collateralAmount) || skipFields.includes("collateralAmount"))) continue; | ||
| if (name === "collateralAmount" && (hasValue(result.collateralAmountRaw) || skipFields.includes("collateralAmountRaw"))) continue; | ||
|
|
||
| const isRequired = required.includes(name); | ||
| const type = Array.isArray(prop.type) ? prop.type[0] : prop.type || "string"; | ||
|
|
||
|
|
@@ -451,7 +487,7 @@ async function promptFromSchema( | |
| type: "input", | ||
| name: "value", | ||
| message, | ||
| initial: (prop.placeholder || prop.default) as string, | ||
| initial: isRequired ? (prop.placeholder || prop.default) as string : undefined, | ||
| validate: (input: string) => { | ||
| if (!isRequired && input === "") return true; | ||
| if (isRequired && input === "") return `${prop.label || name} is required`; | ||
|
|
@@ -855,19 +891,27 @@ async function viewPosition( | |
|
|
||
| for (const supply of position.supplyBalances) { | ||
| for (const pa of supply.pendingActions) { | ||
| const enrichedAction = { | ||
| ...pa, | ||
| args: { ...pa.args, tokenAddress: pa.args.tokenAddress || supply.tokenAddress }, | ||
| }; | ||
| allPendingActions.push({ | ||
| display: `[Supply] ${supply.tokenSymbol} - ${pa.label}`, | ||
| pendingAction: pa, | ||
| pendingAction: enrichedAction, | ||
| source: `${supply.tokenSymbol} supply`, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| for (const debt of position.debtBalances) { | ||
| for (const pa of debt.pendingActions) { | ||
| const enrichedAction = { | ||
| ...pa, | ||
| args: { ...pa.args, tokenAddress: pa.args.tokenAddress || debt.tokenAddress }, | ||
| }; | ||
| allPendingActions.push({ | ||
| display: `[Debt] ${debt.tokenSymbol} - ${pa.label}`, | ||
| pendingAction: pa, | ||
| pendingAction: enrichedAction, | ||
| source: `${debt.tokenSymbol} debt`, | ||
| }); | ||
| } | ||
|
|
@@ -1048,9 +1092,39 @@ async function executeActionFlow( | |
| if (!selected) throw new Error("Invalid market selected"); | ||
|
|
||
| const market = selected.market; | ||
| const args: ArgumentsDto = { marketId: market.id }; | ||
| const args: ArgumentsDto = { marketId: market.id, network }; | ||
|
|
||
| const skipFields: string[] = ["marketId", "network"]; | ||
|
|
||
| // Infer tokenAddress from the selected market when the action unambiguously targets a specific token. | ||
| // - Supply on isolated markets (Morpho): collateral is fixed by the market. | ||
| // - Pool-based (Aave): all actions target the market's loanToken. | ||
| // - Borrow/Repay on any market type: always the loanToken. | ||
| // - Isolated withdraw / collateral toggles: leave user-driven (could target collateral). | ||
| const schemaHasTokenAddress = Boolean(actionDef.schema.properties?.tokenAddress); | ||
| if (schemaHasTokenAddress) { | ||
| if ( | ||
| market.type === "isolated" && | ||
| actionType === BorrowActionType.SUPPLY && | ||
| market.collateralTokens.length > 0 && | ||
| market.collateralTokens[0].token.address | ||
| ) { | ||
| args.tokenAddress = market.collateralTokens[0].token.address; | ||
| skipFields.push("tokenAddress"); | ||
| } else if ( | ||
| ( | ||
| market.type === "pool" || | ||
| actionType === BorrowActionType.BORROW || | ||
| actionType === BorrowActionType.REPAY | ||
| ) && | ||
| market.loanToken.address | ||
| ) { | ||
| args.tokenAddress = market.loanToken.address; | ||
| skipFields.push("tokenAddress"); | ||
| } | ||
| } | ||
|
|
||
| const collected = await promptFromSchema(actionDef.schema, ["marketId"]); | ||
| const collected = await promptFromSchema(actionDef.schema, skipFields); | ||
| Object.assign(args, collected); | ||
|
|
||
| console.log("\nAction Summary:"); | ||
|
|
@@ -1079,11 +1153,12 @@ async function executeActionFlow( | |
| } | ||
|
|
||
| console.log("\nCreating action...\n"); | ||
| const argsForApi = sanitizeActionArgs(args); | ||
| const actionResponse = await apiClient.createAction({ | ||
| integrationId: integration.id, | ||
| action: actionType, | ||
| address, | ||
| args, | ||
| args: argsForApi, | ||
| }); | ||
|
|
||
| if (actionResponse.metadata) { | ||
|
|
@@ -1113,7 +1188,7 @@ async function executePendingAction( | |
| ): Promise<void> { | ||
| const actionDef = integration.actions.find((a) => a.id === pendingAction.type); | ||
| const schema = actionDef?.schema; | ||
| const preFilledArgs = { ...pendingAction.args }; | ||
| const preFilledArgs: ArgumentsDto = { ...pendingAction.args, network }; | ||
| const preFilledFields = Object.keys(preFilledArgs).filter( | ||
| (k) => preFilledArgs[k] !== undefined && preFilledArgs[k] !== null, | ||
| ); | ||
|
Comment on lines
+1191
to
1194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Treat empty-string prefilled values as missing. Line 1180-Line 1182 currently marks 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 |
||
|
|
@@ -1155,11 +1230,12 @@ async function executePendingAction( | |
| } | ||
|
|
||
| console.log("\nCreating action...\n"); | ||
| const argsForApi = sanitizeActionArgs(args); | ||
| const actionResponse = await apiClient.createAction({ | ||
| integrationId: integration.id, | ||
| action: pendingAction.type, | ||
| address, | ||
| args, | ||
| args: argsForApi, | ||
| }); | ||
|
|
||
| if (actionResponse.metadata) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.