A demonstration of PYUSD token splitting on Stellar using Soroban smart contracts. This project shows how to automatically distribute PYUSD tokens among multiple recipients based on predefined share ratios.
This project includes two smart contracts:
- SimpleSplitter - Core contract that splits PYUSD tokens proportionally among recipients
- SimpleSplitterFactory - Factory contract for deploying new splitter instances
- Recipients and shares are set at initialization and cannot be changed
- Uses proportional math to minimize computation costs
- Factory pattern enables deployment of multiple splitter instances
- Factory emits events for off-chain tracking
- Proportional distribution based on customizable share ratios
- Factory pattern for easy splitter deployment
- Works with PYUSD on Stellar testnet and mainnet
- Event emission for tracking deployed splitters
- Integer math with remainder staying in contract
| Network | PYUSD Asset | SAC Contract |
|---|---|---|
| Testnet | PYUSD:GBT2KJDKUZYZTQPCSR57VZT5NJHI4H7FOB5LT5FPRWSR7I5B4FS3UU7G |
CACZL3MGXXP3O6ROMB4Q36ROFULRWD6QARPE3AKWPSWMYZVF2474CBXP |
| Mainnet | PYUSD:GDQE7IXJ4HUHV6RQHIUPRJSEZE4DRS5WY577O2FY6YQ5LVWZ7JZTU2V5 |
CAKBVGHJIK2HPP5JPT2UOP27O2IMKIUUCFGP3LOOMGCZLE3NP73Z44H6 |
- Contract ID:
CANG56EMKRP65Y7AIWU6XA4LGUIMLSY7TT4TOYVJMHMGISGYDJF5R56Z - View on Stellar Expert
A user-friendly web interface is available for creating and managing splitters:
π Live Demo (Testnet only)
Features:
- Connect wallet using Stellar Wallets Kit (Freighter, xBull, Albedo, etc.)
- Create new splitters with custom recipients and share ratios
- View splitter details including balance and recipient allocations
- Distribute PYUSD to recipients with one click
- Links to Stellar Expert for detailed contract and account information
.
βββ contracts/
β βββ simple-splitter/ # Core splitter contract
β β βββ src/lib.rs # Main contract logic
β β βββ src/test.rs # Contract tests
β βββ simple-splitter-factory/ # Factory contract
β βββ src/lib.rs # Factory logic
β βββ src/test.rs # Factory tests
βββ frontend/ # Web interface
β βββ src/
β β βββ components/ # React components
β β βββ contexts/ # Wallet context
β β βββ lib/ # Contract utilities
β β βββ config.ts # Network configuration
β βββ package.json
βββ justfile # Deployment commands
βββ README.md
- Rust with
wasm32-unknown-unknowntarget - Stellar CLI - Installation guide
- Just command runner -
cargo install just - A Stellar wallet with XLM for transaction fees and testnet PYUSD
Note: See pyusd-stellar-recipes for instructions on setting up a local wallet, getting testnet XLM, and obtaining testnet PYUSD.
Copy the example environment file and fill in your details:
cp .env.example .env
# Edit .env with your Stellar secret key and network preferencejust buildjust testFirst, upload the SimpleSplitter WASM and get its hash:
just upload-splitterThis returns a WASM hash. Use it to deploy and initialize the factory:
just deploy-factory <wasm_hash>Use the factory to create a new splitter (50/50 split example):
just create-splitter <factory_contract_id> '["GADDRESS1...", "GADDRESS2..."]' '[1, 1]'// Initialize splitter with token, recipients, and shares
pub fn init(env: Env, token: Address, recipients: Vec<Address>, shares: Vec<u32>)
// Distribute current contract balance proportionally
pub fn distribute(env: Env)
// Get current configuration
pub fn get_config(env: Env) -> (Address, Vec<Address>, Vec<u32>)// Initialize factory with SimpleSplitter WASM hash
pub fn init(env: Env, splitter_wasm_hash: BytesN<32>)
// Create new splitter instance
pub fn create(env: Env, token: Address, recipients: Vec<Address>, shares: Vec<u32>) -> AddressTo get testnet PYUSD for testing:
- Get testnet XLM: Use
stellar request-tokensor Stellar Laboratory - Create PYUSD trustline: Add trustline to the PYUSD testnet issuer
- Get testnet PYUSD: Visit Paxos PYUSD Testnet Faucet
- pyusd-stellar-recipes - TypeScript examples for PYUSD on Stellar
- pyusd-arbitrum-splitter - Similar splitter implementation on Arbitrum
cargo fmt
cargo clippy
cargo test
cargo build --releasecd frontend
npm install
npm run dev # Start development server
npm run build # Build for productionThe frontend is built with:
- Vite + React + TypeScript - Modern build tooling and type safety
- Tailwind CSS + ShadCN - Styling and UI components
- @creit.tech/stellar-wallets-kit - Multi-wallet support (Freighter, xBull, Albedo, etc.)
- @stellar/stellar-sdk - Stellar/Soroban contract interactions
- TanStack Query - Async state management
- Wouter - Lightweight routing
- Sonner - Toast notifications
MIT License - see LICENSE file for details.
This project demonstrates PYUSD integration patterns on Stellar. Contributions welcome!