2.6.8 • Published 4 months ago

dlc-btc-lib v2.6.8

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

dlc-btc-lib

dlc-btc-lib is a comprehensive library for interacting with DLC.Link smart contracts and the Bitcoin blockchain. It includes functions for creating valid Partially Signed Bitcoin Transactions, handling setup, deposit, and withdrawal interactions, and interfacing with Attestors. This library provides all the essential tools and utilities for seamless blockchain and smart contract interactions.

Fee Rate Calculation

The transaction fee rate is calculated by taking the maximum value among three metrics from the Bitcoin blockchain:

  • Average fee rate from the last two blocks /api/v1/mining/blocks/fee-rates/24h
  • Current mempool block's median fee rate /api/v1/fees/mempool-blocks
  • Recommended "fastest" fee rate by API /api/v1/fees/recommended

Each metric is adjusted by an optional multiplier (defaults to 1.0) and the final result is rounded up to the nearest whole number. For regtest environments, a fixed fee rate of 2 is used.

Proof of Reserve Calculation

The Proof of Reserve system verifies and calculates the total value of Bitcoin deposits across all vaults. This is handled by the ProofOfReserveHandler class which:

  1. Takes a list of vaults and verifies each vault's deposit by:

    • Checking for valid transaction IDs (either funding or withdraw-deposit)
    • Fetching the transaction from the Bitcoin blockchain
    • Verifying the transaction has sufficient confirmations
    • For transactions with insufficient confirmations that represent deposit-more or withdraw transactions (those spending a previous vault UTXO), the system returns the value of the input corresponding to the vault's multisig address
    • For confirmed transactions, the system identifies and returns the value of the output matching the vault's multisig script
  2. Aggregates the verified deposit values to determine the total Bitcoin reserves

The handler requires:

  • Bitcoin blockchain API endpoint for transaction lookups
  • Bitcoin network object (mainnet/testnet/regtest)
  • Extended public key of the attestor group for validating vault payments

Example usage:

import { RawVault } from './models/ethereum-models';
import { testnet } from 'bitcoinjs-lib/src/networks.js';
import { ProofOfReserveHandler } from './proof-of-reserve-handlers/proof-of-reserve-handler';

const vaults: RawVault[] = [...];

const extendedAttestorGroupPublicKey = 'tpubDDRekL64eJJav32TLhNhG59qra7wAMaei8YMGXNiJE8ksdYrKgvaFM1XG6JrSt31W97XryScrX37RUEujjZT4qScNf8Zu1JxWj4VYkwz4rU';
const bitcoinBlockchainAPI = 'https://testnet.dlc.link/electrs';
const bitcoinNetwork = testnet;

// Instantiate the Proof of Reserve handler
const proofOfReserveHandler = new ProofOfReserveHandler(bitcoinBlockchainAPI, bitcoinNetwork, extendedAttestorGroupPublicKey);

// Function to calculate and verify reserves
async function calculateAndVerifyReserves() {
  try {
    const totalReservesInSats = await proofOfReserveHandler.calculateProofOfReserve(vaults);
    console.log(`Total reserves in satoshis: ${totalReservesInSats}`);
  } catch (error) {
    console.error('Error calculating reserves:', error);
  }
}
2.6.8

4 months ago

2.6.7

4 months ago

2.6.5

4 months ago

2.6.3

5 months ago

2.6.2

5 months ago

2.6.4

5 months ago

2.6.1

5 months ago

2.6.0

5 months ago

2.5.17

5 months ago

2.5.14

5 months ago

2.5.15

5 months ago

2.5.16

5 months ago

2.5.12

5 months ago

2.5.13

5 months ago

2.5.8

6 months ago

2.5.9

6 months ago

2.5.6

6 months ago

2.5.7

6 months ago

2.5.5

6 months ago

2.5.4

7 months ago

2.5.3

7 months ago

2.5.2

7 months ago

2.5.1

7 months ago

2.4.19

8 months ago

2.4.19-dfns-beta

8 months ago

2.4.21

7 months ago

2.4.20

7 months ago

2.4.18

8 months ago

2.4.17

8 months ago

2.4.14

8 months ago

2.4.13

8 months ago

2.4.15

8 months ago

2.4.12

8 months ago

2.4.10

9 months ago

2.4.11

9 months ago

2.4.9

9 months ago

2.4.8

9 months ago

2.4.7

9 months ago

2.4.1

9 months ago

2.4.3

9 months ago

2.4.2

9 months ago

2.4.5

9 months ago

2.4.4

9 months ago

2.4.6

9 months ago

2.4.0

9 months ago

2.3.0

9 months ago

2.2.5

11 months ago

2.2.7

10 months ago

2.2.6

10 months ago

2.2.10

9 months ago

2.2.9

9 months ago

2.2.8

10 months ago

2.2.3

11 months ago

2.2.4

11 months ago

2.1.2

12 months ago

2.1.1

12 months ago

2.1.0

12 months ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.22

12 months ago

1.0.21

1 year ago

1.0.20

1 year ago

2.0.0

12 months ago

1.0.11

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago