From b8cbddf77828b81687016a882be32b757754db7c Mon Sep 17 00:00:00 2001 From: Martin Saldinger <51637671+LeTamanoir@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:26:56 +0100 Subject: [PATCH] add BTC token (#179) * add BTC * bump version * add convertor --- package.json | 2 +- src/fireblocks_signer.ts | 3 ++- src/utils.ts | 50 ++++++++++++++++++++++++++++++++-------- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 1c3e180..8c7de9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kilnfi/sdk", - "version": "4.0.2", + "version": "4.0.3", "autor": "Kiln (https://kiln.fi)", "license": "BUSL-1.1", "description": "JavaScript sdk for Kiln API", diff --git a/src/fireblocks_signer.ts b/src/fireblocks_signer.ts index 65bf510..13d4461 100644 --- a/src/fireblocks_signer.ts +++ b/src/fireblocks_signer.ts @@ -40,7 +40,8 @@ export type FireblocksAssetId = | 'TON_TEST' | 'TON' | 'KAVA_KAVA' - | 'TRX'; + | 'TRX' + | 'BTC'; export class FireblocksSigner { protected fireblocks: FireblocksSDK; diff --git a/src/utils.ts b/src/utils.ts index 5c4ed91..df9b1d7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -148,6 +148,20 @@ export const uunitToUnit = (uunit: bigint): string => { return formatUnits(uunit, 6); }; +/** + * Convert Satoshi to BTC + */ +export const satToBtc = (sat: bigint): string => { + return formatUnits(sat, 8); +}; + +/** + * Convert BTC to Satoshi + */ +export const btcToSat = (btc: string): bigint => { + return parseUnits(btc, 8); +}; + /** * Convert uOSMO to OSMO */ @@ -219,47 +233,65 @@ export const compressPublicKey = (pubkey: string): string => { return compressed_key.toString('hex'); }; -// Convert ATOM to uATOM +/** + * Convert ATOM to uATOM + */ export const atomToUatom = (atom: string): bigint => { return parseUnits(atom, 6); }; -// Convert DYDX to adydx +/** + * Convert DYDX to adydx + */ export const dydxToAdydx = (dydx: string): bigint => { return parseUnits(dydx, 18); // adydx uses 18 decimals }; -// Convert ZETA to azeta +/** + * Convert ZETA to azeta + */ export const zetaToAzeta = (zeta: string): bigint => { return parseUnits(zeta, 18); // azeta uses 18 decimals }; -// Convert OSMO to uosmo +/** + * Convert OSMO to uosmo + */ export const osmoToUosmo = (osmo: string): bigint => { return parseUnits(osmo, 6); }; -// Convert INJ to inj +/** + * Convert INJ to inj + */ export const injToInj = (inj: string): bigint => { return parseUnits(inj, 18); // inj uses 18 decimals }; -// Convert TIA to utia +/** + * Convert TIA to utia + */ export const tiaToUtia = (tia: string): bigint => { return parseUnits(tia, 6); }; -// Convert FET to afet +/** + * Convert FET to afet + */ export const fetToAfet = (fet: string): bigint => { return parseUnits(fet, 18); // afet uses 18 decimals }; -// Convert TRX to sun +/** + * Convert TRX to sun + */ export const trxToSun = (trx: string): bigint => { return parseUnits(trx, 6); }; -// Convert sun to TRX +/** + * Convert sun to TRX + */ export const sunToTrx = (trx: bigint): string => { return formatUnits(trx, 6); };