bush-maths
Exact fixed-point reference maths for Bush Protocol pools, in Python (int). Given a pool's on-chain state, it
returns the same amounts the Bush Vault would — to the wei — for swaps, adds and removes.
Every pool type here is verified bit-for-bit against a pool deployed through its factory on a local chain (see maths/check); the same maths ships for TypeScript and Rust.
Install
pip install bush-maths
Usage
from bush_maths import Vault, SwapInput, SwapKind
from bush_maths.common.base_pool_state import pool_state_from_json
vault = Vault()
# The pool's state, in the same shape as the `pool` block of a testData/ file (numbers as int).
pool_state = pool_state_from_json(pool)
# Raw token amounts in, raw token amounts out — exactly what the Router returns.
amount_out = vault.swap(
swap_input=SwapInput(
amount_raw=1_000_000,
swap_kind=SwapKind.GIVENIN,
token_in=token_in,
token_out=token_out,
),
pool_state=pool_state,
)
vault.add_liquidity(...) and vault.remove_liquidity(...) work the same way. The Vault reproduces the whole
on-chain flow — token scaling, rates, swap fees, hooks — on top of the pool maths.
How to read each pool type's state from the chain is described in the
TypeScript package's README;
the fields are the same, in snake_case. The
testData/ files show the exact
shape for every pool type.
ERC4626 buffers
Wrapping or unwrapping through a Vault buffer is priced by the wrapper's rate alone. Pass a BufferState
(pool_address is the wrapped token, rate its scaled-18 rate) to vault.swap:
from bush_maths import BufferState
buffer = BufferState(pool_address=wrapped, tokens=[wrapped, underlying], rate=rate)
Pool types
pool_type |
Factory |
|---|---|
WEIGHTED, WEIGHTED_8020, COW |
WeightedPoolFactory, WeightedPool8020Factory, CowPoolFactory |
STABLE (+ StableSurge hook) |
StablePoolFactory, StableSurgePoolFactory |
LIQUIDITY_BOOTSTRAPPING |
LBPoolFactory |
FIXED_PRICE_LBP |
FixedPriceLBPoolFactory |
RECLAMM |
ReClammPoolFactory |
Derived from balancer-maths (MIT).
Metadata
Release files for bush-maths 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bush_maths-0.1.0.tar.gz | 39.6 kB | Without provenance | Details for bush_maths-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bush_maths-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for bush_maths-0.1.0-py3-none-any.whl |
Total release size: 94.3 kB
Release files / bush_maths-0.1.0.tar.gz
| Download URL | bush_maths-0.1.0.tar.gz |
|---|---|
| Size | 39.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04f05682063cd7a414b370a3c3e2d851f87df6c79c6af51dba11e94831fd5558
|
|
BLAKE2b-256 checksum How to use checksums |
16d7811afb2123f47c295de0323677c098e48d28b1201fcde6876bc1ffa17b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Release files / bush_maths-0.1.0-py3-none-any.whl
| Download URL | bush_maths-0.1.0-py3-none-any.whl |
|---|---|
| Size | 54.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f037f473e4dfbf44b5e12f887f850296889907f0cf2b5accf9bf29d85d695a2a
|
|
BLAKE2b-256 checksum How to use checksums |
307e37ea2e70d229b8dedbf3f1ecbac104e7cbcf293e9da6ee0623441deee095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Security for bush-maths 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.