|
1 | | -import { formatEther, formatUnits, parseUnits } from 'viem'; |
| 1 | +import { formatUnits, parseUnits } from 'viem'; |
2 | 2 |
|
3 | | -// Convert wei to ETH |
| 3 | +/** |
| 4 | + * Convert wei to ETH |
| 5 | + */ |
4 | 6 | export const weiToEth = (wei: bigint): string => { |
5 | | - return formatEther(BigInt(wei)); |
| 7 | + return formatUnits(wei, 18); |
6 | 8 | }; |
7 | 9 |
|
8 | | -// Convert wei to POL |
| 10 | +/** |
| 11 | + * Convert wei to POL |
| 12 | + */ |
9 | 13 | export const weiToPol = (wei: bigint): string => { |
10 | 14 | return formatUnits(wei, 18); |
11 | 15 | }; |
12 | 16 |
|
13 | | -// Convert lamports to SOL |
| 17 | +/** |
| 18 | + * Convert lamports to SOL |
| 19 | + */ |
14 | 20 | export const lamportsToSol = (lamports: bigint): string => { |
15 | 21 | return formatUnits(lamports, 9); |
16 | 22 | }; |
17 | 23 |
|
18 | | -// Convert SOL to lamports |
| 24 | +/** |
| 25 | + * Convert SOL to lamports |
| 26 | + */ |
19 | 27 | export const solToLamports = (sol: string): bigint => { |
20 | 28 | return parseUnits(sol, 9); |
21 | 29 | }; |
22 | 30 |
|
23 | | -// Convert XTZ to mutez |
| 31 | +/** |
| 32 | + * Convert XTZ to mutez |
| 33 | + */ |
24 | 34 | export const xtzToMutez = (xtz: string): bigint => { |
25 | 35 | return parseUnits(xtz, 6); |
26 | 36 | }; |
27 | 37 |
|
28 | | -// Convert Cardano lovelace to ADA |
| 38 | +/** |
| 39 | + * Convert Cardano lovelace to ADA |
| 40 | + */ |
29 | 41 | export const lovelaceToAda = (lovelace: bigint): string => { |
30 | 42 | return formatUnits(lovelace, 6); |
31 | 43 | }; |
32 | 44 |
|
33 | | -// Converts yocto to NEAR |
| 45 | +/** |
| 46 | + * Converts yocto to NEAR |
| 47 | + */ |
34 | 48 | export const yoctoToNear = (yocto: bigint): string => { |
35 | 49 | return formatUnits(yocto, 24); |
36 | 50 | }; |
37 | 51 |
|
38 | | -// Convert nanoTON to TON |
| 52 | +/** |
| 53 | + * Convert nanoTON to TON |
| 54 | + */ |
39 | 55 | export const nanotonToTon = (nanoton: bigint): string => { |
40 | 56 | return formatUnits(nanoton, 9); |
41 | 57 | }; |
42 | 58 |
|
43 | | -// Convert uZETA to ZETA |
| 59 | +/** |
| 60 | + * Convert uZETA to ZETA |
| 61 | + */ |
44 | 62 | export const uzetaToZeta = (uzeta: bigint): string => { |
45 | 63 | return formatUnits(uzeta, 6); |
46 | 64 | }; |
47 | 65 |
|
48 | | -// Convert uINJ to INJ |
| 66 | +/** |
| 67 | + * Convert uINJ to INJ |
| 68 | + */ |
49 | 69 | export const uinjToInj = (uinj: bigint): string => { |
50 | 70 | return formatUnits(uinj, 6); |
51 | 71 | }; |
52 | 72 |
|
53 | | -// Convert aFET to FET |
| 73 | +/** |
| 74 | + * Convert aFET to FET |
| 75 | + */ |
54 | 76 | export const afetToFet = (afet: bigint): string => { |
55 | 77 | return formatUnits(afet, 18); |
56 | 78 | }; |
57 | 79 |
|
58 | | -// Convert uFET to FET |
| 80 | +/** |
| 81 | + * Convert uFET to FET |
| 82 | + */ |
59 | 83 | export const ufetToFet = (ufet: bigint): string => { |
60 | 84 | return formatUnits(ufet, 6); |
61 | 85 | }; |
62 | 86 |
|
63 | | -// Convert mutez to XTZ |
| 87 | +/** |
| 88 | + * Convert mutez to XTZ |
| 89 | + */ |
64 | 90 | export const mutezToXtz = (mutez: bigint): string => { |
65 | 91 | return formatUnits(mutez, 6); |
66 | 92 | }; |
67 | 93 |
|
68 | | -// Convert uDYDX to DYDX |
| 94 | +/** |
| 95 | + * Convert uDYDX to DYDX |
| 96 | + */ |
69 | 97 | export const udydxToDydx = (udydx: bigint): string => { |
70 | 98 | return formatUnits(udydx, 6); |
71 | 99 | }; |
72 | 100 |
|
73 | | -// Convert planck to DOT |
| 101 | +/** |
| 102 | + * Convert planck to DOT |
| 103 | + */ |
74 | 104 | export const planckToDot = (planck: bigint): string => { |
75 | 105 | return formatUnits(planck, 10); |
76 | 106 | }; |
77 | 107 |
|
78 | | -// Convert planck to KSM |
| 108 | +/** |
| 109 | + * Convert planck to KSM |
| 110 | + */ |
79 | 111 | export const planckToKsm = (planck: bigint): string => { |
80 | 112 | return formatUnits(planck, 12); |
81 | 113 | }; |
82 | 114 |
|
83 | | -// Convert uATOM to ATOM |
| 115 | +/** |
| 116 | + * Convert uATOM to ATOM |
| 117 | + */ |
84 | 118 | export const uatomToAtom = (uatom: bigint): string => { |
85 | 119 | return formatUnits(uatom, 6); |
86 | 120 | }; |
87 | 121 |
|
88 | | -// Convert u{Cosmos chain token: ATOM, OSMO, etc...} to {Cosmos chain token: ATOM, OSMO, etc...} |
| 122 | +/** |
| 123 | + * Convert u{Cosmos chain token: ATOM, OSMO, etc...} to {Cosmos chain token: ATOM, OSMO, etc...} |
| 124 | + */ |
89 | 125 | export const uunitToUnit = (uunit: bigint): string => { |
90 | 126 | return formatUnits(uunit, 6); |
91 | 127 | }; |
92 | 128 |
|
93 | | -// Convert uOSMO to OSMO |
| 129 | +/** |
| 130 | + * Convert uOSMO to OSMO |
| 131 | + */ |
94 | 132 | export const uosmoToOsmo = (uosmo: bigint): string => { |
95 | 133 | return formatUnits(uosmo, 6); |
96 | 134 | }; |
97 | 135 |
|
98 | | -// Convert uTIA to TIA |
| 136 | +/** |
| 137 | + * Convert uTIA to TIA |
| 138 | + */ |
99 | 139 | export const utiaToTia = (utia: bigint): string => { |
100 | 140 | return formatUnits(utia, 6); |
101 | 141 | }; |
102 | 142 |
|
103 | | -// Convert uusdc to USDC |
| 143 | +/** |
| 144 | + * Convert uusdc to USDC |
| 145 | + */ |
104 | 146 | export const uusdcToUsdc = (uusdc: bigint): string => { |
105 | 147 | return formatUnits(uusdc, 6); |
106 | 148 | }; |
| 149 | + |
| 150 | +/** |
| 151 | + * Convert uKAVA to KAVA |
| 152 | + */ |
| 153 | +export const ukavaToKava = (ukava: bigint): string => { |
| 154 | + return formatUnits(ukava, 6); |
| 155 | +}; |
0 commit comments