feat: implement estimateFee method for stream operations - #397
Conversation
|
@GazzyLee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Jaydbrown
left a comment
There was a problem hiding this comment.
Cannot merge this — the branch was forked from a very old snapshot of src/streams.ts (568 lines) and its diff deletes essentially the entire current StreamsModule implementation down to 397 lines: create(), withdraw(), cancel(), pause()/resume(), topUp(), clawback(), list(), get(), the wallet-adapter integration, the v1-deprecation-warning system, etc. all disappear, and src/tests/streams.test.ts / src/tests/streams-success.test.ts are correspondingly gutted to match. If this were merged as-is it would be a massive regression, not an addition.
The actual new capability — estimateFee(operation) — is a good idea, but please rebase onto the current main (which has moved on substantially) and add it as a new method alongside the existing ones, rather than replacing the whole file. A few things to also tighten up once rebased:
- The simulation-result parsing leans on
as anyguessing at property names (txDataAny.resourceFee,txDataAny.ext?.v1?.resourceFee,anyStats.lastLedgerBaseFee/anyStats.baseFee) rather than the SDK's actual typed shapes — worth pinning down the realSorobanRpc.Api.SimulateTransactionResponse/GetFeeStatsResponsefields instead of trying several optional-chained guesses at runtime. cpuInstructionsis hardcoded to0with a comment saying "if not available" — it looks like it's never actually being read from the simulation result, so the returnedFeeEstimate.cpuInstructionsfield would silently always be0, which is misleading, not just "unavailable."
Happy to review again once it's a real rebase on top of current main rather than a diff against this old base.
d68fd80 to
12688c8
Compare
Rebased onto current main -- the original branch predated the retry/cache Proxy work (conduit-protocol#392, conduit-protocol#417) and would have deleted the entire current StreamsModule (~170 lines: create/withdraw/cancel/pause/resume/topUp/ clawback) if merged as-is. Re-applied just the genuine addition (estimateFee + the StreamOperation/FeeEstimate types) on top of current main, using this._server() (the cached/proxied RPC server) and this._getSenderAddress()/this.config.factoryAddress to match the module's current conventions rather than the original snapshot's.
12688c8 to
a8f1d72
Compare
Summary
Implements the
estimateFeemethod for theStreamsModuleto allow users to estimate network fees before executing stream operations. This addresses the requirement to show estimated network fees to users before they click "Create Stream" in the UI.Changes
Added Types (
types/index.ts)StreamOperation- Union type defining all stream operation types:create- Create a new streamwithdraw- Withdraw from a streamcancel- Cancel a streampause- Pause a streamresume- Resume a paused streamtopUp- Add funds to a streamclawback- Clawback funds from a streamFeeEstimate- Interface for fee estimation results:totalFee- Total estimated fee in stroopsresourceFee- CPU/RAM resource fee component in stroopsbaseFee- Network inclusion fee component in stroopsinstructions- Estimated CPU instructionsImplemented
StreamsModule(streams.ts)estimateFee(operation: StreamOperation)- Main feature that:server.simulateTransaction)server.getFeeStats)FeeEstimateobject with detailed fee breakdownTransaction building methods for each operation type:
buildCreateTx- For creating new streamsbuildWithdrawTx- For withdrawing from streamsbuildCancelTx- For canceling streamsbuildPauseTx- For pausing streamsbuildResumeTx- For resuming streamsbuildTopUpTx- For topping up streamsbuildClawbackTx- For clawback operationsHelper methods:
getStreamAddress- Looks up stream address from stream ID via factory contractbuildCreateArgs- Converts create operation parameters to ScVal argumentsbuildWithdrawArgs- Converts withdraw operation parameters to ScVal argumentsStub methods for existing test compatibility (
create,withdraw,cancel, etc.) - These maintain the API surface for existing tests.Added Tests (
estimate-fee.test.ts)Unit tests covering:
Usage Example