Skip to content

Conversation

@Jon-edge
Copy link
Contributor

@Jon-edge Jon-edge commented Oct 24, 2025

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

none

Note

Adds an iterative, fee-estimating getMaxSpendable to Cosmos engine (incl. IBC cases) and updates CHANGELOG.

  • Cosmos Engine (src/cosmos/engine/CosmosEngine.ts):
    • Add getMaxSpendable(spendInfo) using iterative (binary search) fee estimation via calculateFee, supporting memos, tokens, and IBC transfers with validateTransfer.
    • Update math utils import to include div and lte.
  • CHANGELOG:
    • Add entry: fixed (cosmos) Fix max spend.

Written by Cursor Bugbot for commit b289105. This will update automatically on new commits. Configure here.


Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1160 to +1162
const totalCost = add(mid, networkFee)
if (gt(totalCost, balance)) {
return await getMax(min, mid)

Choose a reason for hiding this comment

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

P1 Badge Handle gas balance separately for token max spend

When computing the maximum spendable amount for Cosmos tokens, the code adds the fee (denominated in the native gas token) to the token amount and compares that sum with the token balance. This has two consequences: the returned token amount is reduced by the fee even though the fee is paid in the native currency, and worse, if the wallet lacks native coins to cover the fee the method will still return the full token balance as spendable. Users attempting to send a token with zero native balance will therefore see a non‑zero max amount and then hit an “insufficient fee” failure during makeSpend. The fee needs to be checked against the native balance instead of being combined with the token amount.

Useful? React with 👍 / 👎.

Copy link
Contributor

@swansontec swansontec left a comment

Choose a reason for hiding this comment

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

The core's default implementation calls makeSpend in a binary search. How does this really differ? Also, there is the issue AI found where the fee gets added to the token value - seems like a units mix-up?


async getMaxSpendable(spendInfo: EdgeSpendInfo): Promise<string> {
const { memos = [], tokenId } = spendInfo
const { currencyCode } =
Copy link
Contributor

Choose a reason for hiding this comment

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

Just delete the currencyCode. It's not really used.

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.

3 participants