No project description provided
Project description
bitcoin-utxo-lp
A Bitcoin UTXO coin-selection engine built around Linear Programming (LP) and Mixed-Integer Linear Programming (MILP) models.
This library focuses on optimal, explainable, and testable UTXO selection under realistic Bitcoin constraints: fees, dust, change outputs, and input sizes.
Table of Contents
- Features
- Installation
- Quick Example
- Core Concepts
- Optimisation Models
- Solution Object
- Testing Philosophy
- Type Checking
- Safety & Correctness
- License
✨ Features
-
🔢 LP & MILP coin selection models
-
⚖️ Optimises for:
- minimal fee cost
- minimal excess change
- minimal number of inputs
-
📏 Precise fee modelling using vbytes
-
🔄 Deterministic and reproducible solutions
-
🧪 Designed for property-based and scenario testing
-
🧩 Extensible objective functions and constraints
📦 Installation
Using Poetry (recommended):
poetry add bitcoin-utxo-lp
Or for development:
git clone https://github.com/<your-org>/bitcoin-utxo-lp.git
cd bitcoin-utxo-lp
poetry install
🚀 Quick Example
from bitcoin_utxo_lp import (
UTXO,
SelectionParams,
SimpleCoinSelectionModel,
SimpleMILPSolver,
)
utxos = [
UTXO(
txid="a" * 64,
vout=0,
value_sats=1_000,
input_vbytes=68.0,
),
]
params = SelectionParams(
target_sats=300,
fee_rate_sat_per_vb=1.0,
min_change_sats=1,
)
model = SimpleCoinSelectionModel(utxos, params)
solver = SimpleMILPSolver()
solution = solver.solve(model)
print(solution.selected_utxos)
print(solution.total_fee_sats)
print(solution.change_sats)
🧠 Core Concepts
UTXO
A spendable output with an associated fee footprint:
UTXO(
txid: str,
vout: int,
value_sats: int,
input_vbytes: float,
)
Fee cost is computed as:
input_vbytes × fee_rate_sat_per_vb
Selection Parameters
SelectionParams(
target_sats: int,
fee_rate_sat_per_vb: float,
min_change_sats: int,
)
These parameters fully define the optimisation problem.
🧮 Optimisation Models
SimpleCoinSelectionModel
Encodes the selection problem as a linear or mixed-integer program:
-
Binary variable per UTXO (
x_i ∈ {0,1}) -
Constraints:
- selected_value − fees ≥ target
- change ≥ min_change
-
Objective:
-
minimise weighted sum of:
- fees
- change
- number of inputs
-
The model is solver-agnostic.
Solvers
SimpleMILPSolver
- Uses integer decision variables
- Guarantees globally optimal solutions
- Suitable for wallets, batching, and backtesting
(An LP-relaxed solver can be added later for heuristics.)
📤 Solution Object
The solver returns a structured result:
solution.selected_utxos
solution.total_input_sats
solution.total_fee_sats
solution.change_sats
solution.is_optimal
This makes it easy to:
- inspect decisions
- debug constraints
- export metrics
🧪 Testing Philosophy
The project is designed for test-first optimisation.
Recommended test categories:
Deterministic Scenarios
- single UTXO exact match
- exact target + fee
- forced change creation
- dust rejection
Edge Cases
- insufficient funds
- fee > UTXO value
- zero-change solutions
- large fee rates
Property-Based Tests
- monotonicity w.r.t fee rate
- solution validity invariants
- no negative change
- no overspending
⚙️ Type Checking
This project is fully typed and designed to work with mypy.
If you see:
Skipping analyzing "pulp": missing library stubs
Recommended fix:
# mypy.ini
[mypy-pulp]
ignore_missing_imports = true
This keeps strict typing everywhere else.
🔐 Safety & Correctness
This library does not construct transactions and does not sign anything.
It only solves the selection problem. Transaction construction, signing, and broadcast must be handled separately.
📜 License
TBD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitcoin_utxo_lp-0.1.0.tar.gz.
File metadata
- Download URL: bitcoin_utxo_lp-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b02fbe11fda3ff2d0506350ba7d920c86fd93cbd01914ea88442535d9c13ef86
|
|
| MD5 |
dd77ea1a28bc92b8e3abae986fe0b9b9
|
|
| BLAKE2b-256 |
b86dad6c7e4290a1b7865940d111a9d77a87d71f92f26f9abf727324c4fb509a
|
Provenance
The following attestation bundles were made for bitcoin_utxo_lp-0.1.0.tar.gz:
Publisher:
publish.yml on AntonioVentilii/bitcoin-utxo-lp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bitcoin_utxo_lp-0.1.0.tar.gz -
Subject digest:
b02fbe11fda3ff2d0506350ba7d920c86fd93cbd01914ea88442535d9c13ef86 - Sigstore transparency entry: 844605671
- Sigstore integration time:
-
Permalink:
AntonioVentilii/bitcoin-utxo-lp@7768134fc2021158fcb073f3464ddc0c26756656 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AntonioVentilii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7768134fc2021158fcb073f3464ddc0c26756656 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bitcoin_utxo_lp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bitcoin_utxo_lp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3f2d071623f8fdb4b0d21452662759ed607625975ffe8722e8396ead2c6ec11
|
|
| MD5 |
acb7c40055a6781e461dbc5b838e77d1
|
|
| BLAKE2b-256 |
19d75160d476eececa29b2fb084d1624950edf3618a0a1259755878f92f8b1b0
|
Provenance
The following attestation bundles were made for bitcoin_utxo_lp-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on AntonioVentilii/bitcoin-utxo-lp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bitcoin_utxo_lp-0.1.0-py3-none-any.whl -
Subject digest:
f3f2d071623f8fdb4b0d21452662759ed607625975ffe8722e8396ead2c6ec11 - Sigstore transparency entry: 844605672
- Sigstore integration time:
-
Permalink:
AntonioVentilii/bitcoin-utxo-lp@7768134fc2021158fcb073f3464ddc0c26756656 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AntonioVentilii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7768134fc2021158fcb073f3464ddc0c26756656 -
Trigger Event:
push
-
Statement type: