A Pythonic SDK for the f(x) Protocol
Project description
f(x) Protocol Python SDK
Creator: Christopher Stampar (@cstampar)
Date: December 20, 2025
A Pythonic, production-grade SDK for interacting with the f(x) Protocol. This client abstracts Web3.py boilerplate and provides human-readable interfaces for both V1 and V2 products.
โจ Key Features
- Modular Design: Clean separation of read and write operations.
- Precision First: Uses Python
Decimalfor all human-readable amounts. - Full Protocol Coverage: Supports fxUSD, fETH, rUSD, veFXN, Gauges, and all x tokens (xETH, xCVX, xWBTC, xeETH, xezETH, xstETH, xfrxETH).
- Infrastructure-Aware: Direct integration with the Pool Manager, Treasury, and Multi-Path Converter.
- V1 & V2 Support: Robust support for both legacy and current protocol versions.
- Convex Finance Integration: Complete vault management, staking, and rewards for 30+ f(x) Protocol pools.
- Curve Finance Integration: Pool operations, swaps, liquidity management, and gauge staking.
๐ Quick Start
Read-Only Mode (No Private Key Required)
from fx_sdk.client import ProtocolClient
# Initialize in read-only mode
client = ProtocolClient(
rpc_url="https://mainnet.infura.io/v3/YOUR_API_KEY"
)
# Read balance
fxusd_balance = client.get_fxusd_balance()
print(f"fxUSD Balance: {fxusd_balance}")
# Fetch protocol NAV
nav = client.get_treasury_nav()
print(f"Base NAV: {nav['base_nav']}")
Write Mode (Secure Authentication Options)
The SDK supports multiple secure methods for wallet authentication. Never hardcode private keys in your scripts!
Option 1: Environment Variable (Recommended for Production)
# Set in your shell or deployment environment
export FX_PROTOCOL_PRIVATE_KEY="0x..."
from fx_sdk.client import ProtocolClient
client = ProtocolClient(
rpc_url="https://mainnet.infura.io/v3/YOUR_API_KEY"
# Private key automatically loaded from FX_PROTOCOL_PRIVATE_KEY
)
Option 2: .env File (Recommended for Local Development)
Create a .env file in your project root:
FX_PROTOCOL_PRIVATE_KEY=0x...
from fx_sdk.client import ProtocolClient
client = ProtocolClient(
rpc_url="https://mainnet.infura.io/v3/YOUR_API_KEY"
# Private key automatically loaded from .env file
)
Important: Add .env to your .gitignore to prevent committing secrets!
Option 3: Google Colab Secrets
from fx_sdk.client import ProtocolClient
# Store your private key in Colab secrets: 'fx_protocol_private_key'
client = ProtocolClient(
rpc_url="https://mainnet.infura.io/v3/YOUR_API_KEY"
# Private key automatically loaded from Colab secrets
)
Option 4: Browser Wallet (MetaMask, etc.)
from fx_sdk.client import ProtocolClient
client = ProtocolClient(
rpc_url="https://mainnet.infura.io/v3/YOUR_API_KEY",
use_browser_wallet=True # Connects to MetaMask or other browser extension
)
# Transactions will prompt user approval in browser
tx_hash = client.mint_f_token(market_address="0x...", base_in=1.0)
Option 5: Explicit Private Key (Not Recommended)
# โ ๏ธ Only use for testing! Never commit this to version control.
client = ProtocolClient(
rpc_url="https://mainnet.infura.io/v3/YOUR_API_KEY",
private_key="0x..." # Explicit parameter (lowest priority)
)
Authentication Priority Order
The SDK checks for credentials in this order:
- Explicit
private_keyparameter FX_PROTOCOL_PRIVATE_KEYenvironment variable.envfile (FX_PROTOCOL_PRIVATE_KEY)- Google Colab secret (
fx_protocol_private_key) - Browser wallet (if
use_browser_wallet=True)
๐ Project Structure
fx_api/
โโโ fx_sdk/ # Core SDK package
โ โโโ __init__.py
โ โโโ client.py # Main ProtocolClient class
โ โโโ constants.py # Contract addresses and configurations
โ โโโ utils.py # Unit conversion utilities
โ โโโ exceptions.py # Custom exception classes
โ โโโ abis/ # Contract ABIs (JSON files)
โโโ tests/ # Test suite
โ โโโ __init__.py
โ โโโ tests.py # Main unit tests
โ โโโ test_sdk.py # SDK integration tests
โ โโโ ... # Additional test files
โโโ docs/ # Documentation
โ โโโ features.md # Detailed feature list
โ โโโ roadmap.md # Development roadmap
โ โโโ ... # Additional documentation
โโโ scripts/ # Utility scripts
โ โโโ upload_pypi.sh # PyPI upload helper
โโโ README.md # This file
โโโ setup.py # Package setup
โโโ pyproject.toml # Modern Python project config
โโโ requirements.txt # Python dependencies
โโโ LICENSE # MIT License
For detailed SDK capabilities, see docs/features.md.
๐ Project Status & Progress
The SDK is currently in a feature-complete state for initial release.
Done:
- Scaffolding & Core Architecture
- Data Normalization (Wei <-> Decimal)
- Contract Registry (V1 & V2)
- Governance & veFXN support
- Gauge & Reward claiming
- V2 Pool Manager (Operate, Liquidate, Rebalance)
- V1 Treasury & Market support
- Multi-Path Converter & stETH Gateway
- Rebalance Pool (Stability Pool) support
- Integrated ABIs for all core components
- Convex Finance Integration (v0.2.0): Vault management, staking, APY calculations, 30+ pools
- Curve Finance Integration (v0.2.0): Swaps, liquidity, gauge staking, pool discovery
๐ Security Best Practices
- Never commit private keys to version control. Always use
.gitignoreto exclude.envfiles. - Use environment variables in production deployments (AWS, Heroku, etc.).
- Use
.envfiles for local development, but never commit them. - Use Colab secrets when working in Google Colab notebooks.
- Use browser wallets for interactive applications where users control their own keys.
- Read-only mode is available for analytics and monitoring without any credentials.
๐ Documentation
For a full list of features and supported products, see docs/features.md.
โ๏ธ License
MIT
Project details
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 fx_sdk-0.4.0.tar.gz.
File metadata
- Download URL: fx_sdk-0.4.0.tar.gz
- Upload date:
- Size: 92.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf6d555fa6744698882f0438e6aebac46f8345f0f1baffb354f0e8ed8296642f
|
|
| MD5 |
3be401165ed7f03c2e90aa84d716719f
|
|
| BLAKE2b-256 |
74ea1d82338c869b56c0221be2b658386d18ccd400d321690190ec6be0b0b851
|
File details
Details for the file fx_sdk-0.4.0-py3-none-any.whl.
File metadata
- Download URL: fx_sdk-0.4.0-py3-none-any.whl
- Upload date:
- Size: 95.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50c85014fb37b34aee47951edfda8f41268c5ce0a714d1362093feba391ac0e4
|
|
| MD5 |
bf04a07a7985a170752a1e377b0fc82e
|
|
| BLAKE2b-256 |
c00f09bc4e179166a6d6d5dda8d7e5a7072a7e8c42a01eae41d061c20db54601
|