Chainpyon
A Python library for interacting with blockchain smart contracts, with specialized support for Premia's clearing house system.
Overview
Chainpyon provides a high-level interface for blockchain interaction, offering:
- Easy interaction with ERC20 tokens and smart contracts
- Specialized support for Premia's clearing house operations
- Built-in support for multiple chains (Arbitrum, Arbitrum Sepolia)
- Web3 integration with type safety
- Local development support through Anvil
Core Components
Chain Management
Chain
: Base class for interacting with a specific blockchainMultiChain
: Class for managing interactions across multiple chains- Built-in support for chain IDs, explorers, and network configurations
Contract Interfaces
ERC20
: Interface for basic ERC20 token operationsClearingHouse
: Specialized interface for Premia's clearing house contract- Support for advanced operations like deposits, withdrawals, and trade settlements
Development Tools
Anvil
: Tooling for local blockchain development and testing- Support for account impersonation, chain manipulation, and state management
Usage Examples
Basic Chain Setup
from chainpyon import Chain, ChainId
# Initialize chain connection
chain = Chain(
chain_id=ChainId.ARBITRUM,
rpc_url="YOUR_RPC_URL",
account="YOUR_ACCOUNT_ADDRESS",
private_key="YOUR_PRIVATE_KEY"
)
ERC20 Token Operations
# Get ERC20 contract interface
token = chain.erc20("USDC")
# Basic token operations
balance = await token.balance_of(account)
await token.approve(spender, amount)
await token.transfer(recipient, amount)
Clearing House Operations
# Access clearing house contract
clearing_house = chain.premia.clearing_house
# Perform operations
equity = await clearing_house.get_equity(account, pair)
position = await clearing_house.get_position(account, instrument_name)
Development
Local Testing with Anvil
from chainpyon.anvil import AnvilInstance
# Start local node
anvil = AnvilInstance(
port=8545,
fork_url="YOUR_FORK_URL"
)
# Test your contracts
...
Installation
Dependencies
- web3.py
- eth-abi
- eth-account
- pydantic
- async-lru
License
[License Type]
This documentation is generated from the service README. For the most up-to-date information, refer to the original README