@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/main.js CHANGED
@@ -1707,6 +1707,59 @@ async function $b2a2726ff5c26695$export$77ffdf974cb300ec(storage, wallet) {
1707
1707
 
1708
1708
 
1709
1709
 
1710
+ // XRPL issued-currency codes are either a 3-char ISO-style code ("USD", "MAG") or a 160-bit
1711
+ // (40 hex char) value. Standard hex codes encode the ASCII symbol in the leading bytes (e.g.
1712
+ // "42495478…" -> "BITx"); non-standard codes (LP tokens, demurrage) aren't printable ASCII, so
1713
+ // we keep the raw hex for those.
1714
+ function $2e46ec862e47c14f$var$decodeXrplCurrency(currency) {
1715
+ if (!currency) return "UNKNOWN";
1716
+ if (!/^[0-9A-Fa-f]{40}$/.test(currency)) return currency;
1717
+ let decoded = "";
1718
+ for(let i = 0; i < currency.length; i += 2){
1719
+ const code = parseInt(currency.slice(i, i + 2), 16);
1720
+ if (code === 0) continue; // strip NUL padding
1721
+ decoded += String.fromCharCode(code);
1722
+ }
1723
+ // only use the decoded form if it's entirely printable ASCII; otherwise the hex is the identity
1724
+ return decoded && /^[\x20-\x7e]+$/.test(decoded) ? decoded : currency.toUpperCase();
1725
+ }
1726
+ // XRPL issued-currency amounts are arbitrary-precision decimal strings (up to 15 significant
1727
+ // digits, wide exponent range) with no fixed on-chain integer unit. Parse them losslessly into a
1728
+ // (mantissa, decimals) pair using string/BigInt math — NEVER parseFloat, which silently rounds
1729
+ // (the old `round(value * 1e6)` reported 0.00026764546195073 BITX as "268"). Handles plain and
1730
+ // scientific-notation values; trailing fractional zeros are trimmed so the scale is minimal.
1731
+ function $2e46ec862e47c14f$var$xrplIssuedValueToAmount(raw) {
1732
+ let s = (raw ?? "0").trim();
1733
+ let negative = false;
1734
+ if (s.startsWith("-")) {
1735
+ negative = true;
1736
+ s = s.slice(1);
1737
+ } else if (s.startsWith("+")) s = s.slice(1);
1738
+ let exponent = 0;
1739
+ const eIndex = s.search(/[eE]/);
1740
+ if (eIndex !== -1) {
1741
+ exponent = parseInt(s.slice(eIndex + 1), 10) || 0;
1742
+ s = s.slice(0, eIndex);
1743
+ }
1744
+ const [intPart = "", fracPart = ""] = s.split(".");
1745
+ let digits = (intPart + fracPart).replace(/^0+(?=\d)/, "") || "0";
1746
+ let decimals = fracPart.length - exponent;
1747
+ if (decimals < 0) {
1748
+ // value scales up past the integer point — append zeros and clamp to 0 decimals
1749
+ digits += "0".repeat(-decimals);
1750
+ decimals = 0;
1751
+ }
1752
+ let amount = BigInt(digits || "0");
1753
+ // trim trailing fractional zeros so e.g. "10.00" -> { amount: 10n, decimals: 0 }
1754
+ while(decimals > 0 && amount % 10n === 0n){
1755
+ amount /= 10n;
1756
+ decimals -= 1;
1757
+ }
1758
+ return {
1759
+ amount: negative ? -amount : amount,
1760
+ decimals: decimals
1761
+ };
1762
+ }
1710
1763
  const $2e46ec862e47c14f$export$400f08bfae9ee97f = {
1711
1764
  match: (block)=>(0, $6bd2ca253e883278$export$ae001c77434c5340)(block) === "RIPPLE",
1712
1765
  transform (block) {
@@ -1736,15 +1789,20 @@ const $2e46ec862e47c14f$export$400f08bfae9ee97f = {
1736
1789
  let tokenSymbol = "XRP";
1737
1790
  let tokenType = "NATIVE";
1738
1791
  let parsedAmount;
1792
+ // Only issued currencies carry an explicit scale; native XRP stays in integer drops.
1793
+ let decimals;
1739
1794
  if (typeof deliveredOrAmount === "object") {
1740
- tokenSymbol = deliveredOrAmount.currency?.toUpperCase() ?? "UNKNOWN";
1795
+ tokenSymbol = $2e46ec862e47c14f$var$decodeXrplCurrency(deliveredOrAmount.currency);
1741
1796
  tokenType = "TOKEN";
1742
- const floatVal = parseFloat(deliveredOrAmount.value);
1743
- const smallestUnit = Math.round(floatVal * 1000000);
1744
- parsedAmount = BigInt(smallestUnit);
1797
+ const scaled = $2e46ec862e47c14f$var$xrplIssuedValueToAmount(deliveredOrAmount.value);
1798
+ parsedAmount = scaled.amount;
1799
+ decimals = scaled.decimals;
1745
1800
  } else parsedAmount = BigInt(String(deliveredOrAmount));
1746
1801
  transfers.push({
1747
1802
  amount: parsedAmount,
1803
+ ...decimals !== undefined ? {
1804
+ decimals: decimals
1805
+ } : {},
1748
1806
  blockNumber: parseInt(typedBlock.ledger_index, 10),
1749
1807
  from: typedTx.Account ?? "UNKNOWN",
1750
1808
  memo: typedTx.DestinationTag,
@@ -1819,6 +1877,137 @@ const $2e46ec862e47c14f$export$400f08bfae9ee97f = {
1819
1877
  transactionHash: "FAILEDXRPLTXHASH"
1820
1878
  }
1821
1879
  ]
1880
+ },
1881
+ // Issued-currency (IOU) amount: arbitrary-precision decimal, NOT XRP drops. This is the
1882
+ // regression case — the old `round(value * 1e6)` reported 0.00026764546195073 BITX as "268".
1883
+ // Now it's the exact mantissa + decimals, and the 40-hex currency decodes to its ASCII symbol.
1884
+ {
1885
+ params: {
1886
+ network: "RIPPLE"
1887
+ },
1888
+ payload: {
1889
+ _network: "RIPPLE",
1890
+ ledger_index: "105011630",
1891
+ close_time_iso: "2026-01-01T00:00:00Z",
1892
+ transactions: [
1893
+ {
1894
+ TransactionType: "Payment",
1895
+ Account: "rBITXFROMxxxxxxxxxxxxxxxxxxxxxxxxx",
1896
+ Destination: "rBITXTOxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1897
+ Amount: {
1898
+ currency: "4249547800000000000000000000000000000000",
1899
+ issuer: "rBitcoiNXev8VoVxV7pwoQx1sSfonVP9i3",
1900
+ value: "0.00026764546195073"
1901
+ },
1902
+ Fee: "12",
1903
+ hash: "BITXSMALLHASH",
1904
+ metaData: {
1905
+ TransactionResult: "tesSUCCESS"
1906
+ }
1907
+ }
1908
+ ]
1909
+ },
1910
+ output: [
1911
+ {
1912
+ amount: 26764546195073n,
1913
+ decimals: 17,
1914
+ blockNumber: 105011630,
1915
+ from: "rBITXFROMxxxxxxxxxxxxxxxxxxxxxxxxx",
1916
+ memo: undefined,
1917
+ timestamp: "2026-01-01T00:00:00Z",
1918
+ to: "rBITXTOxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1919
+ token: "BITx",
1920
+ tokenType: "TOKEN",
1921
+ transactionGasFee: 12n,
1922
+ transactionHash: "BITXSMALLHASH"
1923
+ }
1924
+ ]
1925
+ },
1926
+ // Large whole IOU value (no fractional digits) and a plain 3-char currency code.
1927
+ {
1928
+ params: {
1929
+ network: "RIPPLE"
1930
+ },
1931
+ payload: {
1932
+ _network: "RIPPLE",
1933
+ ledger_index: "105011630",
1934
+ close_time_iso: "2026-01-01T00:00:00Z",
1935
+ transactions: [
1936
+ {
1937
+ TransactionType: "Payment",
1938
+ Account: "rUSDFROMxxxxxxxxxxxxxxxxxxxxxxxxxx",
1939
+ Destination: "rUSDTOxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1940
+ Amount: {
1941
+ currency: "USD",
1942
+ issuer: "rIssuerxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1943
+ value: "1000000000000000"
1944
+ },
1945
+ Fee: "15",
1946
+ hash: "USDWHOLEHASH",
1947
+ metaData: {
1948
+ TransactionResult: "tesSUCCESS"
1949
+ }
1950
+ }
1951
+ ]
1952
+ },
1953
+ output: [
1954
+ {
1955
+ amount: 1000000000000000n,
1956
+ decimals: 0,
1957
+ blockNumber: 105011630,
1958
+ from: "rUSDFROMxxxxxxxxxxxxxxxxxxxxxxxxxx",
1959
+ memo: undefined,
1960
+ timestamp: "2026-01-01T00:00:00Z",
1961
+ to: "rUSDTOxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1962
+ token: "USD",
1963
+ tokenType: "TOKEN",
1964
+ transactionGasFee: 15n,
1965
+ transactionHash: "USDWHOLEHASH"
1966
+ }
1967
+ ]
1968
+ },
1969
+ // Scientific-notation IOU value parses exactly (1.5e-10 -> 15 * 10^-11).
1970
+ {
1971
+ params: {
1972
+ network: "RIPPLE"
1973
+ },
1974
+ payload: {
1975
+ _network: "RIPPLE",
1976
+ ledger_index: "105011630",
1977
+ close_time_iso: "2026-01-01T00:00:00Z",
1978
+ transactions: [
1979
+ {
1980
+ TransactionType: "Payment",
1981
+ Account: "rMAGFROMxxxxxxxxxxxxxxxxxxxxxxxxxx",
1982
+ Destination: "rMAGTOxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
1983
+ Amount: {
1984
+ currency: "MAG",
1985
+ issuer: "rXmagwMmnFtVet3uL26Q2iwk287SRvVMJ",
1986
+ value: "1.5e-10"
1987
+ },
1988
+ Fee: "10",
1989
+ hash: "MAGSCIHASH",
1990
+ metaData: {
1991
+ TransactionResult: "tesSUCCESS"
1992
+ }
1993
+ }
1994
+ ]
1995
+ },
1996
+ output: [
1997
+ {
1998
+ amount: 15n,
1999
+ decimals: 11,
2000
+ blockNumber: 105011630,
2001
+ from: "rMAGFROMxxxxxxxxxxxxxxxxxxxxxxxxxx",
2002
+ memo: undefined,
2003
+ timestamp: "2026-01-01T00:00:00Z",
2004
+ to: "rMAGTOxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
2005
+ token: "MAG",
2006
+ tokenType: "TOKEN",
2007
+ transactionGasFee: 10n,
2008
+ transactionHash: "MAGSCIHASH"
2009
+ }
2010
+ ]
1822
2011
  }
1823
2012
  ]
1824
2013
  };