This directory contains Solana smart contracts (programs) for the Yuzu402 x402 payment infrastructure, built using the Anchor framework.
Handles escrow functionality for x402 payments, holding SOL until payment verification is complete.
Features:
- Create and fund escrow accounts
- Release funds to recipient after verification
- Automatic refunds on expiry
- Cancel and reclaim funds
- Secure PDA-based architecture
Instructions:
initialize_escrow- Create a new escrow accountfund_escrow- Deposit SOL into escrowrelease_escrow- Release funds to recipient (with payment proof)refund_escrow- Refund to payer if expired/cancelledclose_escrow- Close account and reclaim rent
On-chain verification system for x402 payment proofs with dispute resolution.
Features:
- Cryptographic payment proof verification (keccak hash)
- On-chain payment records
- Settlement tracking
- Dispute and resolution system
- Global verifier statistics
Instructions:
initialize_verifier- Setup the verification authorityverify_payment- Verify and record a payment on-chainsettle_payment- Mark payment as settleddispute_payment- Raise a disputeresolve_dispute- Resolve disputes (authority only)get_payment_status- Query payment details
Manages payment settlements with configurable fees and batch processing.
Features:
- Settlement pool with fee collection
- Configurable fee percentages
- Batch settlement processing
- Fee withdrawal (authority only)
- Comprehensive settlement statistics
Instructions:
initialize_pool- Create settlement poolcreate_settlement- Initialize a new settlementprocess_settlement- Execute settlement and transfer fundsbatch_process_settlements- Process multiple settlementscancel_settlement- Cancel pending settlementwithdraw_fees- Withdraw collected feesupdate_fee_percentage- Update platform feesget_pool_stats- Get pool statistics
Real-time payment streaming with vesting schedules and cliff periods.
Features:
- Continuous payment streaming over time
- Configurable vesting schedules
- Optional cliff periods
- Pause/resume functionality
- Cancel with automatic settlement
Instructions:
create_stream- Create a new payment streamfund_stream- Fund the stream with SOLwithdraw_stream- Withdraw vested fundspause_stream- Pause streaming (sender only)resume_stream- Resume paused streamcancel_stream- Cancel and settle remaining fundsget_stream_info- Query stream details
Recurring subscription payments with multiple tiers and auto-renewal.
Features:
- Create subscription plans
- Auto-renewal support
- Failed payment handling (3-strike suspension)
- Subscription lifecycle management
- Revenue tracking and analytics
Instructions:
create_plan- Create subscription plansubscribe- Subscribe to a planprocess_payment- Process recurring paymentmark_failed_payment- Record payment failurecancel_subscription- Cancel subscriptionreactivate_subscription- Reactivate suspended subscriptionupdate_auto_renew- Toggle auto-renewalupdate_plan_price- Update plan pricingdeactivate_plan- Deactivate plan
Decentralized arbitration system for payment disputes.
Features:
- Multi-arbitrator voting system
- Evidence submission and tracking
- Majority-rule dispute resolution
- Appeal system with time windows
- Automatic fund distribution
Instructions:
initialize_resolver- Setup arbitration systemcreate_dispute- File a new disputesubmit_evidence- Submit additional evidenceassign_arbitrators- Assign arbitrators to casecast_vote- Arbitrator votingfinalize_dispute- Execute resolution and transfer fundsappeal_dispute- Appeal a decisionget_dispute_info- Query dispute details
Loyalty rewards program with tiered benefits and point redemption.
Features:
- Points-based rewards system
- 4-tier membership (Bronze, Silver, Gold, Platinum)
- Automatic tier upgrades
- Point redemption for SOL
- Bonus point allocation
- Point transfers between members
Instructions:
initialize_program- Setup rewards programcreate_member- Register new memberaward_points- Award points for paymentsredeem_points- Redeem points for SOLaward_bonus- Award bonus pointstransfer_points- Transfer between membersset_tier- Manually set member tierupdate_rates- Update program rates
Multi-signature wallet for secure payment authorization.
Features:
- N-of-M signature requirement
- Transaction proposal and approval system
- Owner management (add/remove)
- Dynamic threshold adjustment
- Transaction cancellation
Instructions:
create_multisig- Create multisig walletcreate_transaction- Propose new transactionapprove_transaction- Approve transactionreject_transaction- Reject transactionexecute_transaction- Execute approved transactioncancel_transaction- Cancel pending transactionadd_owner- Add new ownerremove_owner- Remove ownerchange_threshold- Update signature threshold
- Install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh- Install Solana CLI:
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"- Install Anchor:
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest- Set up Solana wallet:
solana-keygen new
solana config set --url devnet # or mainnet-beta- Initialize Anchor workspace:
cd contracts
anchor init yuzu402-contracts --no-git- Copy contract files:
cp payment_*.rs yuzu402-contracts/programs/yuzu402-contracts/src/- Update
lib.rs:
pub mod payment_escrow;
pub mod payment_verification;
pub mod payment_settlement;cd yuzu402-contracts
anchor build# Configure for devnet
solana config set --url devnet
# Airdrop SOL for deployment (devnet only)
solana airdrop 2
# Deploy
anchor deploy
# Note the program IDs and update declare_id! in each contract# Configure for mainnet
solana config set --url mainnet-beta
# Deploy (requires sufficient SOL)
anchor deployimport * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
const program = anchor.workspace.PaymentEscrow;
// Initialize escrow
const escrowPDA = await program.methods
.initializeEscrow(
new anchor.BN(1000000000), // 1 SOL in lamports
recipientPublicKey,
Math.floor(Date.now() / 1000) + 3600 // 1 hour expiry
)
.accounts({
escrow: escrowAccount,
payer: payerPublicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
// Fund escrow
await program.methods
.fundEscrow()
.accounts({
escrow: escrowAccount,
payer: payerPublicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
// Release after verification
await program.methods
.releaseEscrow("BASE64_PAYMENT_PROOF")
.accounts({
escrow: escrowAccount,
recipient: recipientPublicKey,
authority: authorityPublicKey,
})
.rpc();const program = anchor.workspace.PaymentVerification;
// Initialize verifier (once)
await program.methods
.initializeVerifier()
.accounts({
verifier: verifierPDA,
authority: authorityPublicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
// Verify a payment
await program.methods
.verifyPayment(
"BASE64_PAYMENT_PROOF",
new anchor.BN(1000000000),
recipientPublicKey,
"solana",
"5wHu...signature"
)
.accounts({
payment: paymentPDA,
verifier: verifierPDA,
payer: payerPublicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();const program = anchor.workspace.PaymentSettlement;
// Initialize pool (once)
await program.methods
.initializePool(100) // 1% fee
.accounts({
pool: poolPDA,
authority: authorityPublicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
// Create settlement
await program.methods
.createSettlement(
new anchor.BN(1000000000),
recipientPublicKey,
"payment_12345"
)
.accounts({
settlement: settlementPDA,
pool: poolPDA,
payer: payerPublicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
// Process settlement
await program.methods
.processSettlement()
.accounts({
settlement: settlementPDA,
pool: poolPDA,
payer: payerPublicKey,
recipient: recipientPublicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();# Run all tests
anchor test
# Run specific test file
anchor test -- --test escrow
# Test on devnet
anchor test --provider.cluster devnet- Escrow PDA:
["escrow", payer.key()]
- Verifier PDA:
["verifier"] - Payment PDA:
["payment", payer.key(), payment_proof.bytes()]
- Pool PDA:
["pool"] - Settlement PDA:
["settlement", payer.key(), payment_id.bytes()]
- Program Authority: All contracts use PDA-based authority for security
- Time-based Controls: Escrows have expiry timestamps to prevent locked funds
- Status Checks: All state transitions validate current status
- Amount Validation: All transfers validate amounts > 0
- Authorization: Critical operations require proper authority signatures
These contracts are designed to work seamlessly with the Yuzu402 REST API:
- API creates escrow β Contract holds funds
- x402 payment received β API calls verify_payment
- Verification complete β Contract releases escrow
- Settlement initiated β Contract processes and collects fees
- Fork the repository
- Create your feature branch
- Write tests for new features
- Ensure all tests pass
- Submit a pull request
Proprietary - All rights reserved
- Documentation: https://docs.yuzu402.dev
- Email: support@yuzu402.dev
- Twitter: @yuzu402dotdev
Built with β€οΈ by the Yuzu402 team