From fac5856f6b83801f0b31ef547454c89d5d54bcea Mon Sep 17 00:00:00 2001 From: Arno Simon Date: Wed, 17 Apr 2024 17:51:00 +0200 Subject: [PATCH] fix bigint conversions (#99) --- package.json | 2 +- src/services/ada.ts | 3 ++- src/services/atom.ts | 3 ++- src/services/dot.ts | 5 +++-- src/services/dydx.ts | 5 +++-- src/services/fet.ts | 3 ++- src/services/inj.ts | 3 ++- src/services/noble.ts | 3 ++- src/services/osmo.ts | 3 ++- src/services/sol.ts | 3 ++- src/services/tia.ts | 3 ++- src/services/xtz.ts | 3 ++- 12 files changed, 25 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 64fd0dc..2370cb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kilnfi/sdk", - "version": "2.14.1", + "version": "2.14.2", "autor": "Kiln (https://kiln.fi)", "license": "BUSL-1.1", "description": "JavaScript sdk for Kiln API", diff --git a/src/services/ada.ts b/src/services/ada.ts index 0525e7d..bbfbb6e 100644 --- a/src/services/ada.ts +++ b/src/services/ada.ts @@ -13,6 +13,7 @@ import api from "../api"; import { ServiceProps } from "../types/service"; import { Integration } from "../types/integrations"; import { TransactionJSON } from "@emurgo/cardano-serialization-lib-nodejs"; +import { parseUnits } from "viem"; export class AdaService extends Service { constructor({ testnet }: ServiceProps) { @@ -63,7 +64,7 @@ export class AdaService extends Service { * @param amountAda */ adaToLovelace(amountAda: string): string { - return (BigInt(amountAda) * BigInt(10 ** 6)).toString(); + return parseUnits(amountAda, 6).toString(); } /** diff --git a/src/services/atom.ts b/src/services/atom.ts index b6b5f17..b7a3736 100644 --- a/src/services/atom.ts +++ b/src/services/atom.ts @@ -6,6 +6,7 @@ import { Integration } from "../types/integrations"; import api from "../api"; import { DecodedTxRaw } from "@cosmjs/proto-signing"; import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos"; +import { parseUnits } from "viem"; export class AtomService extends Service { constructor({ testnet }: ServiceProps) { @@ -17,7 +18,7 @@ export class AtomService extends Service { * @param amountAtom */ atomToUatom(amountAtom: string): string { - return (BigInt(amountAtom) * BigInt(10 ** 6)).toString(); + return parseUnits(amountAtom, 6).toString(); } /** diff --git a/src/services/dot.ts b/src/services/dot.ts index 85b4dc2..566e30f 100644 --- a/src/services/dot.ts +++ b/src/services/dot.ts @@ -4,6 +4,7 @@ import { ServiceProps } from "../types/service"; import { Integration } from "../types/integrations"; import api from "../api"; import { UnsignedTransaction } from "@substrate/txwrapper-polkadot"; +import { parseUnits } from "viem"; /** * Staking docs: https://polkadot.js.org/docs/substrate/extrinsics#staking @@ -20,7 +21,7 @@ export class DotService extends Service { * @param amountWnd */ wndToPlanck(amountWnd: string): string { - return (BigInt(amountWnd) * BigInt(10 ** 12)).toString(); + return parseUnits(amountWnd, 12).toString(); } /** @@ -29,7 +30,7 @@ export class DotService extends Service { * @param amountDot */ dotToPlanck(amountDot: string): string { - return (BigInt(amountDot) * BigInt(10 ** 10)).toString(); + return parseUnits(amountDot, 10).toString(); } /** diff --git a/src/services/dydx.ts b/src/services/dydx.ts index 0d3f8db..6a3d4dc 100644 --- a/src/services/dydx.ts +++ b/src/services/dydx.ts @@ -5,6 +5,7 @@ import { Integration } from "../types/integrations"; import api from "../api"; import { DecodedTxRaw } from "@cosmjs/proto-signing"; import { Balance, CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos"; +import { parseUnits } from "viem"; export class DydxService extends Service { constructor({ testnet }: ServiceProps) { @@ -16,11 +17,11 @@ export class DydxService extends Service { * @param amountDydx */ dydxToAdydx(amountDydx: string): string { - return (BigInt(amountDydx) * BigInt(10 ** 18)).toString(); + return parseUnits(amountDydx, 18).toString(); } usdcToUusdc(amountUsdc: string): string { - return (BigInt(amountUsdc) * BigInt(10 ** 6)).toString(); + return parseUnits(amountUsdc, 6).toString(); } /** diff --git a/src/services/fet.ts b/src/services/fet.ts index 11b975e..f3fe083 100644 --- a/src/services/fet.ts +++ b/src/services/fet.ts @@ -6,6 +6,7 @@ import api from "../api"; import { DecodedTxRaw } from "@cosmjs/proto-signing"; import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos"; import { SigningAlgorithm } from "fireblocks-sdk"; +import { parseUnits } from "viem"; export class FetService extends Service { constructor({ testnet }: ServiceProps) { @@ -17,7 +18,7 @@ export class FetService extends Service { * @param amountFet */ fetToAfet(amountFet: string): string { - return (BigInt(amountFet) * BigInt(10 ** 18)).toString(); + return parseUnits(amountFet, 18).toString(); } /** diff --git a/src/services/inj.ts b/src/services/inj.ts index b6c8c63..858b4a5 100644 --- a/src/services/inj.ts +++ b/src/services/inj.ts @@ -5,6 +5,7 @@ import { Integration } from "../types/integrations"; import api from "../api"; import { DecodedTxRaw } from "@cosmjs/proto-signing"; import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos"; +import { parseUnits } from "viem"; export class InjService extends Service { constructor({ testnet }: ServiceProps) { @@ -16,7 +17,7 @@ export class InjService extends Service { * @param amount */ injToAinj(amount: string): string { - return (BigInt(amount) * BigInt(10 ** 18)).toString(); + return parseUnits(amount, 18).toString(); } /** diff --git a/src/services/noble.ts b/src/services/noble.ts index 9b41525..ed6d10b 100644 --- a/src/services/noble.ts +++ b/src/services/noble.ts @@ -5,6 +5,7 @@ import { Integration } from "../types/integrations"; import api from "../api"; import { DecodedTxRaw } from "@cosmjs/proto-signing"; import { Balance, CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos"; +import { parseUnits } from "viem"; export class NobleService extends Service { constructor({ testnet }: ServiceProps) { @@ -12,7 +13,7 @@ export class NobleService extends Service { } usdcToUusdc(amountUsdc: string): string { - return (BigInt(amountUsdc) * BigInt(10 ** 6)).toString(); + return parseUnits(amountUsdc, 6).toString(); } /** diff --git a/src/services/osmo.ts b/src/services/osmo.ts index 7f086b5..50ea7ff 100644 --- a/src/services/osmo.ts +++ b/src/services/osmo.ts @@ -6,6 +6,7 @@ import { Integration } from "../types/integrations"; import api from "../api"; import { DecodedTxRaw } from "@cosmjs/proto-signing"; import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos"; +import { parseUnits } from "viem"; export class OsmoService extends Service { constructor({ testnet }: ServiceProps) { @@ -17,7 +18,7 @@ export class OsmoService extends Service { * @param amountOsmo */ osmoToUosmo(amountOsmo: string): string { - return (BigInt(amountOsmo) * BigInt(10 ** 6)).toString(); + return parseUnits(amountOsmo, 6).toString(); } /** diff --git a/src/services/sol.ts b/src/services/sol.ts index 673d237..86559fb 100644 --- a/src/services/sol.ts +++ b/src/services/sol.ts @@ -4,6 +4,7 @@ import { SolNetworkStats, SolRewards, SolSignedTx, SolStakes, SolTx, SolTxHash, import { Service } from "./service"; import { ServiceProps } from "../types/service"; import { Integration } from "../types/integrations"; +import { parseUnits } from "viem"; export class SolService extends Service { constructor({ testnet }: ServiceProps) { @@ -257,6 +258,6 @@ export class SolService extends Service { * @param sol */ solToLamports(sol: string): string { - return (BigInt(sol) * BigInt(LAMPORTS_PER_SOL)).toString(); + return parseUnits(sol, 9).toString(); } } diff --git a/src/services/tia.ts b/src/services/tia.ts index a06b4a6..661369d 100644 --- a/src/services/tia.ts +++ b/src/services/tia.ts @@ -5,6 +5,7 @@ import { Integration } from "../types/integrations"; import api from "../api"; import { DecodedTxRaw } from "@cosmjs/proto-signing"; import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos"; +import { parseUnits } from "viem"; export class TiaService extends Service { constructor({ testnet }: ServiceProps) { @@ -16,7 +17,7 @@ export class TiaService extends Service { * @param amountTia */ tiaToUtia(amountTia: string): string { - return (BigInt(amountTia) * BigInt(10 ** 6)).toString(); + return parseUnits(amountTia, 6).toString(); } /** diff --git a/src/services/xtz.ts b/src/services/xtz.ts index 6c662fa..c893e87 100644 --- a/src/services/xtz.ts +++ b/src/services/xtz.ts @@ -4,6 +4,7 @@ import { XtzNetworkStats, XtzRewards, XtzSignedTx, XtzStakes, XtzTx, XtzTxHash, import { ServiceProps } from "../types/service"; import { Integration } from "../types/integrations"; import { ForgeParams } from "@taquito/local-forging"; +import { parseUnits } from "viem"; export class XtzService extends Service { constructor({ testnet }: ServiceProps) { @@ -160,6 +161,6 @@ export class XtzService extends Service { * @param xtz */ xtzToMutez(xtz: string): string { - return (BigInt(xtz) * BigInt(10 ** 6)).toString(); + return parseUnits(xtz, 6).toString(); } }