Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fee bumping Package #114

Open
wants to merge 63 commits into
base: main
Choose a base branch
from

Commits on Jun 23, 2024

  1. feat: Initialize @caravan/feebumping package

    Create a new package for fee bumping functionality in Caravan. This package
    provides modular and reusable utilities for implementing RBF (Replace-By-Fee)
    and CPFP (Child-Pays-For-Parent) fee bumping strategies.
    
    Key additions:
    - Basic package structure and configuration files
    - Core modules for RBF and CPFP implementations
    - Fee estimation utilities
    - Type definitions for fee bumping operations
    - Constants and utility functions
    
    This package aims to enhance Caravan's transaction management capabilities
    by providing a flexible and extensible fee bumping solution that can be
    easily integrated into the Caravan coordinator wallet and other Bitcoin
    projects.
    Legend101Zz committed Jun 23, 2024
    Configuration menu
    Copy the full SHA
    5c233db View commit details
    Browse the repository at this point in the history
  2. changes in rbf file

    Legend101Zz committed Jun 23, 2024
    Configuration menu
    Copy the full SHA
    592a875 View commit details
    Browse the repository at this point in the history

Commits on Jul 19, 2024

  1. Add comprehensive fee bumping package for Caravan

    This commit introduces a new @caravan/fee-bumping package that provides robust functionality for handling Replace-By-Fee (RBF) and Child-Pays-For-Parent (CPFP) fee bumping strategies in Bitcoin transactions. The package is designed to work seamlessly with other Caravan packages and offers a flexible, modular approach to fee bumping.
    
    Key features:
    - Implement RBFHandler for Replace-By-Fee transactions
    - Implement CPFPHandler for Child-Pays-For-Parent transactions
    - Create FeeEstimator for dynamic fee rate calculations
    - Provide utility functions for transaction analysis and manipulation
    - Define comprehensive types for improved type safety and developer experience
    - Implement constants for fee-related thresholds and limits
    
    The package structure includes:
    - src/index.ts: Main entry point and FeeBumping class
    - src/types.ts: TypeScript interfaces and types
    - src/estimator.ts: FeeEstimator class for fee calculations
    - src/rbf.ts: RBFHandler class for RBF operations
    - src/cpfp.ts: CPFPHandler class for CPFP operations
    - src/utils.ts: Utility functions for transaction handling
    - src/constants.ts: Constant values used throughout the package
    
    This package provides a solid foundation for implementing fee bumping strategies in Caravan-based applications. It offers:
    1. Flexible fee estimation based on network conditions
    2. Configurable options for both RBF and CPFP operations
    3. Built-in safeguards against excessive fees
    4. Utility functions for transaction analysis and modification
    
    The implementation is designed with extensibility in mind, allowing for easy updates and additions to fee bumping strategies in the future.
    
    Next steps:
    - Implement comprehensive unit tests for all components
    - Integrate the package with the main Caravan UI
    - Create documentation and usage examples
    - Perform thorough testing with various transaction scenarios
    
    This addition significantly enhances Caravan's capabilities in handling dynamic fee environments, improving overall user experience and transaction reliability.
    Legend101Zz committed Jul 19, 2024
    Configuration menu
    Copy the full SHA
    4f0755c View commit details
    Browse the repository at this point in the history

Commits on Jul 22, 2024

  1. Implement fee bumping types and estimation functions

    - Add new types for UTXO, TransactionOutput, TransactionAnalysis, FeeRate,
      FeeEstimate, TransactionDetails, BlockchainClientInterface, RBFOptions,
      and CPFPOptions in types.ts
    - Create getFeeEstimates function to fetch fee estimates from blockchain client
    - Implement calculateFee function to compute transaction fee based on vsize and fee rate
    - Use BigNumber for precise calculations
    - Import necessary constants and interfaces
    
    This commit lays the groundwork for RBF and CPFP implementations by defining
    essential types and providing core fee estimation functionality.
    Legend101Zz committed Jul 22, 2024
    Configuration menu
    Copy the full SHA
    b00eaae View commit details
    Browse the repository at this point in the history
  2. Add transaction analysis functionality for fee bumping

    - Create new file analyzer.ts with analyzeTransaction function
    - Implement logic to determine if a transaction can use RBF or CPFP
    - Calculate current fee rate of the transaction
    - Provide a recommended fee bumping method based on transaction properties
    - Utilize utility functions isRBFSignaled and calculateEffectiveFeeRate
    - Return a TransactionAnalysis object with fee bumping options
    
    This commit adds crucial functionality for analyzing transactions to determine
    the best fee bumping strategy, supporting the implementation of RBF and CPFP
    features in the Caravan wallet.
    Legend101Zz committed Jul 22, 2024
    Configuration menu
    Copy the full SHA
    9b0c967 View commit details
    Browse the repository at this point in the history
  3. Refactor fee bumping package for improved functionality and integration

    This commit significantly refactors the fee bumping package to improve its functionality,
    integration with bitcoinjs-lib, and overall code structure. Key changes include:
    
    RBF (Replace-By-Fee):
    - Updated to work with bitcoinjs-lib Transaction objects
    - Implemented dynamic input and output handling
    - Added support for transaction cancellation and fee subtraction from outputs
    
    CPFP (Child-Pays-For-Parent):
    - Refactored to handle multiple parent outputs
    - Implemented dynamic input and output calculation
    - Added support for additional outputs in child transactions
    - Improved fee calculation accuracy
    
    Utils:
    - Added deriveAddress function for working with bitcoinjs-lib Output objects
    - Updated isRBFSignaled and calculateEffectiveFeeRate functions
    - Removed estimateVirtualSize in favor of using Transaction.virtualSize()
    
    Transaction Analysis:
    - Implemented analyzeTransaction function for recommending fee bumping strategies
    - Added logic to compare current fee rate with network fee rate
    
    Removed:
    - Eliminated estimator.ts file, integrating necessary functionality into other modules
    
    Tests:
    - Added comprehensive test suite for analyzeTransaction function
    - Updated existing tests to reflect new implementations of RBF and CPFP functions
    
    Types:
    - Updated and expanded type definitions to better integrate with bitcoinjs-lib
    - Added new interfaces for RBFOptions, CPFPOptions, and TransactionAnalysis
    Legend101Zz committed Jul 22, 2024
    Configuration menu
    Copy the full SHA
    b7b2fa5 View commit details
    Browse the repository at this point in the history

Commits on Jul 26, 2024

  1. Changes to the RBF functionality in the fees package and added RBF si…

    …gnalling functionality to PSBTV2
    
    Key changes:
    
    1. rbf.ts:
       - Introduced RbfTransaction class to encapsulate RBF logic
       - Implemented methods for preparing accelerated and canceled transactions
       - Added helper methods for fee calculations and PSBT manipulations
       - Created public functions prepareRbfTransaction and prepareCancelTransaction
         as entry points for RBF operations
    
    2. psbtv2.ts:
       - Added isRbfSignaled method to check if a transaction is RBF-enabled
    Legend101Zz committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    63c129c View commit details
    Browse the repository at this point in the history

Commits on Aug 1, 2024

  1. Implement CPFP and RBF classes with tests

    This commit introduces new classes for Child-Pays-for-Parent (CPFP) and refactors majority of Replace-By-Fee (RBF)
    transaction creation, along with comprehensive tests.
    
    Key changes:
    - Add CPFPTransaction class for creating child transactions
    - Refactored RbfTransaction class for preparing replacement transactions
    - Create tests for CPFP, RBF
    - Update existing transaction utilities to support new classes
    
    The new classes support both PSBTv2 and PSBTv0 formats, handle various edge cases,
    and provide methods for fee calculation and transaction preparation.
    Legend101Zz committed Aug 1, 2024
    Configuration menu
    Copy the full SHA
    4fce4fe View commit details
    Browse the repository at this point in the history

Commits on Aug 3, 2024

  1. Configuration menu
    Copy the full SHA
    77f0cbe View commit details
    Browse the repository at this point in the history

Commits on Aug 6, 2024

  1. Configuration menu
    Copy the full SHA
    77f4db4 View commit details
    Browse the repository at this point in the history

Commits on Aug 14, 2024

  1. Enhance RBF class functionality with improved state management and fe…

    …e calculation
    
    - Add state management to track acceleration and cancellation status
    - Implement caching for fee increase and vsize calculations
    - Introduce incremental relay fee for accurate fee bump calculations
    - Refactor fee calculation logic to comply with BIP 125 rules
    - Optimize input selection by sorting UTXOs before addition
    - Improve RBF signaling by updating only one input sequence
    - Added more comments for better code understanding
    Legend101Zz committed Aug 14, 2024
    Configuration menu
    Copy the full SHA
    4f4f97a View commit details
    Browse the repository at this point in the history
  2. Added methods to handle sequence numbers within PSBTs for better RBF …

    …(Replace-By-Fee) support
    
    - setInputSequence(inputIndex: number, sequence: number): A method for setting the sequence number of a specific input, critical for signaling RBF and handling nLockTime.
    - get isRBFSignaled(): boolean: A method to check if the transaction signals RBF, as per BIP125 guidelines.
    - Added tests
    Legend101Zz committed Aug 14, 2024
    Configuration menu
    Copy the full SHA
    07d5a84 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d71a0ec View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    ee553e7 View commit details
    Browse the repository at this point in the history

Commits on Aug 16, 2024

  1. Refactor RBF class with improved state management and error handling

    This commit introduces a significant refactoring of the RBF (Replace-By-Fee)
    class, enhancing its functionality, reliability, and maintainability. The
    changes focus on implementing a robust state management system, expanding
    method capabilities, and introducing a sophisticated error handling mechanism.
    
    Key Changes:
    
    1. Transaction State Philosophy:
       - Implemented a state machine approach using the TransactionState enum
       - States include: INITIALIZED, ANALYZING, ANALYZED, MODIFYING, FINALIZING,
         FINALIZED, and ERROR
       - Each method now checks and updates the state, ensuring operations occur
         in the correct sequence
       - This approach prevents invalid operations and provides clear visibility
         into the transaction's current status
    
    2. New and Enhanced Methods:
       - analyze(): Performs initial analysis of the transaction, including RBF
         eligibility checks
       - prepareAccelerated(): Prepares an accelerated replacement transaction
       - prepareCanceled(): Creates a cancellation replacement transaction
       - calculateFeeIncrease(): Determines the required fee increase for RBF
       - estimateRBFCost() and estimateCPFPCost(): Calculate costs for different
         fee-bumping strategies
       - recommendFeeBumpStrategy(): Suggests the optimal fee-bumping approach
       - getTransactionInfo(): Provides comprehensive transaction details
    
    3. Error Handling System:
       - Introduced a custom RbfError class extending TransactionError
       - Defined specific error types (RbfErrorType) for various failure scenarios
       - Errors now include both an error type and the transaction state at the
         time of the error
       - This system allows for more precise error reporting and easier debugging
    
    4. Improved UTXO Management:
       - Enhanced logic for selecting and adding additional UTXOs when necessary
       - Implemented checks to ensure compliance with BIP 125 rules
    
    5. Fee Calculations:
       - Refined fee estimation logic, taking into account transaction size changes
       - Introduced methods to calculate and compare different fee scenarios
    
    6. Caching Mechanism:
       - Implemented caching for frequently used calculations (e.g., transaction
         size estimates)
       - Improves performance by reducing redundant computations
    
    7. Comprehensive Transaction Analysis:
       - Added methods to analyze RBF possibility (canRBF) and cancellation
         possibility (canCancel)
       - These provide quick insights into available options for the transaction
    
    8. Helper Functions:
       - Introduced utility functions for common operations like UTXO selection
         and output adjustments
    Legend101Zz committed Aug 16, 2024
    Configuration menu
    Copy the full SHA
    9237196 View commit details
    Browse the repository at this point in the history

Commits on Aug 19, 2024

  1. feat: Implement TransactionAnalyzer for raw transaction analysis

    This commit introduces a new TransactionAnalyzer class designed to work
    with raw transaction hex data instead of PSBTs. The class provides
    functionality to analyze Bitcoin transactions, calculate fees, and
    determine fee bump strategies.
    
    Key features:
    - Parse raw transaction hex to extract inputs and outputs
    - Calculate absolute and relative fees
    - Estimate fees required for RBF and CPFP
    - Determine if a transaction is eligible for RBF or CPFP
    - Recommend optimal fee bump strategy
    
    The TransactionAnalyzer serves as a foundation for future RBF and CPFP
    implementations, providing essential information without relying on
    PSBTs.
    
    Added unit tests to verify the functionality of the TransactionAnalyzer
    class, covering various scenarios and edge cases.
    Legend101Zz committed Aug 19, 2024
    Configuration menu
    Copy the full SHA
    63969ab View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2024

  1. Refactor of TransactionAnalyzer classfor Enhanced Fee Calculation and…

    … Clarity
    
    Description
    - Refactored the TransactionAnalyzer class to address inaccuracies in CPFP (Child Pays for Parent) fee calculations. This involved refining the argument handling, optimizing properties, and improving the use of internal/private values, getters, and setters for more robust and maintainable code.
    - Added comprehensive documentation to all types, enhancing the overall clarity and usability of the package.
    - Moved tests and fixtures to seperate folder
    - Cleaned `utils` and `constants` files
    Legend101Zz committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    0047714 View commit details
    Browse the repository at this point in the history
  2. Added Bitcoin Transaction Components and Template

    Description
    - Added BtcTxComponent as a base class for handling Bitcoin transaction inputs and outputs.
    - Introduced BtcTxInputTemplate and BtcTxOutputTemplate for managing individual inputs and outputs.
    - Created BtcTransactionTemplate to help build, validate, and manage Bitcoin transactions.
    Legend101Zz committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    28a1ae2 View commit details
    Browse the repository at this point in the history
  3. feat: Implemented new CPFP/RBF functions

    - Added `createCPFPTransaction` function to generate a CPFP transaction with enhanced fee handling.
    - Implemented `createCancelRbfTransaction` to allow cancellation of an original transaction using RBF.
    - Added `createAcceleratedRbfTransaction` for accelerating an original transaction by increasing the fee.
    - Integrated transaction analysis and validation within each function.
    - Included detailed documentation and examples for each function.
    Legend101Zz committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    8ca1b75 View commit details
    Browse the repository at this point in the history

Commits on Aug 29, 2024

  1. Configuration menu
    Copy the full SHA
    09cceac View commit details
    Browse the repository at this point in the history
  2. refactor: changes in transactionAnalyzer class and it's tests

    - Removed dust threshold option from the class
    - minor corrections in fee calculations
    - improvement in documentation
    - added new fixtures and tests
    Legend101Zz committed Aug 29, 2024
    Configuration menu
    Copy the full SHA
    47e598f View commit details
    Browse the repository at this point in the history
  3. refactor : btcTransactionComponents and btcTransactionTemplate classes

    - better btcTransactionComponents validation and malleability considerations
    - changes to keep consistent use of BN library within classes
    - fixes to methods : `adjustChangeOutput`
    - new added fixtures and tests
    Legend101Zz committed Aug 29, 2024
    Configuration menu
    Copy the full SHA
    3c9f3ff View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    93f5e39 View commit details
    Browse the repository at this point in the history

Commits on Sep 1, 2024

  1. Configuration menu
    Copy the full SHA
    b247da4 View commit details
    Browse the repository at this point in the history
  2. refactor : btcComponents and btcTemplate ... toPsbt() method , remove…

    …d external/change type from btcOutput and added prevTxHex , sequence fields in btcInput
    Legend101Zz committed Sep 1, 2024
    Configuration menu
    Copy the full SHA
    6662b2d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f6aeea6 View commit details
    Browse the repository at this point in the history

Commits on Sep 2, 2024

  1. refactor: Changes in btcTransactionInput , Add methods for intiatiati…

    …ng class from a UTXO type and having a mapping between the two , removed unnecessary types and changes in analyzer to handle new btcInputs and UTXOs
    Legend101Zz committed Sep 2, 2024
    Configuration menu
    Copy the full SHA
    345d6fb View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ad3c6ee View commit details
    Browse the repository at this point in the history
  3. refactor: RBF/CPFP functions to handle new toPSBT() method of templat…

    …e and new UTXO - btcInput functionality
    Legend101Zz committed Sep 2, 2024
    Configuration menu
    Copy the full SHA
    a215dea View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    4597dc9 View commit details
    Browse the repository at this point in the history
  5. add README

    Legend101Zz committed Sep 2, 2024
    Configuration menu
    Copy the full SHA
    f39e26d View commit details
    Browse the repository at this point in the history

Commits on Sep 9, 2024

  1. Configuration menu
    Copy the full SHA
    372f919 View commit details
    Browse the repository at this point in the history
  2. minor README changes

    Legend101Zz committed Sep 9, 2024
    Configuration menu
    Copy the full SHA
    d19fd1e View commit details
    Browse the repository at this point in the history
  3. refactor btcTransactionComponents : added methods to validate witness…

    …Utxo and sequence setters , methods to enable/disable RBF in InputTemplate
    Legend101Zz committed Sep 9, 2024
    Configuration menu
    Copy the full SHA
    272d946 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    c75270a View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    09d9bc5 View commit details
    Browse the repository at this point in the history
  6. Add ScriptType : Added a new script-type extending MULTISIG_ADDRESS_T…

    …YPES from caravan-bitcoin
    Legend101Zz committed Sep 9, 2024
    Configuration menu
    Copy the full SHA
    8da4962 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    0acce5f View commit details
    Browse the repository at this point in the history

Commits on Sep 11, 2024

  1. minor fix: README link

    Legend101Zz committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    65717ec View commit details
    Browse the repository at this point in the history

Commits on Sep 12, 2024

  1. Refactor: Utils file to remove unnecessary functions, move some util …

    …fn to other files & correct/extend fn like getOutputAddress
    Legend101Zz committed Sep 12, 2024
    Configuration menu
    Copy the full SHA
    dc02fb5 View commit details
    Browse the repository at this point in the history
  2. refactor: Transaction Analyzer ... correct rbf-fees calculation , ret…

    …urn types , add estimatedCPFPChildSize fn
    Legend101Zz committed Sep 12, 2024
    Configuration menu
    Copy the full SHA
    73dd323 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    db3ae16 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    fbd36a1 View commit details
    Browse the repository at this point in the history
  5. refactor: btcTransactionTemplate add addInputToPsbt & addOutputToPsbt…

    … from utils to template class
    Legend101Zz committed Sep 12, 2024
    Configuration menu
    Copy the full SHA
    82a3c5c View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f142a7f View commit details
    Browse the repository at this point in the history

Commits on Sep 16, 2024

  1. Configuration menu
    Copy the full SHA
    104bc75 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e5c98c1 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    74511cf View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    6f35442 View commit details
    Browse the repository at this point in the history

Commits on Sep 22, 2024

  1. Configuration menu
    Copy the full SHA
    dcffd5e View commit details
    Browse the repository at this point in the history
  2. correction tests: RBF

    Legend101Zz committed Sep 22, 2024
    Configuration menu
    Copy the full SHA
    788ff6f View commit details
    Browse the repository at this point in the history
  3. correction tests: CPFP

    Legend101Zz committed Sep 22, 2024
    Configuration menu
    Copy the full SHA
    c3f56c4 View commit details
    Browse the repository at this point in the history
  4. refactor : tsconfig

    Legend101Zz committed Sep 22, 2024
    Configuration menu
    Copy the full SHA
    74c643b View commit details
    Browse the repository at this point in the history

Commits on Sep 24, 2024

  1. Configuration menu
    Copy the full SHA
    c570faf View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    539ac54 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    bddee6e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    ad43a38 View commit details
    Browse the repository at this point in the history
  5. refactor: RBF fixtures

    Legend101Zz committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    e8105cb View commit details
    Browse the repository at this point in the history

Commits on Sep 27, 2024

  1. minor changes : Transaction Analyzer - RBF FEE CALCULATION COMMENTS .…

    ….. REMOVED UNUSED VARIABLES
    Legend101Zz committed Sep 27, 2024
    Configuration menu
    Copy the full SHA
    7150a01 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a44bedc View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    663df1e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    09fba1f View commit details
    Browse the repository at this point in the history

Commits on Oct 9, 2024

  1. changes: README

    Legend101Zz committed Oct 9, 2024
    Configuration menu
    Copy the full SHA
    90b3227 View commit details
    Browse the repository at this point in the history