Skip to content

Commit fac5856

Browse files
authored
fix bigint conversions (#99)
1 parent b575f5b commit fac5856

File tree

12 files changed

+25
-14
lines changed

12 files changed

+25
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kilnfi/sdk",
3-
"version": "2.14.1",
3+
"version": "2.14.2",
44
"autor": "Kiln <[email protected]> (https://kiln.fi)",
55
"license": "BUSL-1.1",
66
"description": "JavaScript sdk for Kiln API",

src/services/ada.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import api from "../api";
1313
import { ServiceProps } from "../types/service";
1414
import { Integration } from "../types/integrations";
1515
import { TransactionJSON } from "@emurgo/cardano-serialization-lib-nodejs";
16+
import { parseUnits } from "viem";
1617

1718
export class AdaService extends Service {
1819
constructor({ testnet }: ServiceProps) {
@@ -63,7 +64,7 @@ export class AdaService extends Service {
6364
* @param amountAda
6465
*/
6566
adaToLovelace(amountAda: string): string {
66-
return (BigInt(amountAda) * BigInt(10 ** 6)).toString();
67+
return parseUnits(amountAda, 6).toString();
6768
}
6869

6970
/**

src/services/atom.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Integration } from "../types/integrations";
66
import api from "../api";
77
import { DecodedTxRaw } from "@cosmjs/proto-signing";
88
import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";
9+
import { parseUnits } from "viem";
910

1011
export class AtomService extends Service {
1112
constructor({ testnet }: ServiceProps) {
@@ -17,7 +18,7 @@ export class AtomService extends Service {
1718
* @param amountAtom
1819
*/
1920
atomToUatom(amountAtom: string): string {
20-
return (BigInt(amountAtom) * BigInt(10 ** 6)).toString();
21+
return parseUnits(amountAtom, 6).toString();
2122
}
2223

2324
/**

src/services/dot.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ServiceProps } from "../types/service";
44
import { Integration } from "../types/integrations";
55
import api from "../api";
66
import { UnsignedTransaction } from "@substrate/txwrapper-polkadot";
7+
import { parseUnits } from "viem";
78

89
/**
910
* Staking docs: https://polkadot.js.org/docs/substrate/extrinsics#staking
@@ -20,7 +21,7 @@ export class DotService extends Service {
2021
* @param amountWnd
2122
*/
2223
wndToPlanck(amountWnd: string): string {
23-
return (BigInt(amountWnd) * BigInt(10 ** 12)).toString();
24+
return parseUnits(amountWnd, 12).toString();
2425
}
2526

2627
/**
@@ -29,7 +30,7 @@ export class DotService extends Service {
2930
* @param amountDot
3031
*/
3132
dotToPlanck(amountDot: string): string {
32-
return (BigInt(amountDot) * BigInt(10 ** 10)).toString();
33+
return parseUnits(amountDot, 10).toString();
3334
}
3435

3536
/**

src/services/dydx.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Integration } from "../types/integrations";
55
import api from "../api";
66
import { DecodedTxRaw } from "@cosmjs/proto-signing";
77
import { Balance, CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";
8+
import { parseUnits } from "viem";
89

910
export class DydxService extends Service {
1011
constructor({ testnet }: ServiceProps) {
@@ -16,11 +17,11 @@ export class DydxService extends Service {
1617
* @param amountDydx
1718
*/
1819
dydxToAdydx(amountDydx: string): string {
19-
return (BigInt(amountDydx) * BigInt(10 ** 18)).toString();
20+
return parseUnits(amountDydx, 18).toString();
2021
}
2122

2223
usdcToUusdc(amountUsdc: string): string {
23-
return (BigInt(amountUsdc) * BigInt(10 ** 6)).toString();
24+
return parseUnits(amountUsdc, 6).toString();
2425
}
2526

2627
/**

src/services/fet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import api from "../api";
66
import { DecodedTxRaw } from "@cosmjs/proto-signing";
77
import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";
88
import { SigningAlgorithm } from "fireblocks-sdk";
9+
import { parseUnits } from "viem";
910

1011
export class FetService extends Service {
1112
constructor({ testnet }: ServiceProps) {
@@ -17,7 +18,7 @@ export class FetService extends Service {
1718
* @param amountFet
1819
*/
1920
fetToAfet(amountFet: string): string {
20-
return (BigInt(amountFet) * BigInt(10 ** 18)).toString();
21+
return parseUnits(amountFet, 18).toString();
2122
}
2223

2324
/**

src/services/inj.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Integration } from "../types/integrations";
55
import api from "../api";
66
import { DecodedTxRaw } from "@cosmjs/proto-signing";
77
import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";
8+
import { parseUnits } from "viem";
89

910
export class InjService extends Service {
1011
constructor({ testnet }: ServiceProps) {
@@ -16,7 +17,7 @@ export class InjService extends Service {
1617
* @param amount
1718
*/
1819
injToAinj(amount: string): string {
19-
return (BigInt(amount) * BigInt(10 ** 18)).toString();
20+
return parseUnits(amount, 18).toString();
2021
}
2122

2223
/**

src/services/noble.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { Integration } from "../types/integrations";
55
import api from "../api";
66
import { DecodedTxRaw } from "@cosmjs/proto-signing";
77
import { Balance, CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";
8+
import { parseUnits } from "viem";
89

910
export class NobleService extends Service {
1011
constructor({ testnet }: ServiceProps) {
1112
super({ testnet });
1213
}
1314

1415
usdcToUusdc(amountUsdc: string): string {
15-
return (BigInt(amountUsdc) * BigInt(10 ** 6)).toString();
16+
return parseUnits(amountUsdc, 6).toString();
1617
}
1718

1819
/**

src/services/osmo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Integration } from "../types/integrations";
66
import api from "../api";
77
import { DecodedTxRaw } from "@cosmjs/proto-signing";
88
import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";
9+
import { parseUnits } from "viem";
910

1011
export class OsmoService extends Service {
1112
constructor({ testnet }: ServiceProps) {
@@ -17,7 +18,7 @@ export class OsmoService extends Service {
1718
* @param amountOsmo
1819
*/
1920
osmoToUosmo(amountOsmo: string): string {
20-
return (BigInt(amountOsmo) * BigInt(10 ** 6)).toString();
21+
return parseUnits(amountOsmo, 6).toString();
2122
}
2223

2324
/**

src/services/sol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { SolNetworkStats, SolRewards, SolSignedTx, SolStakes, SolTx, SolTxHash,
44
import { Service } from "./service";
55
import { ServiceProps } from "../types/service";
66
import { Integration } from "../types/integrations";
7+
import { parseUnits } from "viem";
78

89
export class SolService extends Service {
910
constructor({ testnet }: ServiceProps) {
@@ -257,6 +258,6 @@ export class SolService extends Service {
257258
* @param sol
258259
*/
259260
solToLamports(sol: string): string {
260-
return (BigInt(sol) * BigInt(LAMPORTS_PER_SOL)).toString();
261+
return parseUnits(sol, 9).toString();
261262
}
262263
}

0 commit comments

Comments
 (0)