optimal-sizing (Python)
A chain-agnostic mathematical library for profit-maximizing AMM trade sizing across heterogeneous liquidity curves.
optimal-sizing computes exact profit-maximizing trade sizes for constant-product (Uniswap v2), StableSwap (Curve v1), concentrated liquidity (Uniswap v3), Balancer, Velodrome/Aerodrome, Discretized Liquidity Book (DLMM), Curve CryptoSwap v2, and DODO PMM pools with explicit mathematical guarantee tiers.
Installation
pip install optimal-sizing
Quickstart
from decimal import Decimal
from sizing_py import PyCpmm, PyVelodromeStable, portfolio_optimize
# 1. Single pool sizing
cpmm = PyCpmm(Decimal("1000000"), Decimal("1000000"), Decimal("0.997"))
res = cpmm.optimal_size(reference_price=Decimal("0.95"), fixed_cost=Decimal("10"))
print(f"Optimal delta: {res.optimal_delta}, Expected profit: {res.expected_profit} ({res.guarantee_tier})")
# 2. Multi-pool joint portfolio allocation under hard budget constraint
velo = PyVelodromeStable(Decimal("2000000"), Decimal("2000000"), Decimal("0.9995"))
portfolio = portfolio_optimize(
total_capital_budget=Decimal("50000"),
opportunities=[
{"id": "uniswap_v2", "pool": cpmm, "reference_price": Decimal("0.95")},
{"id": "aerodrome", "pool": velo, "reference_price": Decimal("0.95")},
],
)
print(f"Total capital used: {portfolio.total_capital_used}, Profit: {portfolio.total_expected_profit}")
for pos in portfolio.allocations:
print(f" - {pos.id}: allocated {pos.allocated_size}, profit {pos.expected_profit}")
Supported Curve Families
| Curve Family | Protocols | Solver Strategy | Guarantee Tier |
|---|---|---|---|
Constant-Product (x*y=k) |
Uniswap v2, SushiSwap | Closed-form analytical root | ProvenOptimal |
| StableSwap | Curve v1, Ellipsis | Newton-Raphson + Golden-Section | NumericallyGuaranteed |
| Concentrated Liquidity | Uniswap v3 / v4 | Virtual reserve analytical mapping | ProvenOptimal |
Velodrome Stable (x³y + xy³ = k) |
Velodrome, Aerodrome | Normalized Newton-Raphson | NumericallyGuaranteed |
| Discretized Liquidity Book | Trader Joe, Meteora | Stepwise bin aggregation | ProvenOptimal |
| Curve CryptoSwap | Curve v2 | Dynamic invariant root-solver | NumericallyGuaranteed |
| Balancer Weighted Pool | Balancer v1 / v2 | Generalized invariant solver | NumericallyGuaranteed |
| Proactive Market Maker | WooFi v2, DODO | Golden-Section + Unimodality check | EmpiricallyValidated |
| Multi-Pool Portfolio | Cross-protocol | Dual water-filling Lagrange bisection | Budget-feasible |
License
Released under the MIT License. Copyright (c) 2026 Christley OLUBELA (Xtley001).
Metadata
Release files for optimal-sizing 2.0.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 | |
|---|---|---|---|
| optimal_sizing-2.0.0.tar.gz | 62.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| optimal_sizing-2.0.0-cp314-cp314-win_amd64.whl | CPython 3.14 | CPython 3.14 | Windows x86-64 | Details |
Total release size: 418.3 kB
Release files / optimal_sizing-2.0.0.tar.gz
| Download URL | optimal_sizing-2.0.0.tar.gz |
|---|---|
| Size | 62.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e6ed7a5c80dd3fe4a39a883baab857201f668c88cd4ffa7599198950ab3679d
|
|
BLAKE2b-256 checksum How to use checksums |
d6c323d9bfa24dcfde0cb302dc8757c1d937773cb252a8b906ea0ed0b13a71b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / optimal_sizing-2.0.0-cp314-cp314-win_amd64.whl
| Download URL | optimal_sizing-2.0.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 355.6 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
4d75d8751c9d460a04ffb52e1f6975581c67def546a39d86ac4539f33c0e94b2
|
|
BLAKE2b-256 checksum How to use checksums |
7454333a5196ec128a6a407b4d95abd6d48ae609c8acf775e2760bf4d2c68d3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|