Successfully implemented Pi bridge support for wallet activation in the ACBU backend. The system now automatically switches between Pi and Stellar XLM for wallet activation based on configuration.
- Branch Name:
feature/pi-wallet-activation - Commit:
f566377 - Fork URL: https://github.com/coderolisa/acbu-backend.git
- Branch URL: https://github.com/coderolisa/acbu-backend/tree/feature/pi-wallet-activation
Added Pi network configuration with the following environment variables:
pi: {
enabled: boolean, // PI_BRIDGE_ENABLED
secretKey: string, // PI_SECRET_KEY
apiUrl: string, // PI_API_URL
minBalancePi: number, // WALLET_ACTIVATION_PI or PI_MIN_BALANCE
network: "testnet" | "mainnet" // PI_NETWORK
}- Implements Pi blockchain interactions
- Supports creating accounts and transferring Pi
- Includes retry logic and error handling
- Methods:
sendPiToActivate(): Send Pi to activate walletgetTransactionStatus(): Check transaction statusgetBalance(): Get account balanceisEnabled(): Check if Pi bridge is enabled
- Wrapper for Pi activation operations
- Handles Pi-specific activation logic
- Uses the Pi client for transactions
- Exports Pi services and types for easy importing
Key Changes:
- Added new
sendCryptoToActivate()function that automatically selects between Pi and Stellar - Retained
sendXlmToActivate()for backward compatibility - Automatic chain selection:
- If
PI_BRIDGE_ENABLED=true→ Use Pi - Otherwise → Use Stellar XLM (default)
- If
- Updated documentation to mention Pi support
- Updated to use
sendCryptoToActivate()instead ofsendXlmToActivate() - Now supports both Pi and Stellar transparently
- Updated documentation to explain chain selection
- Exported new activation functions for external use
To enable Pi bridge for wallet activation, set these variables in your .env:
# Enable Pi bridge
PI_BRIDGE_ENABLED=true
# Pi Network Configuration
PI_SECRET_KEY=your_pi_secret_key_here
PI_API_URL=https://api.pi.network.com # or testnet URL
PI_NETWORK=testnet # or mainnet
PI_MIN_BALANCE=0.1 # Minimum Pi for activation
WALLET_ACTIVATION_PI=0.1 # Alternative: WALLET_ACTIVATION_PI
# Keep Stellar config for fallback
STELLAR_NETWORK=testnet
STELLAR_HORIZON_URL=https://horizon-testnet.stellar.org
STELLAR_SECRET_KEY=your_stellar_secret_here
WALLET_ACTIVATION_XLM=1 # XLM amount for activation (used as fallback)KYC Fee Paid → Queue WALLET_ACTIVATION message → sendCryptoToActivate() → sendXlmToActivate() → Send 1 XLM to Stellar address
KYC Fee Paid → Queue WALLET_ACTIVATION message → sendCryptoToActivate() → sendPiToActivate() → Send 0.1 Pi to address
- User completes KYC and pays fee
createApplication()in KYC service enqueues wallet activationstartWalletActivationConsumer()processes the queue messagesendCryptoToActivate()is called with the user's address- Chain selection happens:
- If Pi enabled: Uses Pi client to send Pi tokens
- If Pi disabled: Uses Stellar client to send XLM (backward compatible)
- Transaction hash is logged and stored
Both implementations handle:
- Account already exists scenarios
- Transaction failures
- Network errors
- Invalid addresses
- Configuration errors (logged with helpful messages)
-
Test Stellar activation (default):
PI_BRIDGE_ENABLED=false npm run dev # KYC flow should activate wallet with XLM as before -
Test Pi activation:
PI_BRIDGE_ENABLED=true PI_SECRET_KEY=test_key PI_API_URL=https://testnet-api.pi.network.com npm run dev # KYC flow should activate wallet with Pi -
Test fallback behavior:
- Start with Pi enabled but invalid credentials
- Should fail appropriately with clear error messages
src/config/env.ts- Added Pi configurationsrc/services/wallet/walletActivationService.ts- Added multi-chain supportsrc/jobs/walletActivationJob.ts- Updated to use new functionsrc/services/wallet/index.ts- Exported new functions
src/services/pi/client.ts- Pi network clientsrc/services/pi/activationService.ts- Pi activation logicsrc/services/pi/index.ts- Service exports
✅ Fully backward compatible
- Default behavior unchanged (uses Stellar/XLM)
- Pi is opt-in via environment variable
- Existing deployments work without changes
- Can switch between chains by updating environment variable
Your branch is ready! You can create a PR from: https://github.com/coderolisa/acbu-backend/pull/new/feature/pi-wallet-activation
Or use:
git push origin feature/pi-wallet-activationThen visit GitHub to create the PR from feature/pi-wallet-activation to main.
- Add testnet/mainnet network detection to wallet class
- Support user-specific chain preferences
- Add monitoring and alerting for wallet activation failures
- Add API endpoint to check wallet activation status
- Support multiple chains in parallel (activate on both Pi and Stellar)