Skip to content

fix when fx is same cost token as fx - #438

Merged
ezraripps merged 1 commit into
mainfrom
feature/fix-cost-same-token-fx
Sep 2, 2026
Merged

ezraripps merged 1 commit into
mainfrom
feature/fix-cost-same-token-fx

Conversation

@ezraripps

@ezraripps ezraripps commented Sep 2, 2026

Copy link
Copy Markdown
Member

closes #435

Fixes a bug when the fee for an fx transfer is the same token that the user is expected to send to the anchor


Note

Medium Risk
Touches FX swap construction and settlement validation where token amounts must match quotes; incorrect merging or fee inference could mis-settle funds, though scope is narrow and covered by new tests.

Overview

Summary

FX swaps failed when the quoted fee used the same token as the amount sent to the anchor. The client could not keep a separate fee SEND and the tagged principal SEND in one block, and the server rejected or mis-reported those exchanges.

Related Issues

Closes #435

Changes Made

  • Auto-built exchange blocks add swap amount and same-token fee in one principal SEND when the fee token matches the from token
  • Exchange block validation totals multiple SENDs of the same token instead of rejecting them
  • Completed exchange conversion summaries infer same-token fees from gross from-token sends (net of refunds) when there is no separate fee SEND

Testing

  • createExchange succeeds when FX fee is charged in the send token in client.test.ts (end-to-end quote, balances, getExchangeStatus conversion)
  • util.test.ts cases for dual same-token SEND blocks (quote-based and non-quote)

Breaking Changes

None

Reviewed by Cursor Bugbot for commit b128a53. Configure here.

@ezraripps ezraripps self-assigned this Sep 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b128a53. Configure here.

Comment thread src/services/fx/server.ts
amount: sameTokenCost.toString()
};
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unused same-token fees kept

Medium Severity

Estimate swaps that charge the fee in the from token fund expectedCost.max on the principal SEND, but excess over the live fee is not refundable when affinity is from. The unused buffer stays with the liquidity provider, and conversion.cost reports that gross overage instead of the fee actually charged.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b128a53. Configure here.

@ezraripps
ezraripps merged commit 23987f9 into main Sep 2, 2026
4 checks passed
@ezraripps
ezraripps deleted the feature/fix-cost-same-token-fx branch September 2, 2026 19:20
@ezraripps ezraripps mentioned this pull request Sep 10, 2026
ezraripps added a commit that referenced this pull request Sep 10, 2026
Includes changes from:
 - #440 
 - #438 
 - #437 
 - #434
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.

FX Anchor issues

2 participants