Skip to content

Include the declared gas fee in MAYAChain/THORChain fees - #1084

Open
j0ntz wants to merge 1 commit into
masterfrom
jon/cacao-max-send
Open

Include the declared gas fee in MAYAChain/THORChain fees#1084
j0ntz wants to merge 1 commit into
masterfrom
jon/cacao-max-send

Conversation

@j0ntz

@j0ntz j0ntz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

Asana task

Asana: https://app.asana.com/1/9976422036640/project/1201386023359434/task/1214062657363212

A CACAO max send never left the wallet. The app reported "Transaction Success"
and wrote a sent transaction into history, but nothing moved on-chain.

MAYAChain and THORChain price a transaction by a flat network fee rather than by
gas, so MayachainEngine and ThorchainEngine quote that flat fee and declare a
token gas fee of 1 base unit. The signer pays BOTH: the ante handler collects the
declared gas fee before the message runs. Only the flat fee was reported as
networkFee, and since the cosmos plugin has no getMaxSpendable, edge-core-js
binary-searches makeSpend and checkBalances only enforces
amount + networkFee <= balance. A max send therefore landed on
balance - flatFee, whose real cost is balance + 1. The chain accepted it at
CheckTx and then reverted it in DeliverTx as insufficient funds.

The two engines now share a makeMidgardFee helper on MidgardEngine that owns
the declared gas coin and folds its amount into the reported networkFee.

Evidence the declared fee is a real deduction, from mayanode: every MsgSend's
first transfer event pays auth_info.fee.amount to the fee collector
maya17xpfvakm2amg962yls6f84z3kell8c5lkfyhgj, separate from the 2000000000
native-fee split (txs 78BA4DCE97C88FC72886DAC67FF67A8B1C22E83C85D38CF8718B51D491E34F77
and 128511AD8D479524A2E1F6C5C9DE77029AE2E5EAFA4F5A0F946385536F033E49).

Verification

Driven in the app on the iOS simulator with this branch baked in via updot,
sending between two CACAO wallets on edge-funds.

before after
MAX amount offered 10.15 CACAO 10.1499999998 CACAO
fee shown 0.2 0.2000000001
on-chain result BFBC11AF… code 1, insufficient funds 544BA17E… code 0
sender balance unchanged apart from the 1-unit gas fee emptied to 0
recipient balance unchanged +101499999998 exactly

An ordinary non-max send was driven afterwards and also lands code 0
(051A9C29…),
with the sender debited amount + 2000000000 + 1.

test/cosmos/midgardCalculateFee.test.ts covers the fee arithmetic.
verify-repo.sh passes (install, prepare, eslint, mocha).

Notes for review

  • THORChain is corrected by symmetry: its calculateFee has the same shape and
    the chain is what MAYAChain forked from. Its public nodes were unreachable from
    the machine this ran on, so RUNE was not exercised on-chain. The change is safe
    either way: if RUNE does not charge the declared fee, a max send merely leaves
    1 base unit (1e-8 RUNE) behind rather than failing.
  • The Send scene now renders the fee as 0.2000000001 instead of 0.2, because
    the reported fee is the amount the chain actually takes. Rounding that back to
    a pretty 0.2 for display would reintroduce the failure if it were also used
    for the max calculation, so it is left accurate here.

Note

Cursor Bugbot is generating a summary for commit 2e667be. Configure here.

@j0ntz

j0ntz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

📸 Test evidence

max amount and fee

max amount and fee

tx success

tx success

postfix max amount and fee

postfix max amount and fee

postfix tx success

postfix tx success

postfix txid detail

postfix txid detail

postfix wallet emptied

postfix wallet emptied

postfix normal send success

postfix normal send success

Captured by the agent's in-app test run (build-and-test).

Both chains price a transaction by a flat network fee, so the engines report
that fee and declare a token gas fee of 1 base unit. The signer pays both: the
ante handler collects the declared gas fee before the message runs. Reporting
only the flat fee put a max send one base unit over the balance, so the chain
accepted the transaction and then reverted it as insufficient funds while the
app showed a successful send.
@j0ntz
j0ntz force-pushed the jon/cacao-max-send branch from 057bfc6 to 2e667be Compare August 10, 2026 20:09
@j0ntz
j0ntz marked this pull request as ready for review August 10, 2026 20:09
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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