feat: wip for unbalanced join via swap #747
Draft
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.
Handle maxAdjustableAmount = 0 explicitly: Rejects single-sided unbalanced joins at the SDK level with a clear SDKError, since the router’s proportional-add+swap design cannot drive the adjustable leg to exactly zero in general.
GivenOut (EXACT_OUT correction swap): Adds a helper that scales the BPT target up from the proportional join when needed so that the proportional exact token amount exceeds the user’s exactAmount by at least a fee‑adjusted minSwapAmount, enabling a robust EXACT_OUT correction swap within the adjustable budget.
GivenIn (EXACT_IN correction swap, baseline): Adds a helper that starts from the proportional join and, if necessary, scales the reference down so that (1) the correction swap delta satisfies the fee‑adjusted minSwapAmount constraint and (2) the proportional adjustable amount is within maxAdjustableAmount, thus staying close to proportional while respecting constraints.
GivenIn (EXACT_IN with minimized adjustable): Adds an aggressive helper and routing flag (minimizeAdjustableAmount) that binary‑searches over smaller internal references/BPT targets to minimize the adjustable token in, while still enforcing Vault min‑trade constraints, the user’s maxAdjustableAmount, and a constant‑price underflow guard to avoid router underflows in the adjustable leg (the underflow guard is not working properly yet).