@indexing/jiti 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1689,6 +1689,59 @@ async function $cfe9a1176e32c0c3$export$77ffdf974cb300ec(storage, wallet) {
1689
1689
 
1690
1690
 
1691
1691
 
1692
+ // XRPL issued-currency codes are either a 3-char ISO-style code ("USD", "MAG") or a 160-bit
1693
+ // (40 hex char) value. Standard hex codes encode the ASCII symbol in the leading bytes (e.g.
1694
+ // "42495478…" -> "BITx"); non-standard codes (LP tokens, demurrage) aren't printable ASCII, so
1695
+ // we keep the raw hex for those.
1696
+ function $07b3982e2fc4c8b2$var$decodeXrplCurrency(currency) {
1697
+ if (!currency) return "UNKNOWN";
1698
+ if (!/^[0-9A-Fa-f]{40}$/.test(currency)) return currency;
1699
+ let decoded = "";
1700
+ for(let i = 0; i < currency.length; i += 2){
1701
+ const code = parseInt(currency.slice(i, i + 2), 16);
1702
+ if (code === 0) continue; // strip NUL padding
1703
+ decoded += String.fromCharCode(code);
1704
+ }
1705
+ // only use the decoded form if it's entirely printable ASCII; otherwise the hex is the identity
1706
+ return decoded && /^[\x20-\x7e]+$/.test(decoded) ? decoded : currency.toUpperCase();
1707
+ }
1708
+ // XRPL issued-currency amounts are arbitrary-precision decimal strings (up to 15 significant
1709
+ // digits, wide exponent range) with no fixed on-chain integer unit. Parse them losslessly into a
1710
+ // (mantissa, decimals) pair using string/BigInt math — NEVER parseFloat, which silently rounds
1711
+ // (the old `round(value * 1e6)` reported 0.00026764546195073 BITX as "268"). Handles plain and
1712
+ // scientific-notation values; trailing fractional zeros are trimmed so the scale is minimal.
1713
+ function $07b3982e2fc4c8b2$var$xrplIssuedValueToAmount(raw) {
1714
+ let s = (raw ?? "0").trim();
1715
+ let negative = false;
1716
+ if (s.startsWith("-")) {
1717
+ negative = true;
1718
+ s = s.slice(1);
1719
+ } else if (s.startsWith("+")) s = s.slice(1);
1720
+ let exponent = 0;
1721
+ const eIndex = s.search(/[eE]/);
1722
+ if (eIndex !== -1) {
1723
+ exponent = parseInt(s.slice(eIndex + 1), 10) || 0;
1724
+ s = s.slice(0, eIndex);
1725
+ }
1726
+ const [intPart = "", fracPart = ""] = s.split(".");
1727
+ let digits = (intPart + fracPart).replace(/^0+(?=\d)/, "") || "0";
1728
+ let decimals = fracPart.length - exponent;
1729
+ if (decimals < 0) {
1730
+ // value scales up past the integer point — append zeros and clamp to 0 decimals
1731
+ digits += "0".repeat(-decimals);
1732
+ decimals = 0;
1733
+ }
1734
+ let amount = BigInt(digits || "0");
1735
+ // trim trailing fractional zeros so e.g. "10.00" -> { amount: 10n, decimals: 0 }
1736
+ while(decimals > 0 && amount % 10n === 0n){
1737
+ amount /= 10n;
1738
+ decimals -= 1;
1739
+ }
1740
+ return {
1741
+ amount: negative ? -amount : amount,
1742
+ decimals: decimals
1743
+ };
1744
+ }
1692
1745
  const $07b3982e2fc4c8b2$export$400f08bfae9ee97f = {
1693
1746
  match: (block)=>(0, $09654dffcb68affa$export$ae001c77434c5340)(block) === "RIPPLE",
1694
1747
  transform (block) {
@@ -1718,15 +1771,20 @@ const $07b3982e2fc4c8b2$export$400f08bfae9ee97f = {
1718
1771
  let tokenSymbol = "XRP";
1719
1772
  let tokenType = "NATIVE";
1720
1773
  let parsedAmount;
1774
+ // Only issued currencies carry an explicit scale; native XRP stays in integer drops.
1775
+ let decimals;
1721
1776
  if (typeof deliveredOrAmount === "object") {
1722
- tokenSymbol = deliveredOrAmount.currency?.toUpperCase() ?? "UNKNOWN";
1777
+ tokenSymbol = $07b3982e2fc4c8b2$var$decodeXrplCurrency(deliveredOrAmount.currency);
1723
1778
  tokenType = "TOKEN";
1724
- const floatVal = parseFloat(deliveredOrAmount.value);
1725
- const smallestUnit = Math.round(floatVal * 1000000);
1726
- parsedAmount = BigInt(smallestUnit);
1779
+ const scaled = $07b3982e2fc4c8b2$var$xrplIssuedValueToAmount(deliveredOrAmount.value);
1780
+ parsedAmount = scaled.amount;
1781
+ decimals = scaled.decimals;
1727
1782
  } else parsedAmount = BigInt(String(deliveredOrAmount));
1728
1783
  transfers.push({
1729
1784
  amount: parsedAmount,
1785
+ ...decimals !== undefined ? {
1786
+ decimals: decimals
1787
+ } : {},
1730
1788
  blockNumber: parseInt(typedBlock.ledger_index, 10),
1731
1789
  from: typedTx.Account ?? "UNKNOWN",
1732
1790
  memo: typedTx.DestinationTag,
@@ -1801,6 +1859,137 @@ const $07b3982e2fc4c8b2$export$400f08bfae9ee97f = {
1801
1859
  transactionHash: "FAILEDXRPLTXHASH"
1802
1860
  }
1803
1861
  ]
1862
+ },
1863
+ // Issued-currency (IOU) amount: arbitrary-precision decimal, NOT XRP drops. This is the
1864
+ // regression case — the old `round(value * 1e6)` reported 0.00026764546195073 BITX as "268".
1865
+ // Now it's the exact mantissa + decimals, and the 40-hex currency decodes to its ASCII symbol.
1866
+ {
1867
+ params: {
1868
+ network: "RIPPLE"
1869
+ },
1870
+ payload: {
1871
+ _network: "RIPPLE",
1872
+ ledger_index: "105011630",
1873
+ close_time_iso: "2026-01-01T00:00:00Z",
1874
+ transactions: [
1875
+ {
1876
+ TransactionType: "Payment",
1877
+ Account: "rBITXFROMxxxxxxxxxxxxxxxxxxxxxxxxx",
1878
+ Destination: "rBITXTOxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1879
+ Amount: {
1880
+ currency: "4249547800000000000000000000000000000000",
1881
+ issuer: "rBitcoiNXev8VoVxV7pwoQx1sSfonVP9i3",
1882
+ value: "0.00026764546195073"
1883
+ },
1884
+ Fee: "12",
1885
+ hash: "BITXSMALLHASH",
1886
+ metaData: {
1887
+ TransactionResult: "tesSUCCESS"
1888
+ }
1889
+ }
1890
+ ]
1891
+ },
1892
+ output: [
1893
+ {
1894
+ amount: 26764546195073n,
1895
+ decimals: 17,
1896
+ blockNumber: 105011630,
1897
+ from: "rBITXFROMxxxxxxxxxxxxxxxxxxxxxxxxx",
1898
+ memo: undefined,
1899
+ timestamp: "2026-01-01T00:00:00Z",
1900
+ to: "rBITXTOxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1901
+ token: "BITx",
1902
+ tokenType: "TOKEN",
1903
+ transactionGasFee: 12n,
1904
+ transactionHash: "BITXSMALLHASH"
1905
+ }
1906
+ ]
1907
+ },
1908
+ // Large whole IOU value (no fractional digits) and a plain 3-char currency code.
1909
+ {
1910
+ params: {
1911
+ network: "RIPPLE"
1912
+ },
1913
+ payload: {
1914
+ _network: "RIPPLE",
1915
+ ledger_index: "105011630",
1916
+ close_time_iso: "2026-01-01T00:00:00Z",
1917
+ transactions: [
1918
+ {
1919
+ TransactionType: "Payment",
1920
+ Account: "rUSDFROMxxxxxxxxxxxxxxxxxxxxxxxxxx",
1921
+ Destination: "rUSDTOxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1922
+ Amount: {
1923
+ currency: "USD",
1924
+ issuer: "rIssuerxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1925
+ value: "1000000000000000"
1926
+ },
1927
+ Fee: "15",
1928
+ hash: "USDWHOLEHASH",
1929
+ metaData: {
1930
+ TransactionResult: "tesSUCCESS"
1931
+ }
1932
+ }
1933
+ ]
1934
+ },
1935
+ output: [
1936
+ {
1937
+ amount: 1000000000000000n,
1938
+ decimals: 0,
1939
+ blockNumber: 105011630,
1940
+ from: "rUSDFROMxxxxxxxxxxxxxxxxxxxxxxxxxx",
1941
+ memo: undefined,
1942
+ timestamp: "2026-01-01T00:00:00Z",
1943
+ to: "rUSDTOxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1944
+ token: "USD",
1945
+ tokenType: "TOKEN",
1946
+ transactionGasFee: 15n,
1947
+ transactionHash: "USDWHOLEHASH"
1948
+ }
1949
+ ]
1950
+ },
1951
+ // Scientific-notation IOU value parses exactly (1.5e-10 -> 15 * 10^-11).
1952
+ {
1953
+ params: {
1954
+ network: "RIPPLE"
1955
+ },
1956
+ payload: {
1957
+ _network: "RIPPLE",
1958
+ ledger_index: "105011630",
1959
+ close_time_iso: "2026-01-01T00:00:00Z",
1960
+ transactions: [
1961
+ {
1962
+ TransactionType: "Payment",
1963
+ Account: "rMAGFROMxxxxxxxxxxxxxxxxxxxxxxxxxx",
1964
+ Destination: "rMAGTOxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1965
+ Amount: {
1966
+ currency: "MAG",
1967
+ issuer: "rXmagwMmnFtVet3uL26Q2iwk287SRvVMJ",
1968
+ value: "1.5e-10"
1969
+ },
1970
+ Fee: "10",
1971
+ hash: "MAGSCIHASH",
1972
+ metaData: {
1973
+ TransactionResult: "tesSUCCESS"
1974
+ }
1975
+ }
1976
+ ]
1977
+ },
1978
+ output: [
1979
+ {
1980
+ amount: 15n,
1981
+ decimals: 11,
1982
+ blockNumber: 105011630,
1983
+ from: "rMAGFROMxxxxxxxxxxxxxxxxxxxxxxxxxx",
1984
+ memo: undefined,
1985
+ timestamp: "2026-01-01T00:00:00Z",
1986
+ to: "rMAGTOxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1987
+ token: "MAG",
1988
+ tokenType: "TOKEN",
1989
+ transactionGasFee: 10n,
1990
+ transactionHash: "MAGSCIHASH"
1991
+ }
1992
+ ]
1804
1993
  }
1805
1994
  ]
1806
1995
  };