OpenViSTAI · Agents · Blockchain · Crypto
Menu
OPENVIST RECIPES

Calculate effective PumpSwap quote reserves from pool values

Python

Given a PumpSwap pool's quote-vault token amount and signed virtual quote reserves, calculate and display the effective quote reserves used for quoting and pricing.

Python code excerpt: Calculate effective PumpSwap quote reserves from pool values. Version 0.1.1. Read the full recipe for code, sources and recorded test scope.

Pump.fun's official documentation says PumpSwap pricing uses the sum of the quote-token vault amount and the pool's signed `virtual_quote_reserves`, rather than the raw vault balance alone. This small offline example calculates that value from two supplied integers; it does not fetch pool data or connect to a service.

Before you start

  • Python 3.12 is the independently tested runtime (CPython 3.12.15); standard library only. The code uses f-strings. Older Python versions have not been tested for this Recipe.
  • Input: a non-negative quote-vault integer and a signed virtual-reserve integer, both in the same smallest-unit denomination. No endpoint, network, credentials, SDK, or API version is needed.
  • The official PumpSwap documentation specifies the formula and says the virtual reserve field is signed i128; it guarantees the sum will not overflow or be negative for valid pool data.

Build and check

  1. Supply the quote-vault amount and signed virtual quote reserves as the two CLI arguments; both must use the same token denomination.
  2. Run python3 recipe.py 1000000 -125000; expect Effective quote reserves: 875000. Invalid arguments or negative amounts/results exit 2.
  3. Read the printed effective reserve total. The negative virtual reserve in the sample demonstrates why adding a signed value matters.
  4. Use the total as effective quote reserves if implementing a separate quote calculation; this example does not calculate a trade price or execute a trade.

Limits to understand

  • The supplied source excerpt establishes the PumpSwap formula but does not establish an API endpoint, account-fetching method, or particular SDK. Accordingly the example accepts manually supplied values and makes no claims about retrieving live pool state.
  • The example does not establish pool authenticity or validate that numbers were decoded from the correct on-chain fields; obtain and decode pool data using separately verified documentation before relying on a result.
  • No HTTP call is made, so timeout, API credential, and remote failure handling are not applicable. Input type and non-negative-result failures are handled explicitly; there are no retries.
  • Provenance: recorded as an original, AI-assisted OpenViST example with an MIT declaration for this example only. Pump.fun documentation supports the formula and field semantics, not the authorship or license of this example. This is not an official Pump.fun SDK.
  • Six synthetic CLI cases were independently executed. Boolean function arguments, missing/extra CLI arguments and fixed-width overflow boundaries are not fixture-verified. Python integers do not enforce signed i128 limits.

Run it

Save as recipe.py. Run python3 recipe.py 1000000 -125000. Both arguments must be integers in the same smallest-unit denomination. Local calculation only; no network or transactions.
INSPECT THE SCRIPT

Inspect, copy and run the documented checks.

This browser preview builds code locally. It does not contact an API or run the code.

Default example ready.

Python example
# SPDX-License-Identifier: MIT
# Copyright (c) 2026 OpenViST contributors
def effective_quote_reserves(vault_amount: int, virtual_reserves: int) -> int:
    if isinstance(vault_amount, bool) or not isinstance(vault_amount, int):
        raise TypeError("vault_amount must be an integer")
    if isinstance(virtual_reserves, bool) or not isinstance(virtual_reserves, int):
        raise TypeError("virtual_reserves must be an integer")
    if vault_amount < 0:
        raise ValueError("vault_amount must be non-negative")

    effective = vault_amount + virtual_reserves
    if effective < 0:
        raise ValueError("effective reserves cannot be negative")
    return effective


if __name__ == "__main__":
    import argparse
    import sys
    parser = argparse.ArgumentParser(description="Calculate effective quote reserves from local integer values.")
    parser.add_argument("vault_amount", type=int)
    parser.add_argument("virtual_reserves", type=int)
    args = parser.parse_args()
    try:
        result = effective_quote_reserves(args.vault_amount, args.virtual_reserves)
    except (TypeError, ValueError) as exc:
        print(f"Invalid pool values: {exc}", file=sys.stderr)
        raise SystemExit(2)
    print(f"Effective quote reserves: {result}")
What to verify after running
  • Run with 1000000 -125000: expect Effective quote reserves: 875000 and exit 0.
  • Run with 10 0 and 10 -10: expect 10 and 0, respectively.
  • Run with 10 -11 and -1 0: expect exit 2 and Invalid pool values on stderr.
  • Run with abc 0 or True 0: expect argparse exit 2. Missing or extra arguments must also fail.

Request or format preview

Illustrative preview. No provider response, price or balance is fetched.

Change a setting to inspect the preview.

Official sources and related profiles

    Code license: MIT. Keep the license notice with your copy.

    Example version 0.1.1 · Documentation reviewed 2026-10-12.

    Executed 6 synthetic local fixture cases in isolated CPython 3.12.15 on GitHub Actions, without network access. Declared exit codes, output assertions and input integrity checks passed. Live services, installed third-party packages and production behavior remain outside scope. Editorial approval is still required.