Skip to content

feat: add estimateFee() for stream operations - #423

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

feat: add estimateFee() for stream operations#423
GazzyLee wants to merge 1 commit into
conduit-protocol:mainfrom
GazzyLee:drips-pr

Conversation

@GazzyLee

@GazzyLee GazzyLee commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Before a user clicks Create Stream, the UI needs to display the estimated network fee. This PR adds estimateFee(operation: StreamOperation) to StreamsModule, which runs a Soroban simulation and returns an exact fee breakdown based on the transaction's CPU/RAM resource usage and the current base fee.

What's included

  • src/types/index.ts

    • New StreamOperation discriminated union covering all 7 stream operations: create, withdraw, cancel, pause, resume, topUp, clawback
    • New FeeEstimate interface: { totalFee, resourceFee, baseFee, instructions } (all in stroops)
  • src/streams.ts

    • New async estimateFee(operation: StreamOperation): Promise<FeeEstimate> method on StreamsModule
    • Builds the contract-call Transaction for the requested operation using existing helpers (buildContractCallTx, getTokenDecimals, toStroops, calculateRate, _resolveAddr)
    • Simulates the transaction via Soroban RPC and extracts:
      • Resource fee from simResult.minResourceFee (CPU/RAM cost)
      • CPU instructions from simResult.cost.cpuInsns
      • Base fee from the SDK's BASE_FEE constant
    • Handles RPC rate limits via RateLimitError.fromRpcError() and simulation errors via SorobanRpc.Api.isSimulationError() — no as any property guessing

Example

const client = new ConduitClient({ network: 'mainnet', keypair });

const estimate = await client.streams.estimateFee({
  type: 'create',
  token: 'USDC',
  sender: keypair.publicKey(),
  recipient: 'G...',
  depositAmount: '1000',
  durationSeconds: 2592000,
});

console.log(estimate);
// { totalFee: 3149, resourceFee: 3049, baseFee: 100, instructions: 2048576 }

### Validation
tsc --noEmit  passes
npm run lint  passes
All 500 existing tests pass (no test files modified)

# Closes #353

@GazzyLee GazzyLee closed this Aug 1, 2026
@GazzyLee GazzyLee reopened this Aug 1, 2026
@GazzyLee GazzyLee closed this Aug 1, 2026
@GazzyLee GazzyLee reopened this Aug 2, 2026
@GazzyLee GazzyLee closed this Aug 2, 2026
@GazzyLee GazzyLee reopened this Aug 2, 2026
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