btc-wallet
Version:
BTC Wallet is a toolkit that enables Bitcoin usage on the NEAR blockchain through the Satoshi protocol.
113 lines (112 loc) • 4.53 kB
TypeScript
import type { ENV } from '../config';
import { checkBridgeTransactionStatus, calculateGasLimit, calculateGasStrategy } from '../utils/satoshi';
import type { FinalExecutionOutcome, Transaction } from '@near-wallet-selector/core';
export { calculateGasLimit, calculateGasStrategy, checkBridgeTransactionStatus };
type CheckGasTokenDebtReturnType<T extends boolean> = T extends true ? void : {
receiver_id: string;
amount: string;
msg: string;
} | undefined;
export declare function checkGasTokenDebt<T extends boolean>({ csna, btcAccount, env, autoDeposit, }: {
csna: string;
btcAccount: string;
env: ENV;
autoDeposit?: T;
}): Promise<CheckGasTokenDebtReturnType<T>>;
export declare function getBtcGasPrice(type?: 'fastest' | 'halfHour' | 'hour' | 'economy' | 'minimum'): Promise<number>;
export declare function getBtcUtxos(account: string): Promise<{
value: number;
status: {
confirmed: boolean;
};
}[]>;
export declare function calculateGasFee(account: string, amount: number, feeRate?: number): Promise<any>;
export declare function getBtcBalance(account?: string): Promise<{
rawBalance: number;
balance: number;
availableBalance: number;
}>;
export declare function sendBitcoin(address: string, amount: number, feeRate: number): Promise<string>;
export declare function getPublicKeyBase58(): Promise<any>;
export declare function getAddressByPublicKeyBase58(btcPublicKeyBase58: string): {
p2pkh: string | undefined;
p2sh: string | undefined;
p2wpkh: string | undefined;
p2wsh: string | undefined;
};
export declare function signMessage(message: string): Promise<{
signature: string;
publicKey: string;
}>;
/** estimate deposit receive amount, deduct protocol fee and repay amount */
export declare function estimateDepositAmount(amount: string, option?: {
env?: ENV;
}): Promise<string>;
export declare function getDepositAmount(amount: string, option?: {
csna?: string;
btcAccount?: string;
env?: ENV;
/** default is true, if true, new account minimum deposit amount 1000sat, otherwise 0 */
newAccountMinDepositAmount?: boolean;
}): Promise<{
depositAmount: number;
receiveAmount: number;
protocolFee: number;
repayAmount: string | number;
newAccountMinDepositAmount: number;
minDepositAmount: number;
}>;
export declare function getCsnaAccountId(env: ENV): Promise<string>;
export declare function checkNewAccount({ csna, btcAccount, env, }: {
csna?: string;
btcAccount?: string;
env?: ENV;
}): Promise<boolean>;
interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
action?: {
receiver_id: string;
amount: string;
msg: string;
};
amount?: string;
/** if registerDeposit is true, It will consume the deposit, otherwise it will be 0.000125 NEAR */
registerDeposit?: string;
feeRate?: number;
env?: ENV;
pollResult?: T;
newAccountMinDepositAmount?: boolean;
/** if registerContractId is provided, it will be used to register the contract, otherwise it will be the default contract id */
registerContractId?: string;
}
/**
* @param T - if true, return the poll result, otherwise return the btcTxHash
*/
type ExecuteBTCDepositAndActionReturn<T extends boolean> = T extends true ? FinalExecutionOutcome[] : string;
export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, pollResult, registerDeposit, env, newAccountMinDepositAmount, registerContractId, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
export declare function checkSatoshiWhitelist(btcAccountId: string, env?: ENV): Promise<void>;
interface WithdrawParams {
amount: string | number;
feeRate?: number;
csna?: string;
btcAddress?: string;
env?: ENV;
}
export declare function getWithdrawTransaction({ amount, feeRate, csna, btcAddress, env, }: WithdrawParams): Promise<Transaction>;
interface CalculateWithdrawParams {
amount: string | number;
feeRate?: number;
csna?: string;
btcAddress?: string;
env: ENV;
}
interface CalculateWithdrawResult {
withdrawFee: number;
gasFee?: number;
inputs?: any[];
outputs?: any[];
fromAmount?: number;
receiveAmount?: string;
isError: boolean;
errorMsg?: string;
}
export declare function calculateWithdraw({ amount, feeRate: _feeRate, csna: _csna, btcAddress: _btcAddress, env, }: CalculateWithdrawParams): Promise<CalculateWithdrawResult>;