Skip to content

feat: implement estimateFee method for stream operations - #421

Open
GazzyLee wants to merge 1 commit into
conduit-protocol:mainfrom
GazzyLee:drips-pr
Open

feat: implement estimateFee method for stream operations#421
GazzyLee wants to merge 1 commit into
conduit-protocol:mainfrom
GazzyLee:drips-pr

Conversation

@GazzyLee

Copy link
Copy Markdown
Contributor

Description

Before a user clicks 'Create Stream', the UI should show them the estimated network fee. This PR exposes estimateFee(operation: StreamOperation) on StreamsModule.

Changes

  • src/types/index.ts: Added StreamOperation discriminated union (7 variants: create, withdraw, cancel, pause, resume, topUp, clawback) and FeeEstimate interface
  • src/streams.ts: Added estimateFee(operation) method that builds the contract-call transaction, simulates it via Soroban RPC, and extracts the resource fee (minResourceFee), CPU instructions (cost.cpuInsns), and base fee (BASE_FEE) into a typed FeeEstimate response

Implementation

  • Uses the existing _resolveCallerAddress(), _server(), buildContractCallTx(), getTokenDecimals(), and _resolveAddr() helpers
  • Wraps simulation errors with RateLimitError.fromRpcError() for 429 handling
  • Validates simulation result through SorobanRpc.Api.isSimulationError() — no as any property guessing
  • Returns { totalFee, resourceFee, baseFee, instructions } in stroops

Testing

  • tsc --noEmit: clean
  • All existing tests pass (no test modifications)

Closes #353

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.

Feature: Implement estimateFee method

1 participant