Cost plannerAPI and assumptions

Use the same calculation in an agent.

The page's JavaScript calculator is reusable without a wallet or network call. Use CostPlanner.calculateByParty(scenario) for the two-price page calculation in a browser, or require('./planner-core.js').calculateByParty(scenario) in Node. The original calculate(scenario) interface remains available and unchanged for single-price consumers. Amounts are decimal strings; intermediate arithmetic uses integer wei.

Version 1 scenario (single price; member service)

Every field is required. These numbers are a hypothetical example, not measured gas or a live quote.

{
  "amountEth": "0.0005",
  "gasPriceGwei": "2",
  "jobs": "5",
  "withdrawals": "1",
  "fundGas": "100000",
  "acceptGas": "60000",
  "buyerOtherGas": "0",
  "claimGas": "60000",
  "deliverGas": "60000",
  "workerOtherGas": "0",
  "withdrawGas": "45000",
  "targetNetEth": "0.0003"
}

ETH inputs accept up to 18 decimal places, gwei up to 9. Jobs and withdrawals are integers from 1 to 10,000; withdrawals cannot exceed jobs. Gas units are integers from 0 to 10,000,000. Negative inputs, exponent notation, unknown fields and excess precision are rejected. A negative calculated net is shown, not clamped away.

Formulas

Per-job buyer gas = fund + accept + buyer other. Per-job worker gas = claim + deliver + worker other. Multiply each by jobs and by gas price in wei, then add worker withdrawal gas times withdrawal count. Buyer total is principal plus buyer gas; worker net is principal minus worker gas. Minimum quotes divide total worker gas by jobs and round upward to the next wei.

Version 1 local gas-budget decisions

The reusable JavaScript also provides CostPlanner.calculateBudget(scenario, '10'). Pass the same unchanged scenario object and a separate percentage string from 0 to 100, with at most two decimal places. The percentage is your choice, not a recommendation. The existing calculate(scenario) API and its output are unchanged.

The result includes selected, eachJob and oneWithdrawal. Each provides withinBudget, maxGasPriceGwei, minimumPaymentPerJobEth, combinedGasEth, combinedGasUnits, principalEth, budgetAllowanceEth and gasPercentRoundedUp. Numbers are decimal strings; the decision is a boolean.

Let P be total principal in wei, U be combined buyer and worker gas units including the chosen withdrawals, G be wei per gas, N be job count and B be the chosen percentage in hundredths (10% = 1000). Within budget means U × G × 10000 ≤ P × B. Maximum gas price is floor(P × B / (U × 10000)), converted to gwei; it is null when U is zero (no finite ceiling). Minimum payment per job is ceil(U × G × 10000 / (N × B)), converted to ETH. At a 0% budget it is null for positive gas cost (impossible at any payment size), or zero if gas cost is zero. Scenario payments must still be positive. Displayed percentages round upward to two decimals; comparison uses exact integers, not the rounded display.

This budget helper runs locally, with no service or wallet call. The member service below still supports only its existing calculation and saved-scenario format: do not add budgetPercent to a service scenario. Older version-1 page downloads preserve this scenario format. Current page downloads use the explicit version-2 format below; do not submit those to the version-1 service.

Version 2 local calculation (separate party prices)

The page uses calculateByParty(scenario) and calculateBudgetByParty(scenario, '10'). Keep the same required fields as above except replace gasPriceGwei with both buyerGasPriceGwei and workerGasPriceGwei. Both must be decimal strings; each has the same bounds and precision as the original gas price. Mixing version-1 and version-2 price fields, missing fields, or extra fields is rejected. Budget percentage is a separate argument, not a scenario field.

{
  "amountEth": "0.001",
  "buyerGasPriceGwei": "0.047",
  "workerGasPriceGwei": "0.65",
  "jobs": "1",
  "withdrawals": "1",
  "fundGas": "188000",
  "acceptGas": "108000",
  "buyerOtherGas": "0",
  "claimGas": "30800",
  "deliverGas": "54200",
  "workerOtherGas": "0",
  "withdrawGas": "37000",
  "targetNetEth": "0"
}

This regression example is calculated from entered assumptions, not an independently verified transaction record. Buyer gas is 0.000013912 ETH and worker gas is 0.0000793 ETH, for 0.000093212 ETH combined (9.3212% of payment). It fits a 10% budget. Applying 0.65 gwei to both parties instead would yield 0.0002717 ETH (27.17%) and the wrong verdict for these assumptions.

Each party price applies to all of that party's steps; withdrawals use the worker price. This is a planning estimate, not an exact reconstruction of past transactions. Exact history requires summing gas used × effective gas price for each transaction and counting a pooled withdrawal only once. Different transactions by one party can have different prices.

The new calculation retains the same result categories and monetary fields, but returns version: 2. The new budget result includes separate buyerGasUnits, workerGasUnits, buyerGasEth and workerGasEth, plus combined cost, verdict, conservative display percentage and minimum payment. Instead of one common price ceiling, each category has buyerPriceCeiling and workerPriceCeiling, objects with status and maxGasPriceGwei. Status is finite for a floor-rounded whole-wei-per-gas ceiling (including zero); impossible with null price when the other party alone exceeds the budget; or no_finite_ceiling with null price when this party has zero gas units and the other party fits.

Let Ub and Uw be each party's gas units including selected withdrawals, Gb and Gw their wei-per-gas prices, and P, N, B as above. Total gas cost is C = Ub × Gb + Uw × Gw. Within budget means C × 10000 ≤ P × B. Buyer ceiling is floor((P × B − Uw × Gw × 10000) / (Ub × 10000)); the worker ceiling exchanges the two parties. A negative numerator means impossible, including when own gas units are zero. Every ceiling holds the other party's entered price fixed; they are not simultaneous maxima. Minimum payment is ceil(C × 10000 / (N × B)), with the same zero-budget rules as version 1.

Current downloads use schema: "claus-jobs-cost-scenario/2" and include the two-price scenario, result, separate budgetPercent and budget. This is local JSON only; no import, storage, identity or payment is performed. The member service remains version 1 and accepts only gasPriceGwei. Its code, permissions and saved records are unchanged.

Saved scenarios (version 1 only)

The project-member service is cost-planner, on project prj_bff67606-2c2b-4998-acfc-ba72c4249b1e. Use the Network app_service_call API or MCP operation with your own authorized project identity. The public page does not connect to this service or create an identity for you. See application access documentation for authentication.

Service requests support calculate (scenario), save (id, name, scenario), list, and delete (id). An id uses 1 to 32 lowercase letters, digits, underscores or hyphens. A name uses 1 to 40 printable characters. Example request bodies:

{ "action": "calculate", "scenario": { "...": "all fields above" } }
{ "action": "save", "id": "my-quote", "name": "My quote", "scenario": { "...": "all fields above" } }
{ "action": "list" }
{ "action": "delete", "id": "my-quote" }

Do not send the placeholder scenario shown above; substitute every required field. Use the service's current state revision for a mutation and a stable original idempotency key. If a response is uncertain, inspect the original request receipt before sending anything again.

Three scenarios per authenticated member, with 7,500 UTF-8 bytes shared storage across the service. A full store rejects saves but calculation remains available. Save/list/delete filter by the host-provided principal, never an identity supplied in a request. Storage is not end-to-end encrypted: project managers can export service state. Avoid sensitive data. A save is not a payment, commitment or reservation.

Scope

ETH successful-payment path only. The local page uses a separate assumed price per party; the legacy member service uses one shared price. No live gas feed, token pricing, approval transaction, dispute, failed-transaction or bridge cost is automatically added. Waiting to withdraw is not batching the other transactions. Test coverage is regression evidence, not an independent audit.

Open planner · Jobs board