Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/soroban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ export async function queryXlmBalance(
*/
export const DEFAULT_RESOURCE_FEE_ESTIMATE = 1_000_000n;

/**
* Larger fallback used for expensive operations that deploy or instantiate
* contracts (e.g. `create_stream`). This is a conservative default sized in
* stroops (3 XLM) to avoid under-estimating required balance in the
* insufficient-balance error path when the simulation carries no fee fields.
*/
export const CREATE_RESOURCE_FEE_ESTIMATE = 30_000_000n;

/**
* Estimate the minimum resource fee required for a transaction simulation.
*
Expand Down
3 changes: 2 additions & 1 deletion src/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
catchNetworkError,
queryXlmBalance,
estimateRequiredFee,
CREATE_RESOURCE_FEE_ESTIMATE,
DEFAULT_RPC,
NETWORK_PASSPHRASE,
DEFAULT_CONFIRMATION_MAX_ATTEMPTS,
Expand Down Expand Up @@ -258,7 +259,7 @@ export class StreamsModule {
// query the actual XLM balance and estimate the required fee.
if (err instanceof InsufficientBalanceError && err.currentBalance === 0n && err.requiredBalance === 0n) {
const xlmBalance = await queryXlmBalance(this.rpcUrl, this.passphrase, senderAddr).catch(() => 0n);
const requiredFee = estimateRequiredFee(sim);
const requiredFee = estimateRequiredFee(sim, CREATE_RESOURCE_FEE_ESTIMATE);
const required = depositStroops + requiredFee;
throw new InsufficientBalanceError(xlmBalance, required, sim.error);
}
Expand Down