feat: apply Paytaca platform fee on Cauldron swaps (0.3%, 1 USD cap) - #5
Conversation
Co-authored-by: joemarct <joemarct@users.noreply.github.com>
Review: feat/cauldron-platform-feeOverall: The PR cleanly implements the platform fee logic with correct math, good test coverage, and safe degradation when the fee endpoint or price feed fails. The 13 new tests all pass, and the build is clean. What I like:
Issues found & fixes applied:
Build & test status after fixes:
I have not committed the fixes — let me know if you'd like me to push them to the branch. |
|
User github-actions[bot] does not have write permissions |
Review: feat/cauldron-platform-feeOverall verdict: Approve with minor notes. What looks good
Minor findings (non-blocking)
Build & testsI was unable to run Bottom lineThe fee logic is safe, well-tested, and ready to merge. Addressing note #2 (adding |
Review: feat/cauldron-platform-feeOverall verdict: Approve. The PR adds a conservative, well-gated platform fee to Cauldron swaps. I independently verified the branch builds cleanly and all tests pass. Verified locally
What looks good
Minor notes (non-blocking)
Bottom lineThe platform fee logic is safe, well-tested, and correctly degrades when dependencies are unavailable. Ready to merge. |



Summary
Applies the Paytaca platform fee to Cauldron token ⇄ BCH swaps, mirroring paytaca-app's trade page behavior. The fee config (recipient address, rate, cap) is served by watchtower.cash via the new
GET /api/cauldron-fee/endpoint (watchtower-cash commit3d2b4f51, already deployed to production).Fee rule
fee = (tradeSize − trade_fee) × fee_rate_bps / 10000, wheretradeSizeis the BCH side of the trade (summary.supplywhen buying tokens,summary.demandwhen selling) andtrade_feeis the Cauldron DEX's own fee (so the platform fee is not charged on top of it).The fee is charged only when ALL of the following hold — otherwise it is skipped entirely (clients degrade silently):
addressin the endpoint response)/api/asset-prices/(price failure → no fee)max_usdworth of BCH at the current price (1 USD default) and the result is ≥ 546 sats — below the dust threshold, no fee output is added at allApplies to both swap directions. On sells the fee is deducted from the BCH change output; on buys it is added to the BCH funding target.
Changes
PlatformFeeConfigtype +fetchCauldronFee(isChipnet)hitting{watchtowerApiUrl}/cauldron-fee/; empty address maps tonull(feature disabled).computePlatformFee()pure helper (rate math + USD cap + 546-sat dust floor,PLATFORM_FEE_DUST_LIMIT = 546n);estimateSwap()fetches the fee config in parallel (failure → no fee) and the BCH price only when enabled;SwapQuote.platformFee/platformFeeRateBps;buildSignedTradeTx()passesplatformFeeintocreateInputAndOutput()(existing plumbing emits it as a FIXED payout);formatQuote()showsPlatform fee (0.3%): ~X BCHorPlatform fee (0.3%, capped).formatQuotefee line (normal + capped + omitted), andfetchCauldronFeeresponse parsing (defaults, empty address, HTTP error).Naming
"Platform fee" is used throughout the client to distinguish it from the Cauldron DEX's own
trade_fee(shown as the separate "Trade fee" quote line). The backend endpoint/setting usesCAULDRON_FEE*names (fee_rate_bps: 30= 0.3%).Testing
npm test→ 104/104 pass (incl. 13 new)tsc --noEmitclean;npm run buildOKfetchCauldronFee()returns{address: bitcoincash:qp9szr..., feeRateBps: 30, maxUsd: 1}Rollout
Fee is already active in production (endpoint deployed with
CAULDRON_FEE_ADDRESSset). Older clients are unaffected — they never query the endpoint.