From 75c0e146c8d04bb5c7cf26f40aa00a4c8a15fb15 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Wed, 23 Jul 2025 17:43:57 +0530 Subject: [PATCH] Rename SOL native to GOR native --- .env.example | 2 +- CLAUDE.md | 123 +++++++++++++++++++++++------ src/app/api/registry/route.ts | 14 ++-- src/app/page.tsx | 20 ++--- src/components/PaymentModal.tsx | 14 ++-- src/components/WalletProviders.tsx | 4 +- src/constants/payments.ts | 8 +- src/services/solana.ts | 18 ++--- src/types/index.ts | 2 +- src/utils/solana-verify.ts | 10 +-- 10 files changed, 145 insertions(+), 70 deletions(-) diff --git a/.env.example b/.env.example index 975175e..5b86f19 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ # Solana Payment Configuration NEXT_PUBLIC_SOLANA_RPC_URL=https://skilled-prettiest-seed.solana-mainnet.quiknode.pro/eeecfebd04e345f69f1900cc3483cbbfea02a158 -NEXT_PUBLIC_SOLANA_SOL_RPC_URL=https://rpc.gorbagana.wtf +NEXT_PUBLIC_GORBAGANA_RPC_URL=https://rpc.gorbagana.wtf NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS=71Jvq4Epe2FCJ7JFSF7jLXdNk1Wy4Bhqd9iL6bEFELvg # Multisig address diff --git a/CLAUDE.md b/CLAUDE.md index f51c233..dc64720 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,7 +2,7 @@ ## Project Overview -**GOR Deploy** is a Next.js application that bridges Solana blockchain token payments with Laconic Registry deployments. Users pay with GOR tokens (or any configurable Solana SPL token) and the app creates deployment records in the Laconic Registry for frontend applications. +**GOR Deploy** is a Next.js application that bridges Solana blockchain token payments with Laconic Registry deployments. Users pay with native GOR tokens or GOR SPL tokens and the app creates deployment records in the Laconic Registry for frontend applications. ## Quick Commands @@ -26,12 +26,16 @@ npm run lint # Run ESLint - Solana Web3.js for payments - @cerc-io/registry-sdk for Laconic Registry - CosmJS for Cosmos blockchain interactions -- **Wallet Integration**: Phantom & Solflare +- **Wallet Integration**: Phantom, Solflare & Backpack with context-based filtering - **Language**: TypeScript ### Key Dependencies - `@solana/web3.js` - Solana blockchain interactions - `@solana/spl-token` - SPL token handling +- `@solana/wallet-adapter-react` - Unified wallet adapter integration +- `@solana/wallet-adapter-phantom` - Phantom wallet adapter +- `@solana/wallet-adapter-solflare` - Solflare wallet adapter +- `@solana/wallet-adapter-backpack` - Backpack wallet adapter - `@cerc-io/registry-sdk` - Laconic Registry operations - `@cosmjs/stargate` - Cosmos blockchain operations - `axios` - HTTP requests for GitHub API @@ -40,38 +44,58 @@ npm run lint # Run ESLint ## Application Flow -1. **Wallet Connection**: User connects Phantom or Solflare wallet -2. **URL Input**: User enters repository URL to deploy -3. **Payment**: Fixed amount payment in GOR/SPL tokens to configured recipient -4. **Verification**: Server verifies Solana transaction (5-minute window) -5. **LNT Transfer**: Server transfers LNT tokens for registry fees -6. **Registry Records**: Creates ApplicationRecord and ApplicationDeploymentRequest -7. **Name Mapping**: Sets LRN mappings in Laconic Registry +1. **Payment Method Selection**: User chooses between native GOR or SPL token payment +2. **Wallet Connection**: Compatible wallets are filtered based on payment method +3. **URL Input**: User enters repository URL to deploy (enabled after wallet connection) +4. **Payment**: Fixed amount payment in native GOR or GOR SPL tokens to configured recipient +5. **Verification**: Server verifies Solana transaction (5-minute window) +6. **LNT Transfer**: Server transfers LNT tokens for registry fees +7. **Registry Records**: Creates ApplicationRecord and ApplicationDeploymentRequest +8. **Name Mapping**: Sets LRN mappings in Laconic Registry + +## Payment Method & Wallet Compatibility + +### Native GOR Payments (`nat-gor`) +- **Amount**: 0.01 GOR (10,000,000 lamports) +- **Compatible Wallets**: Backpack only +- **RPC Endpoint**: Uses `NEXT_PUBLIC_GORBAGANA_RPC_URL` for native transactions + +### SPL Token Payments (`spl-token`) +- **Amount**: $5 USD worth of GOR SPL tokens (dynamic pricing via Jupiter) +- **Compatible Wallets**: Phantom, Solflare (Backpack excluded) +- **RPC Endpoint**: Uses `NEXT_PUBLIC_SOLANA_RPC_URL` for token transactions ## Key Files and Components ### Frontend Components -- `src/app/page.tsx` - Main application page with 3-step flow -- `src/components/PaymentModal.tsx` - Solana payment interface -- `src/components/SolanaConnect.tsx` - Wallet connection UI +- `src/app/page.tsx` - Main application page with 4-step flow (Payment Method → Wallet → URL → Status) +- `src/components/PaymentModal.tsx` - Solana payment interface with pre-selected payment method +- `src/components/WalletProviders.tsx` - Context-aware wallet provider with filtering - `src/components/URLForm.tsx` - URL input form - `src/components/StatusDisplay.tsx` - Deployment status display +### Context & State Management +- `src/contexts/PaymentMethodContext.tsx` - Global payment method state management +- Uses React Context for payment method selection +- Wallet filtering based on payment method context + ### Services and Utils -- `src/services/solana.ts` - Solana wallet and payment operations +- `src/services/solana.ts` - Unified wallet adapter integration for payments - `src/services/registry.ts` - Client-side registry service wrapper - `src/services/laconic-transfer.ts` - LNT token transfer logic - `src/utils/solana-verify.ts` - Payment verification with replay protection - `src/config/index.ts` - Registry configuration management +- `src/constants/payments.ts` - Payment method types and configuration ### API Routes -- `src/app/api/registry/route.ts` - Main server-side registry operations +- `src/app/api/registry/route.ts` - Main server-side registry operations with dual payment support ## Environment Configuration ### Client-side Variables (NEXT_PUBLIC_*) ```bash NEXT_PUBLIC_SOLANA_RPC_URL=https://skilled-prettiest-seed.solana-mainnet.quiknode.pro/eeecfebd04e345f69f1900cc3483cbbfea02a158 +NEXT_PUBLIC_GORBAGANA_RPC_URL=https://rpc.gorbagana.wtf NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS= NEXT_PUBLIC_SOLANA_TOKEN_RECIPIENT_ADDRESS= NEXT_PUBLIC_SOLANA_TOKEN_SYMBOL=GOR @@ -95,20 +119,29 @@ DEPLOYER_LRN= ## Code Patterns and Conventions ### State Management -- Uses React `useState` for component state -- No global state management library +- Uses React Context (`PaymentMethodContext`) for global payment method state +- React `useState` for component-level state - Dynamic imports to avoid SSR issues with browser APIs +- Context-driven wallet filtering + +### Payment Architecture +- Unified wallet adapter pattern for all three wallets +- Payment method determines wallet availability +- Separate RPC endpoints for native vs SPL token transactions +- Dynamic pricing via Jupiter API for SPL tokens ### Error Handling - Comprehensive try-catch blocks in all async operations - User-friendly error messages in UI - Server-side error logging with detailed context +- Wallet compatibility validation with clear feedback ### Security Best Practices - Environment variables for sensitive data - Transaction verification with replay protection - Proper SPL token account creation and validation - Private key never exposed to client-side +- Wallet signature verification via adapters ## Development Workflow @@ -117,11 +150,18 @@ DEPLOYER_LRN= 2. **Services**: Add to `src/services/` 3. **API Routes**: Add to `src/app/api/` 4. **Types**: Update `src/types/index.ts` +5. **Payment Methods**: Update `src/constants/payments.ts` ### Payment Integration -- All payment logic in `src/services/solana.ts` +- All payment logic unified in `src/services/solana.ts` - Verification logic in `src/utils/solana-verify.ts` - Transaction signing via wallet adapters +- Payment method context drives wallet selection + +### Wallet Integration +- Add new wallet adapters to `src/components/WalletProviders.tsx` +- Update wallet filtering logic based on payment method compatibility +- Use `@solana/wallet-adapter-*` packages for consistent integration ### Registry Integration - Registry operations in `src/app/api/registry/route.ts` @@ -147,8 +187,9 @@ Format: `lrn://{authority}/applications/{app-name}-{commit-hash}` ### Solana Payment Verification - 5-minute transaction window - Amount verification against configured payment -- Recipient address validation +- Recipient address validation (different for native vs SPL) - Replay attack protection (TODO: implement used transaction tracking) +- Payment method-specific validation logic ### Laconic Registry Operations 1. **ApplicationRecord**: Repository metadata and commit info @@ -158,20 +199,45 @@ Format: `lrn://{authority}/applications/{app-name}-{commit-hash}` ## Common Development Tasks ### Adding New Wallet Support -1. Update `SolanaWalletType` in `src/types/index.ts` -2. Add wallet logic to `src/services/solana.ts` -3. Update `SolanaConnect.tsx` component +1. Install wallet adapter package: `npm install @solana/wallet-adapter-{wallet-name}` +2. Add to `src/components/WalletProviders.tsx` wallets array +3. Update wallet filtering logic based on payment method compatibility +4. Test with both payment methods + +### Adding New Payment Methods +1. Update `PaymentMethod` type in `src/constants/payments.ts` +2. Add payment method label to `PAYMENT_METHOD_LABELS` +3. Update wallet filtering logic in `WalletProviders.tsx` +4. Add payment processing logic in `src/services/solana.ts` +5. Update verification logic in `src/utils/solana-verify.ts` ### Modifying Payment Verification - Update logic in `src/utils/solana-verify.ts` - Consider replay protection requirements - Test with various transaction types +- Handle both native GOR and SPL token verification ### Registry Schema Changes - Update record structures in `src/app/api/registry/route.ts` - Ensure compatibility with Laconic Registry schema - Test with registry validation +## Payment Method Context Usage + +The `PaymentMethodContext` drives wallet filtering: + +```typescript +// In components +const { selectedPaymentMethod, setSelectedPaymentMethod } = usePaymentMethod(); + +// Wallet filtering logic +if (selectedPaymentMethod === 'nat-gor') { + // Show only Backpack wallet +} else if (selectedPaymentMethod === 'spl-token') { + // Show only Phantom and Solflare wallets +} +``` + ## Deployment Considerations ### Production Setup @@ -179,6 +245,7 @@ Format: `lrn://{authority}/applications/{app-name}-{commit-hash}` - HTTPS required for wallet connections - Consider rate limiting for API routes - Monitor gas fees and LNT transfer costs +- Ensure both RPC endpoints are reliable ### Docker Deployment - Dockerfile provided in project root @@ -189,15 +256,18 @@ Format: `lrn://{authority}/applications/{app-name}-{commit-hash}` ### Common Issues - **Wallet connection fails**: Check HTTPS and wallet extension -- **Transaction verification fails**: Check RPC URL and transaction timing +- **Wrong wallet shown**: Verify payment method context is set correctly +- **Transaction verification fails**: Check appropriate RPC URL and transaction timing - **Registry errors**: Verify all REGISTRY_* environment variables - **LNT transfer fails**: Check private key balance and permissions +- **SPL token price errors**: Verify Jupiter API connectivity ### Debug Tools - Browser console for client-side debugging - Server logs for API route debugging - Solana Explorer for transaction verification - Registry CLI for direct registry interactions +- Payment method context state in React DevTools ## Testing Strategy @@ -205,6 +275,8 @@ Format: `lrn://{authority}/applications/{app-name}-{commit-hash}` - Use testnet/devnet for development - Test transaction verification edge cases - Verify registry record creation and name mappings +- Test wallet filtering with different payment methods +- Test both native GOR and SPL token payment flows ## Related Projects @@ -219,7 +291,8 @@ This application references: - Transaction replay protection implemented - Input validation on all user inputs - Secure RPC endpoint usage -- Wallet signature verification +- Wallet signature verification via adapters +- Payment method validation before processing ## Future Enhancements @@ -227,4 +300,6 @@ This application references: - Add support for custom deployment configurations - Enhanced error recovery and retry logic - Monitoring and analytics integration -- Multi-chain payment support \ No newline at end of file +- Multi-chain payment support +- Additional wallet adapter integrations +- Advanced payment method configurations \ No newline at end of file diff --git a/src/app/api/registry/route.ts b/src/app/api/registry/route.ts index e5a7055..7cd0263 100644 --- a/src/app/api/registry/route.ts +++ b/src/app/api/registry/route.ts @@ -15,10 +15,10 @@ import { PaymentMethod, SOL_PAYMENT_AMOUNT_LAMPORTS } from '@/constants/payments import { getRecipientAddress } from '@/services/solana'; assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL, 'SOLANA_RPC_URL is required'); -assert(process.env.NEXT_PUBLIC_SOLANA_SOL_RPC_URL, 'SOLANA_SOL_RPC_URL is required'); +assert(process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL, 'GORBAGANA_RPC_URL is required'); const SOLANA_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_RPC_URL; -const SOLANA_SOL_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_SOL_RPC_URL; +const SOLANA_SOL_RPC_URL = process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL; // Allow 20% slippage due to price fluctuations const ALLOWED_SLIPPAGE_FACTOR = 0.2 @@ -141,7 +141,7 @@ export const registryTransactionWithRetry = async ( // Helper function to get the appropriate connection based on payment method const getConnection = (paymentMethod: PaymentMethod): Connection => { - if (paymentMethod === 'sol' && SOLANA_SOL_RPC_URL) { + if (paymentMethod === 'nat-gor' && SOLANA_SOL_RPC_URL) { return new Connection(SOLANA_SOL_RPC_URL); } return new Connection(SOLANA_RPC_URL); @@ -185,10 +185,10 @@ export async function POST(request: NextRequest) { } // Validate payment method - if (paymentMethod !== 'sol' && paymentMethod !== 'spl-token') { + if (paymentMethod !== 'nat-gor' && paymentMethod !== 'spl-token') { return NextResponse.json({ status: 'error', - message: 'Invalid payment method. Must be "sol" or "spl-token".' + message: 'Invalid payment method. Must be "nat-gor" or "spl-token".' }, { status: 400 }); } } catch (error) { @@ -206,9 +206,9 @@ export async function POST(request: NextRequest) { let expectedAmount: BN; let expectedRecipientAddress: string; - if (paymentMethod === 'sol') { + if (paymentMethod === 'nat-gor') { expectedAmount = new BN(SOL_PAYMENT_AMOUNT_LAMPORTS); - expectedRecipientAddress = getRecipientAddress('sol'); + expectedRecipientAddress = getRecipientAddress('nat-gor'); } else if (paymentMethod === 'spl-token') { const targetUsdAmount = parseFloat(process.env.NEXT_PUBLIC_SOLANA_PAYMENT_AMOUNT_USD!); const mintAddress = process.env.NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS!; diff --git a/src/app/page.tsx b/src/app/page.tsx index a1fea19..04898ca 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -42,8 +42,8 @@ export default function Home() { const walletName = wallet.adapter.name.toLowerCase(); const isBackpack = walletName.includes('backpack'); - if (selectedPaymentMethod === 'sol') { - return isBackpack; // Only Backpack for SOL + if (selectedPaymentMethod === 'nat-gor') { + return isBackpack; // Only Backpack for native GOR } else { return !isBackpack; // Only non-Backpack wallets for SPL tokens } @@ -111,19 +111,19 @@ export default function Home() {