Skip to content

feat(bridge): withdrawal fee estimates — request/confirm/cancel flow#403

Open
heyolaniran wants to merge 8 commits into
lnflash:tmp/bridge-rebase-pr-readyfrom
heyolaniran:tmp/bridge-rebase-pr-ready
Open

feat(bridge): withdrawal fee estimates — request/confirm/cancel flow#403
heyolaniran wants to merge 8 commits into
lnflash:tmp/bridge-rebase-pr-readyfrom
heyolaniran:tmp/bridge-rebase-pr-ready

Conversation

@heyolaniran

Copy link
Copy Markdown
Collaborator

Summary

  • Adds withdrawal fee estimation (flash fee + bridge fee + gas buffer) computed before the user confirms a withdrawal
  • Persists the fee breakdown on the withdrawal Mongo document and surfaces it in the GraphQL API
  • Splits the withdrawal mutation into a request / confirm / cancel flow; the fee estimate is shown to the user between request and confirm
  • Adds a localized flash fee notice in the withdrawal UI
  • Fixes 4 unit test failures introduced by the above (partial module mocks missing getFeesConfig / IbexUrls, stale clearAllMocks mock bleed, toEqualtoMatchObject for shape tests that now include fee fields)

Test plan

  • yarn test:unit --testPathPattern="bridge" — all bridge unit tests pass
  • yarn test:unit --testPathPattern="ibex/client-usd-wallet" — ibex client test passes
  • yarn test:unit — full unit suite green
  • Bruno collection for withdrawal fee estimates runs against sandbox
  • Manual: request withdrawal → fee estimate shown → confirm → submitted with correct fee fields on the record

Introduce developerFeePercent and withdrawalFeeEstimate settings
(bridge fixed fee, gas limit, RPC URL, and fallbacks) for customer
fee breakdown on Bridge withdrawals.
Add flash fee, Bridge rail fee (0.6%), and buffered Ethereum gas
estimates, plus presenter helpers for pending vs receipt amounts.
Store flash, Bridge, gas, and total customer fee estimates on pending
withdrawals and refresh them when reusing an existing pending request.
Resolve and persist fee estimates on request, map Bridge transfer
receipt fees on initiate, improve Ibex balance error mapping, and pass
developer_fee_percent when creating virtual accounts.
Expose flashFeeNotice copy explaining Flash, Bridge, and gas buffer
components while totals remain estimates until Bridge settles.
Add estimated fee breakdown, subtotal/final amounts, receipt fees,
and flashFeeNotice on BridgeWithdrawal for request and query paths.
Add a 3-step Bruno collection and extend existing withdrawal requests
with fee field assertions and local env defaults.
- replay.spec.ts: spread jest.requireActual('@config') so getFeesConfig
  survives the partial @config mock
- index.spec.ts: mock updateWithdrawalFeeEstimates in the dedup test so
  stale clearAllMocks() impl doesn't bleed in from a prior test
- return-shapes.spec.ts: toEqual → toMatchObject for getWithdrawals shape
  check, now that presentBridgeWithdrawal emits fee fields
- client-usd-wallet.spec.ts: spread jest.requireActual('ibex-client') so
  IbexUrls survives the partial ibex-client mock

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep this file in the commit history?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all the Bruno files so the PR has less noise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should never check in an API key, not even a sandbox one. Remove this and purge it from commit history

Comment thread src/config/schema.ts
bridgeFixedFeePercent: { type: "number", default: 0.6 },
usdtTransferGasLimit: { type: "integer", default: 65000 },
gasPriceBufferMultiplier: { type: "number", default: 1.5 },
ethereumGasRpcUrl: { type: "string", default: "https://cloudflare-eth.com" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on only one URL for gas fees is a bottleneck. At a minimum we should be getting multiple sources and using an average, or getting the gas fee estimate from Bridge directly

amount,
gasMarket,
config = getWithdrawalFeeEstimateConfig(),
developerFeePercent = BridgeConfig.developerFeePercent ?? 2,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this still be here? his a hardcoded default of 2 the right answer?

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.

2 participants