Skip to content

Commit

Permalink
fix bigint conversions (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
nooxx authored Apr 17, 2024
1 parent b575f5b commit fac5856
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kilnfi/sdk",
"version": "2.14.1",
"version": "2.14.2",
"autor": "Kiln <[email protected]> (https://kiln.fi)",
"license": "BUSL-1.1",
"description": "JavaScript sdk for Kiln API",
Expand Down
3 changes: 2 additions & 1 deletion src/services/ada.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/services/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

/**
Expand All @@ -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();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/services/dydx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/fet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/inj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/noble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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) {
super({ testnet });
}

usdcToUusdc(amountUsdc: string): string {
return (BigInt(amountUsdc) * BigInt(10 ** 6)).toString();
return parseUnits(amountUsdc, 6).toString();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/osmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
}
3 changes: 2 additions & 1 deletion src/services/tia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/xtz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
}

0 comments on commit fac5856

Please sign in to comment.