Adapter Layer Spec

Adapter Layer Specification - Chain Integration

This document specifies the adapter layer interface for integrating different blockchains with the Roru Protocol.

Adapter Interface

Core Interface

Trait Definition:

pub trait ChainAdapter {
    fn chain_id(&self) -> ChainId;
    
    async fn get_balance(&self, address: &Address) -> Result<u64>;
    
    async fn create_settlement(
        &self,
        tx: &SettlementTransaction,
    ) -> Result<SettlementTx>;
    
    async fn submit_settlement(
        &self,
        settlement: &SettlementTx,
    ) -> Result<TxHash>;
    
    async fn get_confirmation(
        &self,
        hash: &TxHash,
    ) -> Result<ConfirmationStatus>;
    
    async fn estimate_fees(
        &self,
        settlement: &SettlementTx,
    ) -> Result<Fees>;
    
    async fn get_latest_block(&self) -> Result<BlockNumber>;
}

Ethereum Adapter

Implementation

Ethereum Adapter:

Ethereum-Specific Features

Features:

  • ERC-20 token support

  • Gas estimation

  • EIP-1559 support

  • Event listening

  • Contract interaction

Solana Adapter

Implementation

Solana Adapter:

Solana-Specific Features

Features:

  • SPL token support

  • Program interaction

  • Account management

  • Transaction building

  • Fast settlement

Bitcoin Adapter

Implementation

Bitcoin Adapter:

Bitcoin-Specific Features

Features:

  • UTXO management

  • SegWit support

  • Fee estimation

  • Transaction building

  • Block monitoring

Adapter Factory

Factory Pattern

Factory Implementation:

Settlement Transaction Format

Format Definition

Settlement Transaction:

Common Fields

Common Structure:

  • State root update

  • Nullifier additions

  • New note commitments

  • Proof data

  • Metadata

Error Handling

Error Types

Adapter Errors:

  • Network errors

  • RPC errors

  • Transaction errors

  • Confirmation errors

  • Chain-specific errors

Error Recovery

Recovery Strategies:

  • Retry with backoff

  • Fallback RPC endpoints

  • Error reporting

  • State recovery

Testing

Test Adapter

Mock Adapter:

Integration Tests

Test Framework:

  • Unit tests per adapter

  • Integration tests

  • Chain-specific tests

  • End-to-end tests

Performance

Optimization

Optimizations:

  • Connection pooling

  • Batch RPC calls

  • Caching

  • Parallel processing

Metrics

Performance Metrics:

  • RPC latency

  • Transaction submission time

  • Confirmation time

  • Error rate

Security

Security Considerations

Security Measures:

  • Secure RPC connections

  • Transaction signing

  • Input validation

  • Error handling

Threat Model

Protected Against:

  • RPC attacks

  • Transaction manipulation

  • Network attacks

  • State inconsistencies

Conclusion

The adapter layer provides:

  • Abstraction: Unified interface

  • Flexibility: Multiple chains

  • Extensibility: Easy to add chains

  • Reliability: Robust error handling

  • Performance: Optimized operations

Understanding adapters is essential for chain integration.

Last updated