fix(sdk-coin-flrp): correct gas calculation for Flare C-chain atomic imports - #9379
fix(sdk-coin-flrp): correct gas calculation for Flare C-chain atomic imports#9379bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Conversation
1e89430 to
02cca75
Compare
afd478b to
7bd3b5f
Compare
7bd3b5f to
a87411a
Compare
a87411a to
7bd3b5f
Compare
|
@claude review this PR |
|
Claude finished @ArunBala-Bitgo's task —— View job Code Review for Flare Atomic Import Gas Calculation FixTasks
Gas Constants and Formula Analysis ✅The implementation in Constants (lines 215-241 in
Formula Implementation ( const gas = ATOMIC_TX_BASE_GAS + TX_BYTES_GAS * txSizeBytes + SECP256K1_VERIFY_GAS * numSigs;
const rawFee = gas * cChainBaseFeeNFLR;
return (rawFee * BASE_FEE_PADDING_NUMERATOR) / BASE_FEE_PADDING_DENOMINATOR;ImportInCTxBuilder Analysis ✅New
Fee Computation Logic (
Private Fee Computation (
Utility Functions and Exports ✅Export Addition (
Test Coverage Analysis ✅Comprehensive Test Suite (
Notable Test Quality:
Statics Changes Analysis ✅Network Configuration Updates:
These changes are necessary to accommodate the corrected (higher) import fees at elevated base fees. Overall Assessment✅ Strengths
🔍 Minor Observations
✅ Security Considerations
📋 Recommendations
This PR effectively resolves CECHO-1821 by implementing the missing Job Run | Branch: fix/CECHO-1821-flare-atomic-import-gas-calculation |
There was a problem hiding this comment.
Pull request overview
This PR updates the Flare P→C atomic import fee calculation in sdk-coin-flrp to match the coreth gas/fee model (including the missing atomic base gas) and adds an integration path (cChainBaseFee) for callers to supply a live C-chain base fee so the SDK can compute the correct required import fee.
Changes:
- Introduces coreth-derived atomic import gas constants and a
computeAtomicImportFee()helper, and exports it for standalone use. - Adds
ImportInCTxBuilder.cChainBaseFee()to compute/override the import fee internally using a temporary serialization for tx size. - Raises Flare P-chain
maxImportFeelimits and adds unit tests covering the formula and builder integration scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| modules/statics/src/networks.ts | Raises maxImportFee for Flare P mainnet/testnet to accommodate higher base fees with padding. |
| modules/sdk-coin-flrp/src/lib/iface.ts | Adds exported gas/padding constants used for atomic import fee computation. |
| modules/sdk-coin-flrp/src/lib/utils.ts | Adds computeAtomicImportFee() implementing the coreth fee formula. |
| modules/sdk-coin-flrp/src/lib/ImportInCTxBuilder.ts | Adds cChainBaseFee() and internal fee derivation based on base fee + tx size + signature count. |
| modules/sdk-coin-flrp/src/lib/index.ts | Re-exports computeAtomicImportFee() for external/server-side callers. |
| modules/sdk-coin-flrp/test/unit/lib/atomicImportGas.ts | Adds unit/integration tests for constants, fee formula, and builder behavior under elevated base fee. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…imports Add missing AtomicTxBaseCost (10k gas) to import fee formula and introduce cChainBaseFee() setter with 25% volatility padding. Imports were failing with 'inputs < outputs + requiredFee' at elevated C-chain base fees (e.g. 500 gwei on Coston2) because the SDK omitted the coreth AtomicTxBaseCost=10000 constant, producing ~2.85M nFLR instead of the required ~5.66M nFLR. - Add ATOMIC_TX_BASE_GAS, TX_BYTES_GAS, SECP256K1_VERIFY_GAS constants and 25% padding fraction to iface.ts - Add computeAtomicImportFee() utility implementing the full coreth formula: gas = BASE(10k) + txBytes + numSigs*1000; fee = gas*baseFee*1.25 - Add ImportInCTxBuilder.cChainBaseFee() setter that auto-computes fee from the live C-chain base fee, superseding any explicit .fee() value - Export computeAtomicImportFee from lib/index.ts - Raise maxImportFee in FlareP/FlarePTestnet statics from 10M to 20M nFLR to cover up to ~1000 gwei base fee with 25% padding - Add test/unit/lib/atomicImportGas.ts covering the 500 gwei ticket scenario, scaling properties, and cChainBaseFee() integration Fixes CECHO-1821 Session-Id: 4f8df8c7-666c-466b-a16f-d0de7fc2bb20 Task-Id: 4693a1d4-6eb4-490c-9b15-f4533feaf0b9
7bd3b5f to
be2aef1
Compare
What
iface.ts:ATOMIC_TX_BASE_GAS(10,000),TX_BYTES_GAS(1),SECP256K1_VERIFY_GAS(1,000), and 25% volatility-padding fraction constantsBASE_FEE_PADDING_NUMERATOR / DENOMINATOR.computeAtomicImportFee(txSizeBytes, numSigs, cChainBaseFeeNFLR)utility inutils.tsimplementing the full coreth formula:gas = ATOMIC_TX_BASE_GAS + txSizeBytes + numSigs × 1,000 ; fee = gas × baseFee × 1.25ImportInCTxBuilder.cChainBaseFee(baseFeeNFLR)setter that, when supplied, auto-computes the correct import fee internally using a temporary serialisation to measure tx size, superseding any previous.fee()value.computeAtomicImportFeefromsrc/lib/index.tsso server-side callers can use it standalone.maxImportFeeonFlareP(mainnet) andFlarePTestnetfrom 10,000,000 to 20,000,000 nFLR instatics/src/networks.ts, covering a 1,000 gwei base fee with 25% padding.test/unit/lib/atomicImportGas.tswith unit tests for the gas constants, the formula, andcChainBaseFee()integration including the exact Coston2 failure scenario from the ticket (500 gwei base fee).Why
Atomic imports from P-chain to Flare C-chain were failing with "inputs < outputs + requiredFee" when the C-chain base fee was elevated (observed at 500 gwei on Coston2). The SDK was computing ~5,700 gas per import by omitting the coreth
AtomicTxBaseCost = 10,000constant, resulting in a fee of only ~2,850,000 nFLR instead of the required ~5,655,000 nFLR. Any import failed regardless of amount. The fix adds the missing base cost, the 25% volatility-padding multiplier (guards against base-fee movement between signing and broadcast), and acChainBaseFee()entry point so callers can pass the live base fee instead of a pre-computed total.Test plan
computeAtomicImportFee(311n, 1n, 500n)returns7_069_375n(ticket scenario, padded)cChainBaseFee(500n)on a 1-of-1 import builds a tx whose fee > 1,000,000 nFLR (much more than old underprice)cChainBaseFee(500n)produces higher fee thancChainBaseFee(25n)on same inputscChainBaseFee()supersedes any previously set.fee()valuesignFlowTestand all currentimportInCTxBuildertests continue to pass (they use explicit.fee())Ticket: CECHO-1821