Skip to content

fix(sdk-coin-flrp): add correct C-chain atomic import gas formula - #9378

Closed
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
cecho-1820/fix-flare-atomic-import-gas-estimate
Closed

fix(sdk-coin-flrp): add correct C-chain atomic import gas formula#9378
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
cecho-1820/fix-flare-atomic-import-gas-estimate

Conversation

@bitgo-ai-agent-dev

Copy link
Copy Markdown

What

  • Add calcImportCGas(txByteLen, numSigs) to sdk-coin-flrp/src/lib/utils.ts implementing the correct coreth gas formula: txByteLen × 1 + numSigs × 1000 + AtomicTxBaseCost(10000)
  • Add calcImportCFee(txByteLen, numSigs, baseFeeNanoFlr, multiplier=2n) that multiplies the gas estimate by the live C-chain base fee with a 2× volatility buffer
  • Export both functions (plus the three cost constants) from sdk-coin-flrp lib index
  • Add importFeeMultiplier = 2 to FlareP and FlarePTestnet network statics so wallet-platform can read the recommended buffer from network config
  • Add 8 unit tests covering the ticket scenario (311B tx, 1 sig, 500 gwei base fee) and edge cases

Why

  • Flare C-chain atomic imports were being signed with an underfunded fee when the base fee was elevated. At 500 gwei (20× the 25 gwei floor), wallet-platform computed ~5700 gas (missing the 10k AtomicTxBaseCost), resulting in 2.85M nFLR baked in when the node required ~5.66M nFLR. The import fails with inputs < outputs + requiredFee.
  • This is amount-independent — even a 69 FLR import fails the same way as dust when the base fee spikes.
  • The fix exposes the correct gas formula from the SDK so wallet-platform can call calcImportCGas / calcImportCFee instead of maintaining its own (broken) estimate.

Test plan

  • 8 unit tests in modules/sdk-coin-flrp/test/unit/lib/utils.ts all pass
  • TypeScript compiles cleanly for sdk-coin-flrp and statics
  • wallet-platform updated to call FlrPLib.calcImportCFee(txByteLen, numSigs, liveBaseFee) instead of the static gas estimate

Ticket: CECHO-1820

The coreth gas formula for an atomic import is:
  gas = txByteLen × 1 + numSigs × 1000 + AtomicTxBaseCost(10000)

Wallet-platform was computing ~5700 gas (missing the 10k base cost),
which underpriced the fee at elevated base fees (e.g. 500 gwei on
Coston2 requires ~5.66M nFLR but only ~2.85M was provided).

Add `calcImportCGas(txByteLen, numSigs)` and
`calcImportCFee(txByteLen, numSigs, baseFeeNanoFlr, multiplier=2n)`
to sdk-coin-flrp/utils and export them from the lib index.  Also add
`importFeeMultiplier = 2` to FlareP / FlarePTestnet statics so
wallet-platform can read the recommended volatility buffer from the
network config.

Ticket: CECHO-1820
Session-Id: 9f75098f-e910-4499-a1d8-721714606982
Task-Id: e8063c60-329d-4d80-9a39-725b4abc5ade
@linear-code

linear-code Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

CECHO-1820

@bitgo-ai-agent-dev
bitgo-ai-agent-dev Bot force-pushed the cecho-1820/fix-flare-atomic-import-gas-estimate branch from f7a85c2 to d47a626 Compare July 29, 2026 06:43
@ralph-bitgo
ralph-bitgo Bot force-pushed the cecho-1820/fix-flare-atomic-import-gas-estimate branch from d47a626 to 33640ae Compare July 29, 2026 06:43
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