libertyswap-sdk
v1.2.0
Published
TypeScript SDK for LibertySwap — Bridge USDC between PulseChain and Base
Maintainers
Readme
LibertySwap TypeScript SDK
Universal bridge widget and SDK for bridging USDC from PulseChain to Base
🚀 Features
- ✅ Universal Wallet Support - Works with Privy, Rainbow Kit, WalletConnect, MetaMask, etc.
- ✅ Drop-in React Widget - Beautiful pre-built UI component
- ✅ White-Label Ready - Customize branding, colors, fees
- ✅ Affiliate Tracking - Built-in revenue sharing
- ✅ TypeScript First - Full type safety
- ✅ Production Ready - Battle-tested on mainnet
📦 Installation
npm install ethers @privy-io/react-auth
# or
yarn add ethers @privy-io/react-authCopy the SDK files to your project:
src/libertySwap.tssrc/UniversalBridgeWidget.tsxsrc/types.tssrc/config.ts
🎯 Quick Start
Option 1: Use the Universal Widget (Recommended)
import { UniversalBridgeWidget } from './src/UniversalBridgeWidget';
import { useWallets } from '@privy-io/react-auth';
function App() {
const { wallets } = useWallets();
return (
<UniversalBridgeWidget
walletProvider={wallets[0]}
config={{
brandName: 'My App',
primaryColor: '#6366f1',
showBalances: true,
onBridgeComplete: (result) => {
console.log('Success!', result.txHash);
}
}}
/>
);
}Option 2: Use the SDK Directly
import { LibertySwapSDK } from './src/libertySwap';
import { ethers } from 'ethers';
async function bridgeUSDC(signer: ethers.Signer) {
const sdk = new LibertySwapSDK(signer);
const result = await sdk.bridgeUSDCToBase(
'100', // Amount in USDC
'0xRecipientAddress' // Where it goes on Base
);
if (result.success) {
console.log('Bridged!', result.txHash);
}
}🎨 Widget Customization
The widget is fully customizable:
const config = {
// Branding
brandName: 'Your Brand',
brandLogo: '/logo.png',
primaryColor: '#8b5cf6',
secondaryColor: '#f3f4f6',
borderRadius: '16px',
// Limits
minAmount: 10,
maxAmount: 10000,
defaultAmount: '100',
// Features
showBalances: true,
showFees: true,
// Destination (optional - if you want USDC to go to your contract)
destinationAddress: '0xYourContractOnBase',
// Revenue sharing
affiliateId: 'partner-123',
platformFeePercent: 0.1, // 0.1% additional fee
// Callbacks
onBridgeComplete: (result) => {
// Handle success
},
onError: (error) => {
// Handle error
},
onStatusChange: (status) => {
// Track progress
}
};💡 Use Cases
1. Simple Bridge Widget
<UniversalBridgeWidget
walletProvider={wallet}
config={{ brandName: 'Bridge' }}
/>2. Bridge to Your Contract
<UniversalBridgeWidget
walletProvider={wallet}
config={{
destinationAddress: '0xYourContractOnBase',
onBridgeComplete: async (result) => {
// Wait for USDC to arrive
await waitForBridge();
// Call your contract
await yourContract.doSomething();
}
}}
/>3. White-Label Solution
<UniversalBridgeWidget
walletProvider={wallet}
config={{
brandName: 'Partner Bridge',
brandLogo: '/partner-logo.png',
primaryColor: '#your-color',
affiliateId: 'partner-123',
platformFeePercent: 0.1
}}
/>📖 API Reference
LibertySwapSDK
class LibertySwapSDK {
constructor(signer: ethers.Signer);
// Bridge USDC to Base
bridgeUSDCToBase(amount: string, recipient: string): Promise<BridgeResult>;
// Bridge all USDC
bridgeAllUSDC(recipient: string): Promise<BridgeResult>;
// Get balances
getUSDCBalance(address: string): Promise<BalanceInfo>;
getBaseUSDCBalance(address: string): Promise<BalanceInfo>;
getPLSBalance(address: string): Promise<string>;
getStatus(address: string): Promise<ChainStatus>;
// Calculate fees
calculateExpectedOutput(amount: string): FeeCalculation;
// Approval management
needsApproval(amount: string, owner: string): Promise<boolean>;
approveUSDC(amount: string): Promise<BridgeResult>;
}UniversalBridgeWidget
interface UniversalBridgeWidgetProps {
// Wallet provider (flexible)
signer?: ethers.Signer;
walletProvider?: any;
// Configuration
config?: WidgetConfig;
// Styling
className?: string;
style?: React.CSSProperties;
}🔧 Wallet Integration Examples
See examples/WidgetIntegrations.tsx for:
- ✅ Privy integration
- ✅ Rainbow Kit integration
- ✅ WalletConnect integration
- ✅ White-label setup
- ✅ Affiliate tracking
- ✅ Contract destination
- ✅ And more!
💰 Revenue Model
Built-in support for:
- Affiliate Fees - Track referrals and earn commissions
- Platform Fees - Add your own fee on top of LibertySwap's 0.3%
- Custom Destinations - Route USDC to your contracts
Example:
config={{
affiliateId: 'partner-123',
platformFeePercent: 0.1, // Earn 0.1% per bridge
destinationAddress: '0xYourContract'
}}🚀 Publishing as NPM Package
- Build the package:
npm run build- Publish:
npm publish --access public- Use in any project:
npm install @yourusername/libertyswap-widget📊 Contract Addresses
All contracts are already deployed:
- PulseChain Router:
0x0E0eDDaE092176d851d5C70A49b5d83e2510e72f - Base Router:
0x1A19B9f2687C390a130a261d1E9f0B34f5ABf312 - PulseChain USDC:
0x15D38573d2feeb82e7ad5187aB8c1D52810B1f07 - Base USDC:
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
🔐 Security
- ✅ Non-custodial - users sign transactions themselves
- ✅ No private keys ever exposed
- ✅ Contracts are verified and audited
- ✅ Open source
📞 Support
- Docs: LibertySwap Documentation
- GitHub: Report Issues
- Discord: Join Community
📄 License
MIT
🌟 Features Roadmap
- [ ] Multi-token support (PLS, HEX, PLSX)
- [ ] Batch bridging
- [ ] Bridge history tracking
- [ ] Price impact calculations
- [ ] MEV protection
Ready to integrate! 🚀
Copy the files, customize the widget, and start bridging!
