UNPKG

@faktoryfun/styx-sdk

Version:

Bitcoin deposit SDK for Stacks applications, enabling trustless Bitcoin-to-sBTC deposits

105 lines (104 loc) 3.89 kB
// src/index.ts - Minimal changes with network and AI BTC pool support import { BitcoinDepositAPI } from "./api"; import { getApiUrl } from "./constants"; // Default API credentials const DEFAULT_API_KEY = "jc_e4d2e10396eef95215a7afd492f42d743a3325739d29200c2a28b256f778be01"; // Your existing StyxSDK class with minimal enhancements export class StyxSDK { constructor(baseUrl, apiKey = DEFAULT_API_KEY, network = "mainnet" // Default to mainnet, no auto-detection ) { this.network = network; const apiUrl = baseUrl || getApiUrl(network); this.api = new BitcoinDepositAPI(apiUrl, apiKey); } // =========================================== // NEW: Simple network info (optional) // =========================================== getCurrentNetwork() { return this.network; } // =========================================== // All your existing methods stay exactly the same // =========================================== async getFeeEstimates() { return this.api.getFeeEstimates(); } async updateDeposit(data) { return this.api.updateDeposit(data); } async getDepositHistory(userAddress) { return this.api.getDepositHistory(userAddress); } async getAllDepositsHistory(poolId) { return this.api.getAllDepositsHistory(poolId); } async prepareTransaction(params) { return this.api.prepareTransaction(params); } async createDeposit(params) { return this.api.createDeposit(params); } async updateDepositStatus(params) { return this.api.updateDepositStatus(params); } async executeTransaction(params) { return this.api.executeTransaction(params); } async getPoolStatus(poolId) { return this.api.getPoolStatus(poolId); } async getBTCPrice() { return this.api.getBTCPrice(); } async getDepositStatus(depositId) { return this.api.getDepositStatus(depositId); } async getDepositStatusByTxId(btcTxId) { return this.api.getDepositStatusByTxId(btcTxId); } // =========================================== // NEW: AI BTC pool specific methods (minimal additions) // =========================================== async getAvailablePools() { return this.api.getAvailablePools(); } async createAIBTCDeposit(data) { return this.api.createDeposit({ ...data, poolId: "aibtc", swapType: data.swapType || "aibtc", }); } async getAllowlistedPairs(poolId = "aibtc") { return this.api.getAllowlistedPairs(poolId); } async areSwapsPaused(poolId = "aibtc") { return this.api.areSwapsPaused(poolId); } async isDexPairAllowed(ftContract, dexContract, poolId = "aibtc") { try { const allowlistedPairs = await this.getAllowlistedPairs(poolId); return allowlistedPairs.some((pair) => pair.ftContract === ftContract && pair.dexContract === dexContract && pair.isActive); } catch (error) { console.error("Error checking DEX pair allowlist:", error); return false; } } } // =========================================== // Export instances (your existing pattern) // =========================================== // Default mainnet instance (your existing pattern) const sdk = new StyxSDK(); export const styxSDK = sdk; export default sdk; // Network-specific instances for convenience export const mainnetStyxSDK = new StyxSDK(undefined, DEFAULT_API_KEY, "mainnet"); export const testnetStyxSDK = new StyxSDK(undefined, DEFAULT_API_KEY, "testnet"); export const regtestStyxSDK = new StyxSDK(undefined, DEFAULT_API_KEY, "regtest"); export * from "./types"; export * from "./constants"; export { BitcoinDepositAPI } from "./api";