Skip to content

fix(swap): correct fee simulation display with proper decimal conversion#11

Merged
MinaraAgent merged 3 commits intomainfrom
fix/swap-simulation-fee-formatting
Apr 3, 2026
Merged

fix(swap): correct fee simulation display with proper decimal conversion#11
MinaraAgent merged 3 commits intomainfrom
fix/swap-simulation-fee-formatting

Conversation

@MinaraAgent
Copy link
Copy Markdown
Member

Summary

  • Fix ETH swap fee simulation returning astronomical values (e.g., $339,562,475,978,087,550.00)
  • Update types to match the new API response schema for /v1/tx/cross-chain/swaps-simulate
  • Add proper BigInt-to-decimal conversion using token's decimals field

Changes

  • Types: Added TokenInfoDto, TokenChangeDto, CrossChainSwapsSimulateResultDto matching the updated OpenAPI schema
  • Formatters: Added formatWeiToUsd() and formatTokenAmount() helpers for proper unit conversion
  • Swap command: Updated to use new printSwapSimulation() function

Details

  • Token amounts: converted using token.decimals from API response
  • Fee USD values: converted using 10^18 divisor (wei format)
  • priceImpact=-1 now displays as — (negligible) instead of -1%
  • Added sanity check warning for fees exceeding $1000

Test plan

  • Run ./bin/minara.js swap -s buy -t "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" -a 5 --chain ethereum --dry-run
  • Verify fees display reasonable values instead of astronomical numbers
  • All 270 tests pass

- Add TokenInfoDto and CrossChainSwapsSimulateResultDto types matching updated API schema
- Use token.decimals for token amount conversion (previously raw BigInt strings)
- Use 10^18 divisor for USD fee values (wei format)
- Add formatWeiToUsd() and formatTokenAmount() helper functions
- Handle priceImpact=-1 as "negligible" instead of displaying "-1%"
- Add sanity check warning for fees exceeding $1000
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces structured types and enhanced formatting for cross-chain swap simulations. It updates the API client to use the new CrossChainSwapsSimulateResponseDto and adds a dedicated printSwapSimulation formatter to provide detailed, human-readable output for token changes and fees. Review feedback identified a logic error in how simulation results are accessed from the API response and noted that token.realDecimals should be used for accurate amount formatting as per the type definitions.

Comment thread src/commands/swap.ts
Comment thread src/formatters.ts
Comment thread src/formatters.ts
The API client already extracts .data from the response, so the function
should return CrossChainSwapsSimulateItem[] not wrapped in ResponseDto.
The implementation uses token.decimals for amount conversion as per
the requirement that display decimals should match the token's standard.
@MinaraAgent MinaraAgent merged commit c350596 into main Apr 3, 2026
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