Skip to content

Price automatic fees at Coinset's fee tiers - #1028

Merged
Rigidity merged 7 commits into
mainfrom
rigidity/coinset-fee-tiers-auto-fee
Nov 18, 2026
Merged

Rigidity merged 7 commits into
mainfrom
rigidity/coinset-fee-tiers-auto-fee

Conversation

@Rigidity

@Rigidity Rigidity commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Automatic fees can now be priced at a speed using Coinset's fee estimates. Before, they always paid the minimum rate.

What changes

  • Speeds. An automatic fee picks Fast (about a minute), Standard (about 5 minutes) or Economy (within an hour). Each is priced at the rate Coinset's get_fee_estimate gives for that target time, for a transaction of typical cost.

  • Floor of 5.

    • A tier's rate is never below the minimum of 5 mojos per cost.
    • A faster tier's rate is never below a slower one's.
    • Rates are rounded up to a hundredth of a mojo per cost, in whole mojos, so the rate shown is the rate paid.
  • Fallback. Every speed pays the recommended rate of 5, as before, when:

    • the network isn't one Coinset serves (anything other than mainnet or testnet11)
    • the node isn't synced
    • the request fails or takes longer than 5 seconds

    The dropdown then says estimates aren't available.

  • Overrides. A custom rate in mojos per cost can still be entered from the same dropdown. The pencil button still switches to a fixed fee amount.

  • Default. The Default Fee setting uses the same control, and each transaction's fee starts from it.

    • The default tier is Standard. When the mempool isn't busy, all three tiers come out at 5. When it is busy, Economy can leave a transaction waiting up to an hour.
    • An automatic fee saved before tiers existed (auto) is read as Standard.
  • Freshness.

    • Fee rates are cached for a minute and refreshed while an automatic fee input is shown.
    • Submitting with a tier refetches the rates if they're stale.
    • Switching networks or wallets clears the cache.
  • Offer coin splits. Confirming an offer fixes an automatic split fee at the rate the confirmation dialog showed. That way, a newer estimate fetched while the offer is made can't change what's paid without the user seeing it.

  • Layout. The speed name is never cut off. In narrow fields, a long rate is shortened instead, and the custom rate drops the sparkle icon to make room. The Send page now uses one column on narrow screens. Before, its memo and clawback rows spanned two columns at every width, which put Amount and Network Fee side by side on phones and pushed the fee past the screen edge.

Coinset's current_fee_rate isn't used as a floor. In live responses it equals the 1-minute estimate, so using it would price every tier as Fast.

Sandbox

The sandbox runs on a simulator with no mempool, so the bridge now serves made-up estimates in place of Coinset's:

  • They start as a busy mempool: Fast 20, Standard 10, Economy 2 (raised to 5).
  • POST <bridge>/fee-estimates with {"fast", "standard", "economy"} changes them, and null turns them off to show the fallback. docs/sandbox.md has the commands.
  • Sage gets a fee_estimator client override for this. It's used even in test mode, and only the sandbox sets it.

API

  • get_fee_rate is now async and returns tiers: FeeTier[] (name, target_time, fee_per_cost). The list is empty when there are no estimates.
  • Transaction requests are unchanged: the frontend turns a tier into fee_per_cost.
  • coinset_client (in sage-wallet) now chooses the network's Coinset client for both the mempool source and the fee estimates.

For you to decide

  • Default tier: Standard. The alternative is Economy, which matches "maybe the lowest". It's usually 5 anyway, but it can be slow when the mempool is busy. Switching is a one-line change to DEFAULT_FEE_TIER in src/lib/fees.ts.

Testing

  • Rust unit tests cover turning estimate responses into tiers:

    • the floor and the ordering
    • rounding, including rates that are already a whole hundredth
    • responses that are unsynced, failed, mismatched, or have no sync status

    The sage-rpc fee tests check that tests get no tiers. Tests never call Coinset (Sage::test).

  • Frontend tests cover:

    • parsing tiers and the legacy value
    • pricing a tier with and without estimates
    • the rate cache: stale rates, a stale request that fails, and clearing it
    • the refresh hook
    • the speed dropdown: captions with and without estimates and before the rates load, the custom rate, and the default tier
    • the offer confirmation fixing the split rate it showed
  • Sandbox tests go from the bridge's stand-in to get_fee_rate:

    • the defaults and the floor
    • changes reaching both wallets, with exact hundredths
    • turning estimates off
    • rejecting bad rates
  • Checked in the sandbox:

    • The send page's speeds show the stand-in's 20, 10 and 5, and reflect new estimates after a reload.
    • Without estimates, the dropdown shows the note and every speed pays 5.
    • A send priced at Fast showed its rate in the confirmation dialog.
    • A default tier picked in settings is saved.

Translation catalogs need pnpm extract at the next release.

Note

Medium Risk
This changes how every automatic fee is priced, and makes get_fee_rate call Coinset on mainnet and testnet11. A bad or high estimate raises fees. However, the confirmation dialog shows the fee (or, for an offer's coin split, the rate) before anything is submitted, and failures fall back to the old fixed rate of 5.

  • Backend: turns Coinset fee estimates into tiers (sage/utils/fees.rs). get_fee_rate is async and returns tiers, with new FeeTier and FeeTierName API types and regenerated bindings. There's a shared coinset_client.
  • Sandbox: a fee estimate stand-in on the bridge, with a route to change it, and a Sage::fee_estimator override that only the sandbox sets.
  • Frontend:
    • tier-aware fee values and pricing, and a rate cache cleared with the wallet state (lib/fees.ts, state.ts)
    • periodic refresh (useFeeRates)
    • a speed dropdown in the new AutoFeeInput, used by FeeAmountInput and the Default Fee setting
    • the offer split fee fixed at its confirmed rate
    • a one-column Send form on narrow screens

Automatic fees now pick a speed: Fast (about a minute), Standard (about
5 minutes) or Economy (within an hour), priced at the rate Coinset's
get_fee_estimate gives for that target time, and never below the
minimum of 5 mojos per cost. On a network Coinset doesn't serve, or when
the estimate can't be fetched, every speed pays the recommended rate as
before. A custom rate or a fixed amount can still be entered.

- get_fee_rate returns the tiers, fastest first, and is async
- The fee input picks a speed from a dropdown that shows each tier's
  rate, and the default fee setting uses the same control
- Standard is the default tier, and an automatic fee stored before
  tiers is read as Standard
- Fee rates are refreshed every minute while a fee input is shown
- Make the offer's coin split at the rate the confirmation showed, rather than a newer estimate fetched when the offer is made
- Round tier rates up in whole mojos, so a rate that's already a whole hundredth isn't raised by another one
- Share the network's Coinset client with the mempool source
- Move the automatic fee input into its own component, and the tier labels and rate formatting into the fee helpers
- Say only that estimates aren't available, since they can also fail to load on mainnet
- Test the rate refresh, the fee rate cache keeping newer rates, the split fee confirmation, and that tests get no tiers
- Forget the fee rates when the wallet's state is cleared, so a network switch doesn't price transactions at the previous network's estimates
- Show each speed's time until the rates load, rather than saying there are no estimates
- Show an entered split rate as it was entered, and fix only a tier's rate when the offer is confirmed
- Load the fee rates in the automatic fee input, so inputs showing an amount don't poll them
- Derive the tiers' target times from the tiers
- Test the speed captions without estimates and before the rates load, picking Custom again, the empty rate's placeholder, clearing the rates, and a response without a sync status
- Price the stand-in's estimates in whole hundredths of a mojo per cost, so a rate such as 5.11 isn't shown as 5.12
- Start the estimates state from the default estimates, rather than having a default with none
- Drop a check for rates JSON can't express, and simplify choosing the fee estimate client
- Test rejecting a negative standard or economy rate
The memo and clawback rows spanned two columns at every width, which gave the grid two content-sized columns below the breakpoint, so the amount and fee sat side by side and could run past the screen.
@Rigidity
Rigidity merged commit dd5abce into main Nov 18, 2026
9 checks passed
@Rigidity
Rigidity deleted the rigidity/coinset-fee-tiers-auto-fee branch November 18, 2026 18:32
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