UNPKG

@ckboost/client

Version:

TypeScript/JavaScript SDK for dApps to integrate CKBoost - Fast ck-token transactions on Internet Computer through liquidity pools

243 lines (237 loc) 7.45 kB
import { Principal } from '@dfinity/principal'; import { ActorMethod } from '@dfinity/agent'; /** * Supported ck-tokens for CKBoost acceleration */ declare enum SupportedToken { ckTESTBTC = "ckTESTBTC" } /** * Token configuration with network-specific settings */ interface TokenConfig { token: SupportedToken; backendCanisterId: string; ledgerCanisterId: string; minimumAmount: string; maximumAmount: string; standardFee: string; confirmationsRequired: number; blockExplorerUrl: string; decimals: number; isTestnet: boolean; } /** * Predefined token configurations */ declare const TOKEN_CONFIGS: Record<SupportedToken, TokenConfig>; /** * Parameters for generating a deposit address */ interface DepositAddressParams { token: SupportedToken; amount: string; maxFeePercentage: number; confirmationsRequired?: number; preferredBooster?: string; } /** * Generated deposit address information */ interface DepositAddress { requestId: string; address: string; amount: string; amountRaw: string; maxFeePercentage: number; confirmationsRequired: number; explorerUrl: string; } /** * Boost request status (matches backend candid interface) */ declare enum BoostStatus$1 { PENDING = "pending",// Waiting for deposit ACTIVE = "active",// Transaction detected/being processed COMPLETED = "completed",// ck-tokens delivered to user CANCELLED = "cancelled" } /** * Detailed boost request information (matches backend BoostRequest type) */ interface BoostRequest$1 { id: string; status: BoostStatus$1; amount: string; amountRaw: string; maxFeePercentage: number; owner: string; booster?: string | undefined; preferredBooster?: string | undefined; depositAddress?: string | undefined; receivedAmount: string; confirmationsRequired: number; createdAt: number; updatedAt: number; explorerUrl: string; } /** * Client configuration options */ interface ClientConfig { host?: string; timeout?: number; } /** * Error types for better error handling */ declare enum CKBoostErrorType { NETWORK_ERROR = "NETWORK_ERROR", INVALID_AMOUNT = "INVALID_AMOUNT", INVALID_TOKEN = "INVALID_TOKEN", REQUEST_NOT_FOUND = "REQUEST_NOT_FOUND", REQUEST_EXPIRED = "REQUEST_EXPIRED", CANISTER_ERROR = "CANISTER_ERROR", VALIDATION_ERROR = "VALIDATION_ERROR" } /** * Structured error for CKBoost operations */ declare class CKBoostError extends Error { type: CKBoostErrorType; details?: any | undefined; constructor(type: CKBoostErrorType, message: string, details?: any | undefined); } /** * Response wrapper for API calls - discriminated union for better type safety */ type ApiResponse<T> = { success: true; data: T; } | { success: false; error: { type: CKBoostErrorType; message: string; details?: any; }; }; /** * Utility type for amount conversion */ interface AmountInfo { tokenAmount: string; rawAmount: string; formatted: string; } /** * ckTESTBTC Client for integrating CKBoost acceleration for ckTESTBTC * * Provides two main functions: * 1. generateDepositAddress - Creates a boost request and returns deposit info * 2. getBoostRequest - Gets detailed information about a boost request */ declare class ckTESTBTCClient { private agent; private backend; private config; private tokenConfig; constructor(config?: ClientConfig); /** * Generate a deposit address for a ckTESTBTC boost request * * This function: * 1. Validates the input parameters * 2. Calls registerBoostRequest on the backend * 3. Gets the deposit address for the request * 4. Returns formatted deposit information */ generateDepositAddress(params: Omit<DepositAddressParams, 'token'>): Promise<ApiResponse<DepositAddress>>; /** * Get detailed information about a ckTESTBTC boost request * * @param requestId - The boost request ID (as string) * @returns Detailed boost request information */ getBoostRequest(requestId: string): Promise<ApiResponse<BoostRequest$1>>; /** * Convert backend BoostStatus variant to our enum */ private convertBoostStatus; /** * Convert raw amount (bigint) to token amount string */ private rawToTokenAmount; /** * Utility method to get all pending ckTESTBTC boost requests */ getPendingBoostRequests(): Promise<ApiResponse<BoostRequest$1[]>>; /** * Get the ckTESTBTC token configuration */ getTokenConfig(): TokenConfig; } type Amount = bigint; type BoostId = bigint; interface BoostRequest { 'id' : BoostId, 'status' : BoostStatus, 'receivedBTC' : Amount, 'confirmationsRequired' : bigint, 'owner' : Principal, 'maxFeePercentage' : number, 'createdAt' : Timestamp, 'subaccount' : Subaccount, 'booster' : [] | [Principal], 'updatedAt' : Timestamp, 'btcAddress' : [] | [string], 'amount' : Amount, 'preferredBooster' : [] | [Principal], } type BoostStatus = { 'active' : null } | { 'cancelled' : null } | { 'pending' : null } | { 'completed' : null }; interface BoosterAccount { 'availableBalance' : Amount, 'owner' : Principal, 'createdAt' : Timestamp, 'subaccount' : Subaccount, 'updatedAt' : Timestamp, 'totalDeposited' : Amount, } interface Main { 'acceptBoostRequest' : ActorMethod<[BoostId], string>, 'checkBTCDeposit' : ActorMethod<[BoostId], Result>, 'getAllBoostRequests' : ActorMethod<[], Array<BoostRequest>>, 'getAllBoosterAccounts' : ActorMethod<[], Array<BoosterAccount>>, 'getBoostRequest' : ActorMethod<[BoostId], [] | [BoostRequest]>, 'getBoostRequestBTCAddress' : ActorMethod<[BoostId], Result_2>, 'getBoosterAccount' : ActorMethod<[Principal], [] | [BoosterAccount]>, 'getCanisterPrincipal' : ActorMethod<[], Principal>, 'getDirectBTCAddress' : ActorMethod<[], string>, 'getPendingBoostRequests' : ActorMethod<[], Array<BoostRequest>>, 'getUserBoostRequests' : ActorMethod<[Principal], Array<BoostRequest>>, 'registerBoostRequest' : ActorMethod< [Amount, number, bigint, [] | [Principal]], Result >, 'registerBoosterAccount' : ActorMethod<[], Result_1>, 'updateBoosterDeposit' : ActorMethod<[Principal, Amount], Result_1>, 'updateReceivedBTC' : ActorMethod<[BoostId, Amount], Result>, 'withdrawBoosterFunds' : ActorMethod<[Amount], string>, } type Result = { 'ok' : BoostRequest } | { 'err' : string }; type Result_1 = { 'ok' : BoosterAccount } | { 'err' : string }; type Result_2 = { 'ok' : string } | { 'err' : string }; type Subaccount = Uint8Array | number[]; type Timestamp = bigint; interface _SERVICE extends Main {} declare const ckTESTBTC_CANISTER_IDS: { readonly CKBOOST_BACKEND: "75egi-7qaaa-aaaao-qj6ma-cai"; readonly CKTESTBTC_LEDGER: "mc6ru-gyaaa-aaaar-qaaaq-cai"; }; export { type AmountInfo, type ApiResponse, type BoostRequest$1 as BoostRequest, BoostStatus$1 as BoostStatus, CKBoostError, CKBoostErrorType, type ClientConfig, type DepositAddress, type DepositAddressParams, SupportedToken, TOKEN_CONFIGS, type TokenConfig, type BoostRequest as ckTESTBTCBackendBoostRequest, type BoosterAccount as ckTESTBTCBoosterAccount, ckTESTBTCClient, type Result as ckTESTBTCResult, type Result_1 as ckTESTBTCResult_1, type _SERVICE as ckTESTBTCService, ckTESTBTC_CANISTER_IDS };