npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitfi-market-maker-sdk

v1.1.9

Published

## Overview BitFi Market Maker SDK is a TypeScript library that provides a comprehensive interface for interacting with the BitFi trading platform. It facilitates token transfers across different blockchain networks, handles signature verification, and ma

Downloads

768

Readme

BitFi Market Maker SDK

Overview

BitFi Market Maker SDK is a TypeScript library that provides a comprehensive interface for interacting with the BitFi trading platform. It facilitates token transfers across different blockchain networks, handles signature verification, and manages trade settlements.

Installation

npm install bitfi-market-maker-sdk
# or
yarn add bitfi-market-maker-sdk

Features

  • Cross-chain token transfers (EVM and BTC networks)
  • Trade settlement management
  • Token information retrieval
  • Signature verification and generation
  • Router contract interactions
  • Advanced configuration management

Configuration

The SDK requires several environment variables to be set:

// Required Environment Variables
PMM_EVM_PRIVATE_KEY=<your-evm-private-key>
PMM_BTC_PRIVATE_KEY=<your-btc-private-key>
ROUTER_ADDRESS=<router-contract-address>

Core Services

1. Transfer Service

The TransferService handles token transfers across different blockchain networks.

import { transferService } from 'bitfi-market-maker-sdk';

// Example usage
await transferService.transfer({
  toAddress: '0x...',
  amount: BigInt('1000000000000000000'), // 1 token with 18 decimals
  networkId: 'ethereum-sepolia',
  tokenAddress: '0x...',
  tradeId: '0x...'
});

2. Token Service

The TokenService provides information about available tokens and their properties.

import { tokenService } from 'bitfi-market-maker-sdk';

// Get all available tokens
const tokens = await tokenService.getTokens();

// Get token by network and address
const token = await tokenService.getToken('ethereum-sepolia', '0x...');

// Get tokens for a specific network
const networkTokens = await tokenService.getTokensByNetwork('ethereum-sepolia');

3. Solver Service

The SolverService handles trade settlement submissions.

import { solverService } from 'bitfi-market-maker-sdk';

// Submit a single settlement
await solverService.submitSingleSettlement(
  'tradeId',
  'pmmId',
  'settlementTx',
  'signature'
);

// Submit batch settlements
await solverService.submitBatchSettlement(
  ['tradeId1', 'tradeId2'],
  'pmmId',
  'settlementTx',
  'signature'
);

4. Router Service

The RouterService provides interfaces for interacting with the BitFi router contract.

import { routerService } from 'bitfi-market-maker-sdk';

// Get protocol fee
const fee = await routerService.getProtocolFee(tradeId);

// Check if network is valid
const isValid = await routerService.isValidNetwork(networkId);

Supported Networks

EVM Networks

  • Ethereum (Mainnet)
  • Ethereum Sepolia
  • Base Sepolia

Bitcoin Networks

  • Bitcoin (Mainnet)
  • Bitcoin Testnet

Transfer Strategies

The SDK implements two main transfer strategies:

1. EVM Transfer Strategy

Handles transfers on EVM-compatible networks with features like:

  • Native token transfers
  • ERC20 token transfers
  • Protocol fee handling
  • Gas optimization

2. BTC Transfer Strategy

Manages Bitcoin transfers with features like:

  • UTXO management
  • Dynamic fee calculation
  • Transaction signing
  • OP_RETURN data inclusion

Signature Utilities

The SDK provides comprehensive signature utilities for various operations:

import { getSignature, SignatureType } from 'bitfi-market-maker-sdk';

// Generate signature
const signature = await getSignature(
  signer,
  provider,
  signerHelper,
  tradeId,
  infoHash,
  SignatureType.Presign
);

Error Handling

The SDK implements comprehensive error handling. All services throw typed errors that can be caught and handled appropriately:

try {
  await transferService.transfer({...});
} catch (error) {
  if (error instanceof Error) {
    console.error('Transfer failed:', error.message);
  }
}

Best Practices

  1. Always initialize services with proper configuration
  2. Handle errors appropriately
  3. Monitor transaction status after transfers
  4. Validate addresses and amounts before transfers
  5. Keep private keys secure
  6. Use appropriate network endpoints for different environments

Development Setup

# Install dependencies
npm install

# Generate TypeChain contracts
npm run typechain

# Generate index files
npm run ctix

# Build the package
npm run build

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License.