@vultisig/cli 0.16.0 → 0.17.0

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/index.js +1326 -74
  3. package/package.json +5 -4
package/dist/index.js CHANGED
@@ -1430,7 +1430,7 @@ var init_sha3 = __esm({
1430
1430
  }
1431
1431
  });
1432
1432
 
1433
- // node_modules/viem/_esm/utils/unit/formatUnits.js
1433
+ // ../../node_modules/viem/_esm/utils/unit/formatUnits.js
1434
1434
  function formatUnits(value, decimals) {
1435
1435
  let display = value.toString();
1436
1436
  const negative = display.startsWith("-");
@@ -1445,7 +1445,981 @@ function formatUnits(value, decimals) {
1445
1445
  return `${negative ? "-" : ""}${integer || "0"}${fraction ? `.${fraction}` : ""}`;
1446
1446
  }
1447
1447
  var init_formatUnits = __esm({
1448
- "node_modules/viem/_esm/utils/unit/formatUnits.js"() {
1448
+ "../../node_modules/viem/_esm/utils/unit/formatUnits.js"() {
1449
+ }
1450
+ });
1451
+
1452
+ // ../../packages/lib/utils/dist/promise/isPromise.js
1453
+ function isPromise(value) {
1454
+ return !!value && typeof value.then === "function";
1455
+ }
1456
+ var init_isPromise = __esm({
1457
+ "../../packages/lib/utils/dist/promise/isPromise.js"() {
1458
+ }
1459
+ });
1460
+
1461
+ // ../../packages/lib/utils/dist/attempt.js
1462
+ function attempt(input) {
1463
+ if (typeof input === "function") {
1464
+ try {
1465
+ const result = input();
1466
+ if (isPromise(result)) {
1467
+ return attempt(result);
1468
+ }
1469
+ return { data: result };
1470
+ } catch (error2) {
1471
+ return { error: error2 };
1472
+ }
1473
+ } else {
1474
+ return input.then((data) => ({ data }), (error2) => ({ error: error2 }));
1475
+ }
1476
+ }
1477
+ function withFallback(result, fallback) {
1478
+ if (isPromise(result)) {
1479
+ return result.then((res) => {
1480
+ if ("error" in res) {
1481
+ return fallback;
1482
+ }
1483
+ return res.data;
1484
+ });
1485
+ }
1486
+ if ("error" in result) {
1487
+ return fallback;
1488
+ }
1489
+ return result.data;
1490
+ }
1491
+ var init_attempt = __esm({
1492
+ "../../packages/lib/utils/dist/attempt.js"() {
1493
+ init_isPromise();
1494
+ }
1495
+ });
1496
+
1497
+ // ../../packages/lib/utils/dist/error/extractErrorMsg/index.js
1498
+ var extractErrorMsg;
1499
+ var init_extractErrorMsg = __esm({
1500
+ "../../packages/lib/utils/dist/error/extractErrorMsg/index.js"() {
1501
+ init_attempt();
1502
+ extractErrorMsg = (err) => {
1503
+ if (typeof err === "string") {
1504
+ return err;
1505
+ }
1506
+ if (typeof err === "number" || typeof err === "boolean") {
1507
+ return String(err);
1508
+ }
1509
+ if (typeof err === "object" && err && "message" in err) {
1510
+ return extractErrorMsg(err.message);
1511
+ }
1512
+ return withFallback(attempt(() => JSON.stringify(err)), "Unknown Error");
1513
+ };
1514
+ }
1515
+ });
1516
+
1517
+ // ../../packages/lib/utils/dist/array/isEmpty/index.js
1518
+ var isEmpty;
1519
+ var init_isEmpty = __esm({
1520
+ "../../packages/lib/utils/dist/array/isEmpty/index.js"() {
1521
+ isEmpty = (items) => items.length === 0;
1522
+ }
1523
+ });
1524
+
1525
+ // ../../packages/lib/utils/dist/promise/asyncFallbackChain/index.js
1526
+ var asyncFallbackChain;
1527
+ var init_asyncFallbackChain = __esm({
1528
+ "../../packages/lib/utils/dist/promise/asyncFallbackChain/index.js"() {
1529
+ init_isEmpty();
1530
+ asyncFallbackChain = async (...functions) => {
1531
+ if (isEmpty(functions)) {
1532
+ throw new Error("No functions provided");
1533
+ }
1534
+ try {
1535
+ const result = await functions[0]();
1536
+ return result;
1537
+ } catch (error2) {
1538
+ if (functions.length <= 1) {
1539
+ throw error2;
1540
+ }
1541
+ return asyncFallbackChain(...functions.slice(1));
1542
+ }
1543
+ };
1544
+ }
1545
+ });
1546
+
1547
+ // ../../packages/lib/utils/dist/fetch/HttpResponseError.js
1548
+ var HttpResponseError;
1549
+ var init_HttpResponseError = __esm({
1550
+ "../../packages/lib/utils/dist/fetch/HttpResponseError.js"() {
1551
+ HttpResponseError = class extends Error {
1552
+ status;
1553
+ statusText;
1554
+ url;
1555
+ body;
1556
+ constructor(opts) {
1557
+ super(opts.message);
1558
+ this.name = "HttpResponseError";
1559
+ this.status = opts.status;
1560
+ this.statusText = opts.statusText;
1561
+ this.url = opts.url;
1562
+ this.body = opts.body;
1563
+ }
1564
+ };
1565
+ }
1566
+ });
1567
+
1568
+ // ../../packages/lib/utils/dist/fetch/assertFetchResponse.js
1569
+ var assertFetchResponse;
1570
+ var init_assertFetchResponse = __esm({
1571
+ "../../packages/lib/utils/dist/fetch/assertFetchResponse.js"() {
1572
+ init_extractErrorMsg();
1573
+ init_asyncFallbackChain();
1574
+ init_HttpResponseError();
1575
+ assertFetchResponse = async (response) => {
1576
+ if (!response.ok) {
1577
+ const body = await asyncFallbackChain(async () => response.json(), async () => response.text(), async () => `HTTP ${response.status} ${response.statusText || "Error"}: Request failed for ${response.url}`);
1578
+ const msg = extractErrorMsg(body);
1579
+ throw new HttpResponseError({
1580
+ message: msg,
1581
+ status: response.status,
1582
+ statusText: response.statusText,
1583
+ url: response.url,
1584
+ body
1585
+ });
1586
+ }
1587
+ };
1588
+ }
1589
+ });
1590
+
1591
+ // ../../packages/lib/utils/dist/record/getRecordKeys/index.js
1592
+ var getRecordKeys;
1593
+ var init_getRecordKeys = __esm({
1594
+ "../../packages/lib/utils/dist/record/getRecordKeys/index.js"() {
1595
+ getRecordKeys = (record) => {
1596
+ return Object.keys(record);
1597
+ };
1598
+ }
1599
+ });
1600
+
1601
+ // ../../packages/lib/utils/dist/record/withoutUndefinedFields.js
1602
+ function withoutUndefinedFields(record) {
1603
+ const result = {};
1604
+ getRecordKeys(record).forEach((key) => {
1605
+ const typedKey = key;
1606
+ const value = record[typedKey];
1607
+ if (value !== void 0) {
1608
+ result[typedKey] = value;
1609
+ }
1610
+ });
1611
+ return result;
1612
+ }
1613
+ var init_withoutUndefinedFields = __esm({
1614
+ "../../packages/lib/utils/dist/record/withoutUndefinedFields.js"() {
1615
+ init_getRecordKeys();
1616
+ }
1617
+ });
1618
+
1619
+ // ../../packages/lib/utils/dist/query/queryUrl.js
1620
+ async function queryUrl(url, options = {}) {
1621
+ const { responseType = "json", body, headers, method } = options;
1622
+ const response = await fetch(url, withoutUndefinedFields({
1623
+ method: method ?? (body ? "POST" : "GET"),
1624
+ headers: withoutUndefinedFields({
1625
+ ...headers,
1626
+ "Content-Type": body ? "application/json" : void 0
1627
+ }),
1628
+ body: processBody(body)
1629
+ }));
1630
+ await assertFetchResponse(response);
1631
+ if (responseType !== "none") {
1632
+ return response[responseType]();
1633
+ }
1634
+ }
1635
+ var processBody;
1636
+ var init_queryUrl = __esm({
1637
+ "../../packages/lib/utils/dist/query/queryUrl.js"() {
1638
+ init_assertFetchResponse();
1639
+ init_withoutUndefinedFields();
1640
+ processBody = (body) => {
1641
+ if (body === void 0) {
1642
+ return void 0;
1643
+ }
1644
+ if (typeof body === "string") {
1645
+ return body;
1646
+ }
1647
+ return JSON.stringify(body);
1648
+ };
1649
+ }
1650
+ });
1651
+
1652
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/pools.js
1653
+ var thorchainMidgardBaseUrl, POOL_ID_RE, assertValidPoolId, isValidPoolId, normalizePool, getThorchainPools;
1654
+ var init_pools = __esm({
1655
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/pools.js"() {
1656
+ init_queryUrl();
1657
+ thorchainMidgardBaseUrl = "https://midgard.ninerealms.com";
1658
+ POOL_ID_RE = /^[A-Z0-9]+\.[A-Z0-9]+(-[A-Z0-9]+)?$/;
1659
+ assertValidPoolId = (pool) => {
1660
+ if (typeof pool !== "string" || pool.length === 0) {
1661
+ throw new Error(`assertValidPoolId: pool id must be a non-empty string, got ${typeof pool} ${pool === "" ? '""' : ""}`);
1662
+ }
1663
+ if (!POOL_ID_RE.test(pool)) {
1664
+ throw new Error(`assertValidPoolId: ${JSON.stringify(pool)} is not a valid THORChain pool id. Expected uppercase CHAIN.ASSET (e.g. "BTC.BTC") or CHAIN.ASSET-CONTRACT (e.g. "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48").`);
1665
+ }
1666
+ };
1667
+ isValidPoolId = (pool) => {
1668
+ if (typeof pool !== "string" || pool.length === 0)
1669
+ return false;
1670
+ return POOL_ID_RE.test(pool);
1671
+ };
1672
+ normalizePool = (raw) => ({
1673
+ asset: raw.asset ?? "",
1674
+ status: raw.status ?? "",
1675
+ assetDepth: raw.assetDepth ?? "0",
1676
+ runeDepth: raw.runeDepth ?? "0",
1677
+ liquidityUnits: raw.liquidityUnits ?? "0",
1678
+ volume24h: raw.volume24h ?? "0",
1679
+ annualPercentageRate: raw.annualPercentageRate ?? "0"
1680
+ });
1681
+ getThorchainPools = async (options = {}) => {
1682
+ const status = options.status === void 0 ? "available" : options.status;
1683
+ const url = status === null ? `${thorchainMidgardBaseUrl}/v2/pools` : `${thorchainMidgardBaseUrl}/v2/pools?status=${encodeURIComponent(status)}`;
1684
+ const raw = await queryUrl(url);
1685
+ if (!Array.isArray(raw)) {
1686
+ throw new Error(`getThorchainPools: expected an array from ${url}, got ${typeof raw}`);
1687
+ }
1688
+ return raw.map(normalizePool);
1689
+ };
1690
+ }
1691
+ });
1692
+
1693
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/memo.js
1694
+ var assertMemoSegmentSafe, addLpMemo, removeLpMemo;
1695
+ var init_memo = __esm({
1696
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/memo.js"() {
1697
+ init_pools();
1698
+ assertMemoSegmentSafe = (value, fieldName) => {
1699
+ if (typeof value !== "string") {
1700
+ throw new Error(`${fieldName} must be a string, got ${typeof value}`);
1701
+ }
1702
+ if (value.includes(":")) {
1703
+ throw new Error(`${fieldName} must not contain \`:\` (would inject extra memo segments), got ${JSON.stringify(value)}`);
1704
+ }
1705
+ if (/\s/.test(value)) {
1706
+ throw new Error(`${fieldName} must not contain whitespace, got ${JSON.stringify(value)}`);
1707
+ }
1708
+ };
1709
+ addLpMemo = ({ pool, pairedAddress }) => {
1710
+ assertValidPoolId(pool);
1711
+ if (pairedAddress && pairedAddress.length > 0) {
1712
+ assertMemoSegmentSafe(pairedAddress, "pairedAddress");
1713
+ return `+:${pool}:${pairedAddress}`;
1714
+ }
1715
+ return `+:${pool}`;
1716
+ };
1717
+ removeLpMemo = ({ pool, basisPoints, withdrawToAsset }) => {
1718
+ assertValidPoolId(pool);
1719
+ if (!Number.isInteger(basisPoints) || basisPoints < 1 || basisPoints > 1e4) {
1720
+ throw new Error(`removeLpMemo: basisPoints must be an integer in [1, 10000], got ${basisPoints}`);
1721
+ }
1722
+ if (withdrawToAsset && withdrawToAsset.length > 0) {
1723
+ assertMemoSegmentSafe(withdrawToAsset, "withdrawToAsset");
1724
+ return `-:${pool}:${basisPoints}:${withdrawToAsset}`;
1725
+ }
1726
+ return `-:${pool}:${basisPoints}`;
1727
+ };
1728
+ }
1729
+ });
1730
+
1731
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/payload.js
1732
+ var LP_REMOVE_DUST_RUNE_BASE_UNITS, isPositiveBaseUnitString, buildThorchainLpAddPayload, buildThorchainLpRemovePayload;
1733
+ var init_payload = __esm({
1734
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/payload.js"() {
1735
+ init_memo();
1736
+ LP_REMOVE_DUST_RUNE_BASE_UNITS = "2000000";
1737
+ isPositiveBaseUnitString = (value) => /^\d+$/.test(value) && BigInt(value) > 0n;
1738
+ buildThorchainLpAddPayload = ({ pool, amountRuneBaseUnits, pairedAddress }) => {
1739
+ if (!isPositiveBaseUnitString(amountRuneBaseUnits)) {
1740
+ throw new Error(`buildThorchainLpAddPayload: amountRuneBaseUnits must be a positive integer string, got ${amountRuneBaseUnits}`);
1741
+ }
1742
+ const memo = addLpMemo({ pool, pairedAddress });
1743
+ return {
1744
+ kind: "thorchain_lp_add",
1745
+ chain: "THORChain",
1746
+ denom: "rune",
1747
+ amount: amountRuneBaseUnits,
1748
+ memo,
1749
+ pool,
1750
+ ...pairedAddress ? { pairedAddress } : {}
1751
+ };
1752
+ };
1753
+ buildThorchainLpRemovePayload = ({ pool, basisPoints, withdrawToAsset }) => {
1754
+ if (!Number.isInteger(basisPoints) || basisPoints < 1 || basisPoints > 1e4) {
1755
+ throw new Error(`buildThorchainLpRemovePayload: basisPoints must be an integer in [1, 10000], got ${basisPoints}`);
1756
+ }
1757
+ const memo = removeLpMemo({ pool, basisPoints, withdrawToAsset });
1758
+ return {
1759
+ kind: "thorchain_lp_remove",
1760
+ chain: "THORChain",
1761
+ denom: "rune",
1762
+ amount: LP_REMOVE_DUST_RUNE_BASE_UNITS,
1763
+ memo,
1764
+ pool,
1765
+ basisPoints,
1766
+ ...withdrawToAsset ? { withdrawToAsset } : {}
1767
+ };
1768
+ };
1769
+ }
1770
+ });
1771
+
1772
+ // ../../packages/core/chain/dist/Chain.js
1773
+ var EthereumL2Chain, EvmChain, UtxoChain, cosmosChainsByKind, IbcEnabledCosmosChain, VaultBasedCosmosChain, CosmosChain, OtherChain, Chain9, UtxoBasedChain, defaultChains;
1774
+ var init_Chain = __esm({
1775
+ "../../packages/core/chain/dist/Chain.js"() {
1776
+ EthereumL2Chain = {
1777
+ Arbitrum: "Arbitrum",
1778
+ Base: "Base",
1779
+ Blast: "Blast",
1780
+ Optimism: "Optimism",
1781
+ Zksync: "Zksync",
1782
+ Mantle: "Mantle"
1783
+ };
1784
+ EvmChain = {
1785
+ ...EthereumL2Chain,
1786
+ Avalanche: "Avalanche",
1787
+ CronosChain: "CronosChain",
1788
+ BSC: "BSC",
1789
+ Ethereum: "Ethereum",
1790
+ Polygon: "Polygon",
1791
+ Hyperliquid: "Hyperliquid",
1792
+ Sei: "Sei"
1793
+ };
1794
+ (function(UtxoChain2) {
1795
+ UtxoChain2["Bitcoin"] = "Bitcoin";
1796
+ UtxoChain2["BitcoinCash"] = "Bitcoin-Cash";
1797
+ UtxoChain2["Litecoin"] = "Litecoin";
1798
+ UtxoChain2["Dogecoin"] = "Dogecoin";
1799
+ UtxoChain2["Dash"] = "Dash";
1800
+ UtxoChain2["Zcash"] = "Zcash";
1801
+ })(UtxoChain || (UtxoChain = {}));
1802
+ cosmosChainsByKind = {
1803
+ ibcEnabled: {
1804
+ Cosmos: "Cosmos",
1805
+ Osmosis: "Osmosis",
1806
+ Dydx: "Dydx",
1807
+ Kujira: "Kujira",
1808
+ Terra: "Terra",
1809
+ TerraClassic: "TerraClassic",
1810
+ Noble: "Noble",
1811
+ Akash: "Akash"
1812
+ },
1813
+ vaultBased: {
1814
+ THORChain: "THORChain",
1815
+ MayaChain: "MayaChain"
1816
+ }
1817
+ };
1818
+ IbcEnabledCosmosChain = cosmosChainsByKind.ibcEnabled;
1819
+ VaultBasedCosmosChain = cosmosChainsByKind.vaultBased;
1820
+ CosmosChain = {
1821
+ ...IbcEnabledCosmosChain,
1822
+ ...VaultBasedCosmosChain
1823
+ };
1824
+ (function(OtherChain2) {
1825
+ OtherChain2["Sui"] = "Sui";
1826
+ OtherChain2["Solana"] = "Solana";
1827
+ OtherChain2["Polkadot"] = "Polkadot";
1828
+ OtherChain2["Bittensor"] = "Bittensor";
1829
+ OtherChain2["Ton"] = "Ton";
1830
+ OtherChain2["Ripple"] = "Ripple";
1831
+ OtherChain2["Tron"] = "Tron";
1832
+ OtherChain2["Cardano"] = "Cardano";
1833
+ OtherChain2["QBTC"] = "QBTC";
1834
+ })(OtherChain || (OtherChain = {}));
1835
+ Chain9 = {
1836
+ ...EvmChain,
1837
+ ...UtxoChain,
1838
+ ...CosmosChain,
1839
+ ...OtherChain
1840
+ };
1841
+ UtxoBasedChain = [
1842
+ ...Object.values(UtxoChain),
1843
+ OtherChain.Cardano
1844
+ ];
1845
+ defaultChains = [
1846
+ Chain9.Bitcoin,
1847
+ Chain9.Ethereum,
1848
+ Chain9.THORChain,
1849
+ Chain9.Solana,
1850
+ Chain9.BSC
1851
+ ];
1852
+ }
1853
+ });
1854
+
1855
+ // ../../packages/core/chain/dist/chains/cosmos/cosmosRpcUrl.js
1856
+ var cosmosRpcUrl;
1857
+ var init_cosmosRpcUrl = __esm({
1858
+ "../../packages/core/chain/dist/chains/cosmos/cosmosRpcUrl.js"() {
1859
+ cosmosRpcUrl = {
1860
+ Cosmos: "https://cosmos-rest.publicnode.com",
1861
+ Osmosis: "https://osmosis-rest.publicnode.com",
1862
+ Dydx: "https://dydx-rest.publicnode.com",
1863
+ Kujira: "https://kujira-rest.publicnode.com",
1864
+ Terra: "https://terra-lcd.publicnode.com",
1865
+ TerraClassic: "https://terra-classic-lcd.publicnode.com",
1866
+ Noble: "https://noble-api.polkachu.com",
1867
+ THORChain: "https://thornode.thorchain.network",
1868
+ MayaChain: "https://mayanode.mayachain.info",
1869
+ Akash: "https://akash-rest.publicnode.com"
1870
+ };
1871
+ }
1872
+ });
1873
+
1874
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/memberPool.js
1875
+ var isNonZeroBaseUnit, normalizeMemberPool;
1876
+ var init_memberPool = __esm({
1877
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/memberPool.js"() {
1878
+ isNonZeroBaseUnit = (value) => {
1879
+ if (!value)
1880
+ return false;
1881
+ try {
1882
+ return BigInt(value) > 0n;
1883
+ } catch {
1884
+ return false;
1885
+ }
1886
+ };
1887
+ normalizeMemberPool = (raw) => ({
1888
+ pool: raw.pool ?? "",
1889
+ liquidityUnits: raw.liquidityUnits ?? "0",
1890
+ runeAdded: raw.runeAdded ?? "0",
1891
+ assetAdded: raw.assetAdded ?? "0",
1892
+ runePending: raw.runePending ?? "0",
1893
+ assetPending: raw.assetPending ?? "0",
1894
+ runeAddress: raw.runeAddress ?? "",
1895
+ assetAddress: raw.assetAddress ?? "",
1896
+ dateLastAdded: raw.dateLastAdded ?? "0",
1897
+ lastAddHeight: "",
1898
+ isPending: isNonZeroBaseUnit(raw.runePending) || isNonZeroBaseUnit(raw.assetPending)
1899
+ });
1900
+ }
1901
+ });
1902
+
1903
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/position.js
1904
+ var isMidgardNotFoundError, getThorchainLpPosition, getThorchainLpPositionFromThornode;
1905
+ var init_position = __esm({
1906
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/position.js"() {
1907
+ init_Chain();
1908
+ init_cosmosRpcUrl();
1909
+ init_HttpResponseError();
1910
+ init_queryUrl();
1911
+ init_memberPool();
1912
+ init_pools();
1913
+ isMidgardNotFoundError = (err) => err instanceof HttpResponseError && err.status === 404;
1914
+ getThorchainLpPosition = async ({ thorAddress, pool }) => {
1915
+ assertValidPoolId(pool);
1916
+ const url = `${thorchainMidgardBaseUrl}/v2/member/${encodeURIComponent(thorAddress)}`;
1917
+ let midgardNotFound = false;
1918
+ let raw = {};
1919
+ try {
1920
+ raw = await queryUrl(url);
1921
+ } catch (err) {
1922
+ if (isMidgardNotFoundError(err)) {
1923
+ midgardNotFound = true;
1924
+ } else {
1925
+ throw err;
1926
+ }
1927
+ }
1928
+ if (!midgardNotFound) {
1929
+ const pools = Array.isArray(raw.pools) ? raw.pools : [];
1930
+ const found = pools.find((p) => p.pool === pool);
1931
+ if (found)
1932
+ return normalizeMemberPool(found);
1933
+ }
1934
+ return getThorchainLpPositionFromThornode({ thorAddress, pool });
1935
+ };
1936
+ getThorchainLpPositionFromThornode = async ({ thorAddress, pool }) => {
1937
+ assertValidPoolId(pool);
1938
+ const url = `${cosmosRpcUrl[Chain9.THORChain]}/thorchain/pool/${encodeURIComponent(pool)}/liquidity_provider/${encodeURIComponent(thorAddress)}`;
1939
+ let raw;
1940
+ try {
1941
+ raw = await queryUrl(url);
1942
+ } catch (err) {
1943
+ if (err instanceof HttpResponseError && err.status === 404)
1944
+ return null;
1945
+ throw err;
1946
+ }
1947
+ const units = raw.units ?? "0";
1948
+ const pendingRune = raw.pending_rune ?? "0";
1949
+ const pendingAsset = raw.pending_asset ?? "0";
1950
+ if (!isNonZeroBaseUnit(units) && !isNonZeroBaseUnit(pendingRune) && !isNonZeroBaseUnit(pendingAsset)) {
1951
+ return null;
1952
+ }
1953
+ return {
1954
+ pool: raw.asset ?? pool,
1955
+ liquidityUnits: units,
1956
+ // Thornode doesn't track historical added amounts — those are a
1957
+ // Midgard-only enrichment. Surface them as 0; the caller can still
1958
+ // act on units/pending.
1959
+ runeAdded: "0",
1960
+ assetAdded: "0",
1961
+ runePending: pendingRune,
1962
+ assetPending: pendingAsset,
1963
+ runeAddress: raw.rune_address ?? thorAddress,
1964
+ assetAddress: raw.asset_address ?? "",
1965
+ // Thornode exposes the last-add block height, not a Unix timestamp.
1966
+ // Keep `dateLastAdded` semantically Unix-seconds-or-0 and expose the
1967
+ // block height via the dedicated `lastAddHeight` field so lockup
1968
+ // checks can use either source.
1969
+ dateLastAdded: "0",
1970
+ lastAddHeight: typeof raw.last_add_height === "number" ? String(raw.last_add_height) : "",
1971
+ isPending: isNonZeroBaseUnit(pendingRune) || isNonZeroBaseUnit(pendingAsset)
1972
+ };
1973
+ };
1974
+ }
1975
+ });
1976
+
1977
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/validation.js
1978
+ var extractPoolStatus, poolPauseMimirKey, getThorchainMimir, assertPoolDepositable;
1979
+ var init_validation = __esm({
1980
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/validation.js"() {
1981
+ init_Chain();
1982
+ init_cosmosRpcUrl();
1983
+ init_queryUrl();
1984
+ init_pools();
1985
+ extractPoolStatus = (raw) => {
1986
+ if (raw && typeof raw === "object" && "status" in raw) {
1987
+ const status = raw.status;
1988
+ return typeof status === "string" ? status : void 0;
1989
+ }
1990
+ return void 0;
1991
+ };
1992
+ poolPauseMimirKey = (pool) => {
1993
+ const dotIdx = pool.indexOf(".");
1994
+ if (dotIdx <= 0 || dotIdx >= pool.length - 1) {
1995
+ throw new Error(`poolPauseMimirKey: invalid pool id ${pool}`);
1996
+ }
1997
+ const chain = pool.slice(0, dotIdx);
1998
+ const asset = pool.slice(dotIdx + 1);
1999
+ return `PAUSELPDEPOSIT-${chain}-${asset}`;
2000
+ };
2001
+ getThorchainMimir = async () => {
2002
+ const url = `${cosmosRpcUrl[Chain9.THORChain]}/thorchain/mimir`;
2003
+ const raw = await queryUrl(url);
2004
+ if (!raw || typeof raw !== "object") {
2005
+ throw new Error(`getThorchainMimir: unexpected response shape from ${url}`);
2006
+ }
2007
+ const out = {};
2008
+ for (const [k, v] of Object.entries(raw)) {
2009
+ if (typeof v === "number" && Number.isFinite(v)) {
2010
+ out[k] = v;
2011
+ } else if (typeof v === "string" && /^-?\d+$/.test(v)) {
2012
+ out[k] = Number(v);
2013
+ }
2014
+ }
2015
+ return out;
2016
+ };
2017
+ assertPoolDepositable = async (pool) => {
2018
+ assertValidPoolId(pool);
2019
+ const [poolRaw, mimir] = await Promise.all([
2020
+ queryUrl(`${cosmosRpcUrl[Chain9.THORChain]}/thorchain/pool/${encodeURIComponent(pool)}`),
2021
+ getThorchainMimir()
2022
+ ]);
2023
+ const status = extractPoolStatus(poolRaw);
2024
+ if (status === void 0) {
2025
+ throw new Error(`assertPoolDepositable: pool ${pool} response from thornode did not include a string \`status\` field`);
2026
+ }
2027
+ if (status !== "Available") {
2028
+ throw new Error(`assertPoolDepositable: pool ${pool} status is ${status}, must be Available for LP add`);
2029
+ }
2030
+ const pauseKey = poolPauseMimirKey(pool);
2031
+ const pauseValue = mimir[pauseKey];
2032
+ if (typeof pauseValue === "number" && pauseValue > 0) {
2033
+ throw new Error(`assertPoolDepositable: pool ${pool} has LP deposits paused on-chain via mimir ${pauseKey}=${pauseValue}. THORChain validators have disabled new adds for this pool; any tx would be rejected at handler execution time.`);
2034
+ }
2035
+ };
2036
+ }
2037
+ });
2038
+
2039
+ // ../../packages/core/chain/dist/chains/cosmos/thor/thorchainLp.js
2040
+ var thorchainLpChainCode;
2041
+ var init_thorchainLp = __esm({
2042
+ "../../packages/core/chain/dist/chains/cosmos/thor/thorchainLp.js"() {
2043
+ init_Chain();
2044
+ thorchainLpChainCode = {
2045
+ [Chain9.Avalanche]: "AVAX",
2046
+ [Chain9.Base]: "BASE",
2047
+ [Chain9.BitcoinCash]: "BCH",
2048
+ [Chain9.BSC]: "BSC",
2049
+ [Chain9.Bitcoin]: "BTC",
2050
+ [Chain9.Dash]: "DASH",
2051
+ [Chain9.Dogecoin]: "DOGE",
2052
+ [Chain9.Ethereum]: "ETH",
2053
+ [Chain9.Cosmos]: "GAIA",
2054
+ [Chain9.Kujira]: "KUJI",
2055
+ [Chain9.Litecoin]: "LTC",
2056
+ [Chain9.THORChain]: "THOR",
2057
+ [Chain9.Tron]: "TRON",
2058
+ [Chain9.Ripple]: "XRP",
2059
+ [Chain9.Arbitrum]: "ARB",
2060
+ [Chain9.Zcash]: "ZEC"
2061
+ };
2062
+ }
2063
+ });
2064
+
2065
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/lpChainMap.js
2066
+ var lpChainMap, chainPrefixToChain, chainToLpPrefix;
2067
+ var init_lpChainMap = __esm({
2068
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/lpChainMap.js"() {
2069
+ init_thorchainLp();
2070
+ lpChainMap = Object.freeze(Object.entries(thorchainLpChainCode).reduce((acc, [chainKey, prefix]) => {
2071
+ if (prefix) {
2072
+ acc[prefix] = chainKey;
2073
+ }
2074
+ return acc;
2075
+ }, {}));
2076
+ chainPrefixToChain = (prefix) => lpChainMap[prefix.toUpperCase()];
2077
+ chainToLpPrefix = (chain) => thorchainLpChainCode[chain];
2078
+ }
2079
+ });
2080
+
2081
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/pairing.js
2082
+ var resolvePairedAddressForLpAdd;
2083
+ var init_pairing = __esm({
2084
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/pairing.js"() {
2085
+ init_Chain();
2086
+ init_lpChainMap();
2087
+ init_pools();
2088
+ resolvePairedAddressForLpAdd = ({ pool, side, vaultAddresses }) => {
2089
+ assertValidPoolId(pool);
2090
+ const [chainPrefix] = pool.split(".");
2091
+ if (!chainPrefix)
2092
+ return void 0;
2093
+ const assetChain = chainPrefixToChain(chainPrefix);
2094
+ if (!assetChain)
2095
+ return void 0;
2096
+ if (side === "asset") {
2097
+ return vaultAddresses[Chain9.THORChain];
2098
+ }
2099
+ return vaultAddresses[assetChain];
2100
+ };
2101
+ }
2102
+ });
2103
+
2104
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/math.js
2105
+ var assertBaseUnitString, getLiquidityUnits, getPoolShare, getLpAddSlippage, estimateLpAdd;
2106
+ var init_math = __esm({
2107
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/math.js"() {
2108
+ init_Chain();
2109
+ init_cosmosRpcUrl();
2110
+ init_queryUrl();
2111
+ init_pools();
2112
+ assertBaseUnitString = (value, fieldName) => {
2113
+ if (typeof value !== "string" || value.length === 0) {
2114
+ throw new Error(`${fieldName} must be a non-empty base-unit string, got ${typeof value === "string" ? JSON.stringify(value) : typeof value}`);
2115
+ }
2116
+ if (!/^\d+$/.test(value)) {
2117
+ throw new Error(`${fieldName} must be a non-negative integer base-unit string, got ${JSON.stringify(value)}`);
2118
+ }
2119
+ return BigInt(value);
2120
+ };
2121
+ getLiquidityUnits = ({ pool, assetAmountBaseUnit, runeAmountBaseUnit }) => {
2122
+ const P = assertBaseUnitString(pool.poolUnits, "pool.poolUnits");
2123
+ const R = assertBaseUnitString(pool.runeDepth, "pool.runeDepth");
2124
+ const A = assertBaseUnitString(pool.assetDepth, "pool.assetDepth");
2125
+ const r = assertBaseUnitString(runeAmountBaseUnit, "runeAmountBaseUnit");
2126
+ const a = assertBaseUnitString(assetAmountBaseUnit, "assetAmountBaseUnit");
2127
+ if (R === 0n || A === 0n || P === 0n) {
2128
+ return "0";
2129
+ }
2130
+ const numerator = P * (R * a + r * A);
2131
+ const denominator = 2n * R * A;
2132
+ return (numerator / denominator).toString();
2133
+ };
2134
+ getPoolShare = ({ pool, liquidityUnits }) => {
2135
+ const P = assertBaseUnitString(pool.poolUnits, "pool.poolUnits");
2136
+ const L = assertBaseUnitString(liquidityUnits, "liquidityUnits");
2137
+ if (P === 0n || L === 0n) {
2138
+ return { poolShareDecimal: "0" };
2139
+ }
2140
+ const totalAfter = P + L;
2141
+ const SCALE = 10n ** 18n;
2142
+ const scaled = L * SCALE / totalAfter;
2143
+ const decimal = scaled.toString().padStart(19, "0");
2144
+ const intPart = decimal.slice(0, -18) || "0";
2145
+ const fracPart = decimal.slice(-18).replace(/0+$/, "");
2146
+ return {
2147
+ poolShareDecimal: fracPart.length > 0 ? `${intPart}.${fracPart}` : intPart
2148
+ };
2149
+ };
2150
+ getLpAddSlippage = ({ pool, assetAmountBaseUnit, runeAmountBaseUnit }) => {
2151
+ const R = assertBaseUnitString(pool.runeDepth, "pool.runeDepth");
2152
+ const A = assertBaseUnitString(pool.assetDepth, "pool.assetDepth");
2153
+ const r = assertBaseUnitString(runeAmountBaseUnit, "runeAmountBaseUnit");
2154
+ const a = assertBaseUnitString(assetAmountBaseUnit, "assetAmountBaseUnit");
2155
+ if (R === 0n || A === 0n) {
2156
+ return { decimalPercent: "0", slippageInRuneBaseUnit: "0" };
2157
+ }
2158
+ const ra = R * a;
2159
+ const ar = A * r;
2160
+ const numerator = ra > ar ? ra - ar : ar - ra;
2161
+ const denominator = A * r + R * A;
2162
+ if (denominator === 0n) {
2163
+ return { decimalPercent: "0", slippageInRuneBaseUnit: "0" };
2164
+ }
2165
+ const SCALE = 10n ** 18n;
2166
+ const scaled = numerator * SCALE / denominator;
2167
+ const decimal = scaled.toString().padStart(19, "0");
2168
+ const intPart = decimal.slice(0, -18) || "0";
2169
+ const fracPart = decimal.slice(-18).replace(/0+$/, "");
2170
+ const decimalPercent = fracPart.length > 0 ? `${intPart}.${fracPart}` : intPart;
2171
+ const imbalanceNumerator = ra > ar ? ra - ar : ar - ra;
2172
+ const imbalanceInRune = A === 0n ? 0n : imbalanceNumerator / (2n * A);
2173
+ const slippageInRune = imbalanceInRune * scaled / SCALE;
2174
+ return {
2175
+ decimalPercent,
2176
+ slippageInRuneBaseUnit: slippageInRune.toString()
2177
+ };
2178
+ };
2179
+ estimateLpAdd = async ({ pool, assetAmountBaseUnit, runeAmountBaseUnit, thornodeBaseUrl }) => {
2180
+ assertValidPoolId(pool);
2181
+ const base = thornodeBaseUrl ?? cosmosRpcUrl[Chain9.THORChain];
2182
+ const url = `${base}/thorchain/pool/${encodeURIComponent(pool)}`;
2183
+ const raw = await queryUrl(url);
2184
+ if (!raw || typeof raw !== "object" || typeof raw.balance_asset !== "string" || typeof raw.balance_rune !== "string") {
2185
+ throw new Error(`estimateLpAdd: pool ${pool} response from ${url} missing balance fields`);
2186
+ }
2187
+ const poolUnitsRaw = raw.pool_units ?? raw.LP_units;
2188
+ if (typeof poolUnitsRaw !== "string" || poolUnitsRaw.length === 0) {
2189
+ throw new Error(`estimateLpAdd: pool ${pool} response from ${url} missing pool_units / LP_units`);
2190
+ }
2191
+ const poolState = {
2192
+ assetDepth: raw.balance_asset,
2193
+ runeDepth: raw.balance_rune,
2194
+ poolUnits: poolUnitsRaw
2195
+ };
2196
+ const liquidityUnits = getLiquidityUnits({
2197
+ pool: poolState,
2198
+ assetAmountBaseUnit,
2199
+ runeAmountBaseUnit
2200
+ });
2201
+ const share = getPoolShare({
2202
+ pool: poolState,
2203
+ liquidityUnits
2204
+ });
2205
+ const slip = getLpAddSlippage({
2206
+ pool: poolState,
2207
+ assetAmountBaseUnit,
2208
+ runeAmountBaseUnit
2209
+ });
2210
+ const R = BigInt(poolState.runeDepth);
2211
+ const A = BigInt(poolState.assetDepth);
2212
+ const P = BigInt(poolState.poolUnits);
2213
+ const r = BigInt(runeAmountBaseUnit);
2214
+ const a = BigInt(assetAmountBaseUnit);
2215
+ const L = BigInt(liquidityUnits);
2216
+ const totalAfter = P + L;
2217
+ const runeDepthAfter = R + r;
2218
+ const assetDepthAfter = A + a;
2219
+ const runeShareBaseUnit = totalAfter === 0n ? "0" : (runeDepthAfter * L / totalAfter).toString();
2220
+ const assetShareBaseUnit = totalAfter === 0n ? "0" : (assetDepthAfter * L / totalAfter).toString();
2221
+ return {
2222
+ liquidityUnits,
2223
+ poolShareDecimal: share.poolShareDecimal,
2224
+ runeShareBaseUnit,
2225
+ assetShareBaseUnit,
2226
+ slippageDecimal: slip.decimalPercent,
2227
+ slippageRuneBaseUnit: slip.slippageInRuneBaseUnit
2228
+ };
2229
+ };
2230
+ }
2231
+ });
2232
+
2233
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/positions.js
2234
+ var getThorchainLpPositions;
2235
+ var init_positions = __esm({
2236
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/positions.js"() {
2237
+ init_HttpResponseError();
2238
+ init_queryUrl();
2239
+ init_memberPool();
2240
+ init_pools();
2241
+ getThorchainLpPositions = async ({ thorAddress }) => {
2242
+ const url = `${thorchainMidgardBaseUrl}/v2/member/${encodeURIComponent(thorAddress)}`;
2243
+ let raw;
2244
+ try {
2245
+ raw = await queryUrl(url);
2246
+ } catch (err) {
2247
+ if (err instanceof HttpResponseError && err.status === 404)
2248
+ return [];
2249
+ throw err;
2250
+ }
2251
+ if (!raw || typeof raw !== "object") {
2252
+ throw new Error(`getThorchainLpPositions: unexpected Midgard response shape from ${url}`);
2253
+ }
2254
+ if (raw.pools === void 0) {
2255
+ return [];
2256
+ }
2257
+ if (!Array.isArray(raw.pools)) {
2258
+ throw new Error(`getThorchainLpPositions: Midgard response ${url} has non-array \`pools\` field`);
2259
+ }
2260
+ return raw.pools.map(normalizeMemberPool);
2261
+ };
2262
+ }
2263
+ });
2264
+
2265
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/lockup.js
2266
+ var THORCHAIN_BLOCK_TIME_SECONDS, getThorchainLpLockupSeconds, getLpWithdrawReadiness;
2267
+ var init_lockup = __esm({
2268
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/lockup.js"() {
2269
+ init_validation();
2270
+ THORCHAIN_BLOCK_TIME_SECONDS = 6;
2271
+ getThorchainLpLockupSeconds = async () => {
2272
+ const mimir = await getThorchainMimir();
2273
+ const blocks = mimir["LIQUIDITYLOCKUPBLOCKS"];
2274
+ if (typeof blocks !== "number" || !Number.isFinite(blocks) || blocks < 0) {
2275
+ throw new Error(`getThorchainLpLockupSeconds: mimir did not include a valid LIQUIDITYLOCKUPBLOCKS value`);
2276
+ }
2277
+ return blocks * THORCHAIN_BLOCK_TIME_SECONDS;
2278
+ };
2279
+ getLpWithdrawReadiness = async ({ position, lockupSeconds: providedLockupSeconds, nowUnix = Math.floor(Date.now() / 1e3) }) => {
2280
+ const lockupSeconds = providedLockupSeconds ?? await getThorchainLpLockupSeconds();
2281
+ const lastAdded = Number(position.dateLastAdded);
2282
+ if (!Number.isFinite(lastAdded) || lastAdded <= 0) {
2283
+ return {
2284
+ isWithdrawable: true,
2285
+ unlockAtUnix: 0,
2286
+ remainingSeconds: 0
2287
+ };
2288
+ }
2289
+ const unlockAtUnix = lastAdded + lockupSeconds;
2290
+ const remainingSeconds = Math.max(unlockAtUnix - nowUnix, 0);
2291
+ return {
2292
+ isWithdrawable: remainingSeconds === 0,
2293
+ unlockAtUnix,
2294
+ remainingSeconds
2295
+ };
2296
+ };
2297
+ }
2298
+ });
2299
+
2300
+ // ../../packages/core/chain/dist/chains/cosmos/thor/getThorchainInboundAddress.js
2301
+ var getThorchainInboundAddress_exports = {};
2302
+ __export(getThorchainInboundAddress_exports, {
2303
+ getThorchainInboundAddress: () => getThorchainInboundAddress
2304
+ });
2305
+ var thorchainInboundAddressApi, getThorchainInboundAddress;
2306
+ var init_getThorchainInboundAddress = __esm({
2307
+ "../../packages/core/chain/dist/chains/cosmos/thor/getThorchainInboundAddress.js"() {
2308
+ init_queryUrl();
2309
+ init_Chain();
2310
+ init_cosmosRpcUrl();
2311
+ thorchainInboundAddressApi = `${cosmosRpcUrl[Chain9.THORChain]}/thorchain/inbound_addresses`;
2312
+ getThorchainInboundAddress = () => queryUrl(thorchainInboundAddressApi);
2313
+ }
2314
+ });
2315
+
2316
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/halts.js
2317
+ var buildStatus, getThorchainLpHaltStatusAll, getThorchainLpHaltStatus, getThorchainLpPoolPauseStatus;
2318
+ var init_halts = __esm({
2319
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/halts.js"() {
2320
+ init_getThorchainInboundAddress();
2321
+ init_validation();
2322
+ buildStatus = (raw) => {
2323
+ const reasons = [];
2324
+ if (raw.halted)
2325
+ reasons.push(`${raw.chain} chain is halted`);
2326
+ if (raw.global_trading_paused)
2327
+ reasons.push("global trading paused");
2328
+ if (raw.chain_trading_paused)
2329
+ reasons.push(`${raw.chain} chain trading paused`);
2330
+ if (raw.chain_lp_actions_paused)
2331
+ reasons.push(`${raw.chain} LP actions paused`);
2332
+ const depositable = !raw.halted && !raw.chain_lp_actions_paused && !raw.chain_trading_paused && !raw.global_trading_paused;
2333
+ const withdrawable = !raw.halted && !raw.chain_lp_actions_paused;
2334
+ return {
2335
+ chain: raw.chain,
2336
+ depositable,
2337
+ withdrawable,
2338
+ reasons,
2339
+ raw: {
2340
+ halted: raw.halted,
2341
+ chain_trading_paused: raw.chain_trading_paused,
2342
+ chain_lp_actions_paused: raw.chain_lp_actions_paused,
2343
+ global_trading_paused: raw.global_trading_paused
2344
+ }
2345
+ };
2346
+ };
2347
+ getThorchainLpHaltStatusAll = async () => {
2348
+ const addresses = await getThorchainInboundAddress();
2349
+ return addresses.map((a) => buildStatus({
2350
+ chain: a.chain,
2351
+ halted: a.halted,
2352
+ chain_trading_paused: a.chain_trading_paused,
2353
+ chain_lp_actions_paused: a.chain_lp_actions_paused,
2354
+ global_trading_paused: a.global_trading_paused
2355
+ }));
2356
+ };
2357
+ getThorchainLpHaltStatus = async (chain) => {
2358
+ const all = await getThorchainLpHaltStatusAll();
2359
+ const upper = chain.toUpperCase();
2360
+ const match = all.find((s) => s.chain.toUpperCase() === upper);
2361
+ if (!match) {
2362
+ throw new Error(`getThorchainLpHaltStatus: chain ${chain} not found in inbound_addresses`);
2363
+ }
2364
+ return match;
2365
+ };
2366
+ getThorchainLpPoolPauseStatus = async (pool) => {
2367
+ const mimir = await getThorchainMimir();
2368
+ const mimirKey = poolPauseMimirKey(pool);
2369
+ const mimirValue = mimir[mimirKey];
2370
+ if (typeof mimirValue === "number" && mimirValue > 0) {
2371
+ return { paused: true, mimirKey, mimirValue };
2372
+ }
2373
+ return { paused: false };
2374
+ };
2375
+ }
2376
+ });
2377
+
2378
+ // ../../packages/core/chain/dist/chains/cosmos/thor/lp/index.js
2379
+ var lp_exports = {};
2380
+ __export(lp_exports, {
2381
+ THORCHAIN_BLOCK_TIME_SECONDS: () => THORCHAIN_BLOCK_TIME_SECONDS,
2382
+ addLpMemo: () => addLpMemo,
2383
+ assertPoolDepositable: () => assertPoolDepositable,
2384
+ assertValidPoolId: () => assertValidPoolId,
2385
+ buildThorchainLpAddPayload: () => buildThorchainLpAddPayload,
2386
+ buildThorchainLpRemovePayload: () => buildThorchainLpRemovePayload,
2387
+ chainPrefixToChain: () => chainPrefixToChain,
2388
+ chainToLpPrefix: () => chainToLpPrefix,
2389
+ estimateLpAdd: () => estimateLpAdd,
2390
+ getLiquidityUnits: () => getLiquidityUnits,
2391
+ getLpAddSlippage: () => getLpAddSlippage,
2392
+ getLpWithdrawReadiness: () => getLpWithdrawReadiness,
2393
+ getPoolShare: () => getPoolShare,
2394
+ getThorchainLpHaltStatus: () => getThorchainLpHaltStatus,
2395
+ getThorchainLpHaltStatusAll: () => getThorchainLpHaltStatusAll,
2396
+ getThorchainLpLockupSeconds: () => getThorchainLpLockupSeconds,
2397
+ getThorchainLpPoolPauseStatus: () => getThorchainLpPoolPauseStatus,
2398
+ getThorchainLpPosition: () => getThorchainLpPosition,
2399
+ getThorchainLpPositionFromThornode: () => getThorchainLpPositionFromThornode,
2400
+ getThorchainLpPositions: () => getThorchainLpPositions,
2401
+ getThorchainMimir: () => getThorchainMimir,
2402
+ getThorchainPools: () => getThorchainPools,
2403
+ isValidPoolId: () => isValidPoolId,
2404
+ lpChainMap: () => lpChainMap,
2405
+ poolPauseMimirKey: () => poolPauseMimirKey,
2406
+ removeLpMemo: () => removeLpMemo,
2407
+ resolvePairedAddressForLpAdd: () => resolvePairedAddressForLpAdd,
2408
+ thorchainMidgardBaseUrl: () => thorchainMidgardBaseUrl
2409
+ });
2410
+ var init_lp = __esm({
2411
+ "../../packages/core/chain/dist/chains/cosmos/thor/lp/index.js"() {
2412
+ init_memo();
2413
+ init_payload();
2414
+ init_pools();
2415
+ init_position();
2416
+ init_validation();
2417
+ init_pairing();
2418
+ init_lpChainMap();
2419
+ init_math();
2420
+ init_positions();
2421
+ init_lockup();
2422
+ init_halts();
1449
2423
  }
1450
2424
  });
1451
2425
 
@@ -4850,10 +5824,10 @@ async function authenticateVault(client, vault, password, maxAttempts = 3) {
4850
5824
  });
4851
5825
  const messageHash = computePersonalSignHash(authMessage);
4852
5826
  let lastError = null;
4853
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
5827
+ for (let attempt2 = 1; attempt2 <= maxAttempts; attempt2++) {
4854
5828
  try {
4855
- if (attempt > 1) {
4856
- process.stderr.write(` Retry ${attempt}/${maxAttempts}...
5829
+ if (attempt2 > 1) {
5830
+ process.stderr.write(` Retry ${attempt2}/${maxAttempts}...
4857
5831
  `);
4858
5832
  }
4859
5833
  const signature = await vault.signBytes({ data: Buffer.from(messageHash), chain: Chain7.Ethereum }, {});
@@ -4870,7 +5844,7 @@ async function authenticateVault(client, vault, password, maxAttempts = 3) {
4870
5844
  };
4871
5845
  } catch (err) {
4872
5846
  lastError = err;
4873
- if (attempt < maxAttempts && err.message?.includes("timeout")) {
5847
+ if (attempt2 < maxAttempts && err.message?.includes("timeout")) {
4874
5848
  continue;
4875
5849
  }
4876
5850
  throw err;
@@ -4931,6 +5905,18 @@ function padTo32Bytes(buf) {
4931
5905
  }
4932
5906
 
4933
5907
  // src/agent/client.ts
5908
+ function v1StatusFromType(type) {
5909
+ switch (type) {
5910
+ case "tool-input-start":
5911
+ case "tool-input-available":
5912
+ case "tool-input-delta":
5913
+ return "running";
5914
+ case "tool-output-available":
5915
+ return "done";
5916
+ default:
5917
+ return void 0;
5918
+ }
5919
+ }
4934
5920
  function sseErrorToMessage(value) {
4935
5921
  if (value == null) return "";
4936
5922
  if (typeof value === "string") return value;
@@ -5034,6 +6020,7 @@ var AgentClient = class {
5034
6020
  transactions: [],
5035
6021
  message: null
5036
6022
  };
6023
+ const toolNameByCallId = /* @__PURE__ */ new Map();
5037
6024
  const reader = res.body.getReader();
5038
6025
  const decoder = new TextDecoder();
5039
6026
  let buffer = "";
@@ -5048,7 +6035,7 @@ var AgentClient = class {
5048
6035
  currentData += (currentData ? "\n" : "") + stripLeadingSpace(line.slice(5));
5049
6036
  } else if (line === "") {
5050
6037
  if (currentData) {
5051
- this.handleSSEEvent(currentEvent || "message", currentData, result, callbacks);
6038
+ this.handleSSEEvent(currentEvent || "message", currentData, result, callbacks, toolNameByCallId);
5052
6039
  }
5053
6040
  currentEvent = "";
5054
6041
  currentData = "";
@@ -5068,7 +6055,7 @@ var AgentClient = class {
5068
6055
  if (done) {
5069
6056
  if (trailing) processLine(trailing);
5070
6057
  if (currentData) {
5071
- this.handleSSEEvent(currentEvent || "message", currentData, result, callbacks);
6058
+ this.handleSSEEvent(currentEvent || "message", currentData, result, callbacks, toolNameByCallId);
5072
6059
  }
5073
6060
  break;
5074
6061
  }
@@ -5078,71 +6065,75 @@ var AgentClient = class {
5078
6065
  }
5079
6066
  return result;
5080
6067
  }
5081
- handleSSEEvent(event, data, result, callbacks) {
6068
+ handleSSEEvent(event, data, result, callbacks, toolNameByCallId) {
5082
6069
  try {
5083
- const rawParsed = JSON.parse(data);
5084
- let resolvedEvent = event;
5085
- let parsed = rawParsed;
5086
- if (event === "message" && typeof rawParsed?.type === "string") {
5087
- const v1Type = rawParsed.type;
5088
- if (v1Type === "text-delta") {
5089
- resolvedEvent = "text_delta";
5090
- } else if (v1Type === "finish") {
5091
- resolvedEvent = "done";
5092
- } else if (v1Type === "error") {
5093
- resolvedEvent = "error";
5094
- parsed = { error: rawParsed.errorText ?? rawParsed.error };
5095
- } else if (v1Type.startsWith("data-")) {
5096
- resolvedEvent = v1Type.slice(5);
5097
- if (rawParsed.data && typeof rawParsed.data === "object" && !Array.isArray(rawParsed.data)) {
5098
- parsed = rawParsed.data;
5099
- }
5100
- } else {
5101
- resolvedEvent = v1Type;
5102
- if (this.verbose) process.stderr.write(`[SSE:unmapped v1 type: ${v1Type}]
5103
- `);
5104
- }
5105
- }
5106
- switch (resolvedEvent) {
6070
+ const parsed = JSON.parse(data);
6071
+ const v1Type = typeof parsed?.type === "string" && parsed.type.length > 0 ? parsed.type : null;
6072
+ const routingEvent = v1Type ? this.mapV1EventType(v1Type) : event;
6073
+ const v1Data = typeof parsed?.type === "string" && parsed.type.startsWith("data-") ? parsed.data : null;
6074
+ switch (routingEvent) {
5107
6075
  case "text_delta":
5108
6076
  if (typeof parsed.delta === "string") {
5109
6077
  result.fullText += parsed.delta;
5110
6078
  callbacks.onTextDelta?.(parsed.delta);
5111
6079
  }
5112
6080
  break;
5113
- case "tool_progress":
6081
+ case "tool_progress": {
5114
6082
  if (this.verbose) process.stderr.write(`[SSE:tool_progress] raw: ${data.slice(0, 1e3)}
5115
6083
  `);
5116
- callbacks.onToolProgress?.(parsed.tool, parsed.status, parsed.label);
6084
+ const v1Status = v1StatusFromType(v1Type);
6085
+ const status = parsed.status ?? v1Status;
6086
+ const callId = typeof parsed.toolCallId === "string" ? parsed.toolCallId : null;
6087
+ const rawInlineName = parsed.tool ?? parsed.toolName;
6088
+ const inlineName = typeof rawInlineName === "string" && rawInlineName.length > 0 ? rawInlineName : void 0;
6089
+ if (callId && inlineName) {
6090
+ toolNameByCallId.set(callId, inlineName);
6091
+ }
6092
+ const toolName = inlineName ?? (callId ? toolNameByCallId.get(callId) : void 0);
6093
+ const label = typeof parsed.label === "string" ? parsed.label : void 0;
6094
+ if (status && toolName) {
6095
+ callbacks.onToolProgress?.(toolName, status, label);
6096
+ }
6097
+ if (status === "done" && callId) toolNameByCallId.delete(callId);
5117
6098
  break;
5118
- case "title":
5119
- callbacks.onTitle?.(parsed.title);
6099
+ }
6100
+ case "title": {
6101
+ const title = v1Data?.title ?? parsed.title;
6102
+ if (typeof title === "string") callbacks.onTitle?.(title);
5120
6103
  break;
5121
- case "actions":
6104
+ }
6105
+ case "actions": {
5122
6106
  if (this.verbose) process.stderr.write(`[SSE:actions] raw: ${data.slice(0, 1e3)}
5123
6107
  `);
5124
- result.actions.push(...parsed.actions || []);
5125
- callbacks.onActions?.(parsed.actions || []);
6108
+ const actions = v1Data?.actions ?? parsed.actions ?? [];
6109
+ result.actions.push(...actions);
6110
+ callbacks.onActions?.(actions);
5126
6111
  break;
5127
- case "suggestions":
5128
- result.suggestions.push(...parsed.suggestions || []);
5129
- callbacks.onSuggestions?.(parsed.suggestions || []);
6112
+ }
6113
+ case "suggestions": {
6114
+ const suggestions = v1Data?.suggestions ?? parsed.suggestions ?? [];
6115
+ result.suggestions.push(...suggestions);
6116
+ callbacks.onSuggestions?.(suggestions);
5130
6117
  break;
6118
+ }
5131
6119
  case "tx_ready":
5132
6120
  if (this.verbose) process.stderr.write(`[SSE:tx_ready] raw: ${data.slice(0, 2e3)}
5133
6121
  `);
5134
6122
  {
5135
- const txReady = parsed;
6123
+ const txReady = v1Data ?? parsed;
5136
6124
  result.transactions.push(txReady);
5137
6125
  callbacks.onTxReady?.(txReady);
5138
6126
  }
5139
6127
  break;
5140
- case "message":
5141
- result.message = parsed.message || parsed;
6128
+ case "message": {
6129
+ const msg = v1Data?.message ?? parsed.message ?? parsed;
6130
+ result.message = msg;
5142
6131
  callbacks.onMessage?.(result.message);
5143
6132
  break;
6133
+ }
5144
6134
  case "error": {
5145
- const msg = sseErrorToMessage(parsed.error);
6135
+ const errorText = typeof parsed.errorText === "string" ? parsed.errorText : parsed.error;
6136
+ const msg = sseErrorToMessage(errorText);
5146
6137
  const codeFromBackend = typeof parsed.code === "string" && isAgentErrorCode(parsed.code) ? parsed.code : inferAgentErrorCodeFromMessage(msg);
5147
6138
  callbacks.onError?.(msg, codeFromBackend);
5148
6139
  break;
@@ -5159,6 +6150,37 @@ var AgentClient = class {
5159
6150
  }
5160
6151
  }
5161
6152
  }
6153
+ // Maps a V1 `type` field to the legacy event bucket used by handleSSEEvent's
6154
+ // switch. Frame-level types (start, text-start, text-end, finish-step) and
6155
+ // non-critical telemetry (data-tokens, data-usage, data-confirmation) route
6156
+ // to 'ignore' which is a no-op.
6157
+ mapV1EventType(type) {
6158
+ switch (type) {
6159
+ case "text-delta":
6160
+ return "text_delta";
6161
+ case "tool-input-start":
6162
+ case "tool-input-available":
6163
+ case "tool-input-delta":
6164
+ case "tool-output-available":
6165
+ return "tool_progress";
6166
+ case "data-title":
6167
+ return "title";
6168
+ case "data-actions":
6169
+ return "actions";
6170
+ case "data-suggestions":
6171
+ return "suggestions";
6172
+ case "data-tx_ready":
6173
+ return "tx_ready";
6174
+ case "data-message":
6175
+ return "message";
6176
+ case "error":
6177
+ return "error";
6178
+ case "finish":
6179
+ return "done";
6180
+ default:
6181
+ return "ignore";
6182
+ }
6183
+ }
5162
6184
  // ============================================================================
5163
6185
  // Calldata
5164
6186
  // ============================================================================
@@ -5353,9 +6375,9 @@ function getNativeTokenDecimals(chain) {
5353
6375
  }
5354
6376
 
5355
6377
  // src/agent/executor.ts
5356
- import { Chain as Chain9, evmCall, fiatCurrencies as fiatCurrencies3, Vultisig as VultisigSdk } from "@vultisig/sdk";
6378
+ import { Chain as Chain10, evmCall, fiatCurrencies as fiatCurrencies3, Vultisig as VultisigSdk } from "@vultisig/sdk";
5357
6379
 
5358
- // node_modules/viem/_esm/index.js
6380
+ // ../../node_modules/viem/_esm/index.js
5359
6381
  init_formatUnits();
5360
6382
 
5361
6383
  // src/core/VaultStateStore.ts
@@ -5533,7 +6555,10 @@ var AUTO_EXECUTE_ACTIONS = /* @__PURE__ */ new Set([
5533
6555
  "sign_tx",
5534
6556
  "sign_typed_data",
5535
6557
  "read_evm_contract",
5536
- "scan_tx"
6558
+ "scan_tx",
6559
+ "thorchain_pool_info",
6560
+ "thorchain_add_liquidity",
6561
+ "thorchain_remove_liquidity"
5537
6562
  ]);
5538
6563
  var PASSWORD_REQUIRED_ACTIONS = /* @__PURE__ */ new Set(["sign_tx", "sign_typed_data", "build_custom_tx"]);
5539
6564
 
@@ -5568,7 +6593,7 @@ var EVM_GAS_RPC = {
5568
6593
  Hyperliquid: "https://rpc.hyperliquid.xyz/evm",
5569
6594
  Sei: "https://evm-rpc.sei-apis.com"
5570
6595
  };
5571
- var AgentExecutor = class {
6596
+ var AgentExecutor = class _AgentExecutor {
5572
6597
  vault;
5573
6598
  /** Owning SDK (optional); used for address book backed by app storage */
5574
6599
  vultisig;
@@ -5619,7 +6644,7 @@ var AgentExecutor = class {
5619
6644
  `);
5620
6645
  return false;
5621
6646
  }
5622
- const chain = resolveChainFromTxReady(txReadyData) || Chain9.Ethereum;
6647
+ const chain = resolveChainFromTxReady(txReadyData) || Chain10.Ethereum;
5623
6648
  this.pendingPayloads.clear();
5624
6649
  this.pendingPayloads.set("latest", {
5625
6650
  payload: { __serverTx: true, ...txReadyData },
@@ -5708,6 +6733,12 @@ var AgentExecutor = class {
5708
6733
  return this.scanTx(params);
5709
6734
  case "read_evm_contract":
5710
6735
  return this.readEvmContract(params);
6736
+ case "thorchain_pool_info":
6737
+ return this.thorchainPoolInfo(params);
6738
+ case "thorchain_add_liquidity":
6739
+ return this.thorchainAddLiquidity(params);
6740
+ case "thorchain_remove_liquidity":
6741
+ return this.thorchainRemoveLiquidity(params);
5711
6742
  default:
5712
6743
  throw new Error(
5713
6744
  `Action type '${action.type}' is not implemented locally. The backend may handle this action server-side.`
@@ -5977,6 +7008,227 @@ var AgentExecutor = class {
5977
7008
  throw err;
5978
7009
  }
5979
7010
  }
7011
+ // ============================================================================
7012
+ // THORChain LP (RUNE-side asym add / remove via prepareSendTx + memo)
7013
+ // ============================================================================
7014
+ /**
7015
+ * Pool stats from Midgard (no signing). Optional `pool` filters to one row.
7016
+ */
7017
+ async thorchainPoolInfo(params) {
7018
+ const { assertValidPoolId: assertValidPoolId2, getThorchainPools: getThorchainPools2, thorchainMidgardBaseUrl: thorchainMidgardBaseUrl2 } = await Promise.resolve().then(() => (init_lp(), lp_exports));
7019
+ const statusRaw = params.status;
7020
+ let poolFetchOpts = {};
7021
+ if (statusRaw === null || String(statusRaw).toLowerCase() === "all") {
7022
+ poolFetchOpts = { status: null };
7023
+ } else if (statusRaw !== void 0) {
7024
+ poolFetchOpts = { status: String(statusRaw) };
7025
+ }
7026
+ const pools = await getThorchainPools2(poolFetchOpts);
7027
+ const poolArg = params.pool;
7028
+ if (poolArg) {
7029
+ const normalized = poolArg.trim().toUpperCase();
7030
+ assertValidPoolId2(normalized);
7031
+ const row = pools.find((p) => p.asset.toUpperCase() === normalized);
7032
+ return {
7033
+ found: !!row,
7034
+ pool_id: normalized,
7035
+ summary: row ?? null,
7036
+ midgard: thorchainMidgardBaseUrl2
7037
+ };
7038
+ }
7039
+ const limitRaw = params.limit;
7040
+ const limit = Math.min(500, Math.max(1, typeof limitRaw === "number" ? limitRaw : Number(limitRaw) || 80));
7041
+ return {
7042
+ pools: pools.slice(0, limit),
7043
+ total: pools.length,
7044
+ midgard: thorchainMidgardBaseUrl2
7045
+ };
7046
+ }
7047
+ async thorchainAddLiquidity(params) {
7048
+ const { assertValidPoolId: assertValidPoolId2, buildThorchainLpAddPayload: buildThorchainLpAddPayload2, resolvePairedAddressForLpAdd: resolvePairedAddressForLpAdd2 } = await Promise.resolve().then(() => (init_lp(), lp_exports));
7049
+ const { getThorchainInboundAddress: getThorchainInboundAddress2 } = await Promise.resolve().then(() => (init_getThorchainInboundAddress(), getThorchainInboundAddress_exports));
7050
+ const pool = this.normalizeThorchainPoolId(params.pool, assertValidPoolId2);
7051
+ const amountStr = String(params.amount ?? "").trim();
7052
+ if (!amountStr) {
7053
+ throw new Error('amount is required (RUNE amount as a decimal string, e.g. "0.25")');
7054
+ }
7055
+ if (!/^\d+(\.\d+)?$/.test(amountStr)) {
7056
+ throw new Error('amount must be a positive decimal string (no sign or scientific notation), e.g. "0.25"');
7057
+ }
7058
+ const [, frac = ""] = amountStr.split(".");
7059
+ if (frac.length > 8) {
7060
+ throw new Error("RUNE amount supports at most 8 decimal places");
7061
+ }
7062
+ const amountRuneBaseUnits = parseAmount(amountStr, 8);
7063
+ if (amountRuneBaseUnits <= 0n) {
7064
+ throw new Error("amount must be greater than zero");
7065
+ }
7066
+ let pairedAddress = params.paired_address?.trim() || void 0;
7067
+ const autoPairRaw = params.auto_pair ?? params.autoPair;
7068
+ const autoPairDisabled = autoPairRaw === false || autoPairRaw === 0 || typeof autoPairRaw === "string" && ["false", "0"].includes(autoPairRaw.toLowerCase());
7069
+ const autoPair = !pairedAddress && !autoPairDisabled;
7070
+ if (autoPair) {
7071
+ const vaultAddresses = await this.buildVaultAddressMap();
7072
+ pairedAddress = resolvePairedAddressForLpAdd2({
7073
+ pool,
7074
+ side: "rune",
7075
+ vaultAddresses
7076
+ }) || void 0;
7077
+ }
7078
+ const lpPayload = buildThorchainLpAddPayload2({
7079
+ pool,
7080
+ amountRuneBaseUnits: amountRuneBaseUnits.toString(),
7081
+ ...pairedAddress ? { pairedAddress } : {}
7082
+ });
7083
+ const receiver = await this.getThorchainNativeInboundAddress(getThorchainInboundAddress2);
7084
+ const address = await this.vault.address(Chain10.THORChain);
7085
+ const coin = {
7086
+ chain: Chain10.THORChain,
7087
+ address,
7088
+ decimals: 8,
7089
+ ticker: "RUNE"
7090
+ };
7091
+ const payload = await this.vault.prepareSendTx({
7092
+ coin,
7093
+ receiver,
7094
+ amount: BigInt(lpPayload.amount),
7095
+ memo: lpPayload.memo
7096
+ });
7097
+ const messageHashes = await this.vault.extractMessageHashes(payload);
7098
+ this.pendingPayloads.clear();
7099
+ const payloadId = `tc_lp_add_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
7100
+ this.pendingPayloads.set(payloadId, {
7101
+ payload,
7102
+ coin,
7103
+ chain: Chain10.THORChain,
7104
+ timestamp: Date.now()
7105
+ });
7106
+ this.pendingPayloads.set("latest", {
7107
+ payload,
7108
+ coin,
7109
+ chain: Chain10.THORChain,
7110
+ timestamp: Date.now()
7111
+ });
7112
+ return {
7113
+ keysign_payload: payloadId,
7114
+ chain: "THORChain",
7115
+ pool: lpPayload.pool,
7116
+ memo: lpPayload.memo,
7117
+ amount_rune: amountStr,
7118
+ paired_address: pairedAddress,
7119
+ inbound_receiver: receiver,
7120
+ sender: address,
7121
+ message_hashes: messageHashes
7122
+ };
7123
+ }
7124
+ async thorchainRemoveLiquidity(params) {
7125
+ const { assertValidPoolId: assertValidPoolId2, buildThorchainLpRemovePayload: buildThorchainLpRemovePayload2 } = await Promise.resolve().then(() => (init_lp(), lp_exports));
7126
+ const { getThorchainInboundAddress: getThorchainInboundAddress2 } = await Promise.resolve().then(() => (init_getThorchainInboundAddress(), getThorchainInboundAddress_exports));
7127
+ const pool = this.normalizeThorchainPoolId(params.pool, assertValidPoolId2);
7128
+ let basisPoints;
7129
+ if (params.basis_points != null) {
7130
+ basisPoints = Number(params.basis_points);
7131
+ } else if (params.basisPoints != null) {
7132
+ basisPoints = Number(params.basisPoints);
7133
+ }
7134
+ if (basisPoints == null && params.withdraw_percent != null) {
7135
+ const pct = Number(params.withdraw_percent);
7136
+ if (Number.isFinite(pct)) {
7137
+ basisPoints = Math.round(pct * 100);
7138
+ }
7139
+ }
7140
+ if (basisPoints == null || !Number.isInteger(basisPoints)) {
7141
+ throw new Error("basis_points (integer 1\u201310000) or withdraw_percent (0.01\u2013100, maps to basis points) is required");
7142
+ }
7143
+ let withdrawToAsset = params.withdraw_to_asset?.trim();
7144
+ if (!withdrawToAsset && params.withdrawToAsset) {
7145
+ withdrawToAsset = String(params.withdrawToAsset).trim();
7146
+ }
7147
+ if (withdrawToAsset) {
7148
+ withdrawToAsset = withdrawToAsset.toUpperCase();
7149
+ }
7150
+ const lpPayload = buildThorchainLpRemovePayload2({
7151
+ pool,
7152
+ basisPoints,
7153
+ ...withdrawToAsset ? { withdrawToAsset } : {}
7154
+ });
7155
+ const receiver = await this.getThorchainNativeInboundAddress(getThorchainInboundAddress2);
7156
+ const address = await this.vault.address(Chain10.THORChain);
7157
+ const coin = {
7158
+ chain: Chain10.THORChain,
7159
+ address,
7160
+ decimals: 8,
7161
+ ticker: "RUNE"
7162
+ };
7163
+ const payload = await this.vault.prepareSendTx({
7164
+ coin,
7165
+ receiver,
7166
+ amount: BigInt(lpPayload.amount),
7167
+ memo: lpPayload.memo
7168
+ });
7169
+ const messageHashes = await this.vault.extractMessageHashes(payload);
7170
+ this.pendingPayloads.clear();
7171
+ const payloadId = `tc_lp_rm_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
7172
+ this.pendingPayloads.set(payloadId, {
7173
+ payload,
7174
+ coin,
7175
+ chain: Chain10.THORChain,
7176
+ timestamp: Date.now()
7177
+ });
7178
+ this.pendingPayloads.set("latest", {
7179
+ payload,
7180
+ coin,
7181
+ chain: Chain10.THORChain,
7182
+ timestamp: Date.now()
7183
+ });
7184
+ return {
7185
+ keysign_payload: payloadId,
7186
+ chain: "THORChain",
7187
+ pool: lpPayload.pool,
7188
+ memo: lpPayload.memo,
7189
+ basis_points: basisPoints,
7190
+ withdraw_to_asset: withdrawToAsset || void 0,
7191
+ dust_rune_base_units: lpPayload.amount,
7192
+ inbound_receiver: receiver,
7193
+ sender: address,
7194
+ message_hashes: messageHashes
7195
+ };
7196
+ }
7197
+ normalizeThorchainPoolId(raw, assertValidPoolId2) {
7198
+ const pool = String(raw ?? "").trim();
7199
+ if (!pool) {
7200
+ throw new Error('pool is required (e.g. "BTC.BTC")');
7201
+ }
7202
+ const upper = pool.toUpperCase();
7203
+ assertValidPoolId2(upper);
7204
+ return upper;
7205
+ }
7206
+ async buildVaultAddressMap() {
7207
+ const map = {};
7208
+ for (const c of this.vault.chains) {
7209
+ try {
7210
+ map[c] = await this.vault.address(c);
7211
+ } catch {
7212
+ }
7213
+ }
7214
+ return map;
7215
+ }
7216
+ /** THORChain protocol vault for native RUNE deposits (SWAP/LP memos). Matches SDK e2e fixture. */
7217
+ static THORCHAIN_RUNE_DEPOSIT_ADDRESS = "thor1g98cy3n9mmjrpn0sxmn63lztelera37n8n67c0";
7218
+ async getThorchainNativeInboundAddress(getInbound) {
7219
+ const rows = await getInbound();
7220
+ const thor = rows.find((r) => r.chain.toUpperCase() === "THOR");
7221
+ if (thor?.address) {
7222
+ return thor.address;
7223
+ }
7224
+ if (this.verbose) {
7225
+ process.stderr.write(
7226
+ `[thorchain_lp] THOR inbound row missing; using static RUNE deposit vault ${_AgentExecutor.THORCHAIN_RUNE_DEPOSIT_ADDRESS}
7227
+ `
7228
+ );
7229
+ }
7230
+ return _AgentExecutor.THORCHAIN_RUNE_DEPOSIT_ADDRESS;
7231
+ }
5980
7232
  async buildTx(params) {
5981
7233
  if (params.calldata_id && !params.data && this.backendClient) {
5982
7234
  const id = params.calldata_id;
@@ -6008,7 +7260,7 @@ var AgentExecutor = class {
6008
7260
  if (!stored) {
6009
7261
  throw new Error("Could not stage calldata transaction for signing (invalid or empty tx payload)");
6010
7262
  }
6011
- const chain = resolveChain(params.chain) || Chain9.Ethereum;
7263
+ const chain = resolveChain(params.chain) || Chain10.Ethereum;
6012
7264
  const address = await this.vault.address(chain);
6013
7265
  return {
6014
7266
  status: "ready",
@@ -6559,11 +7811,11 @@ var AgentExecutor = class {
6559
7811
  `);
6560
7812
  const chainName = params.chain;
6561
7813
  const chainId = domain.chainId;
6562
- let chain = Chain9.Ethereum;
7814
+ let chain = Chain10.Ethereum;
6563
7815
  if (chainName) {
6564
- chain = resolveChain(chainName) || Chain9.Ethereum;
7816
+ chain = resolveChain(chainName) || Chain10.Ethereum;
6565
7817
  } else if (chainId) {
6566
- chain = resolveChainId(chainId) || Chain9.Ethereum;
7818
+ chain = resolveChainId(chainId) || Chain10.Ethereum;
6567
7819
  }
6568
7820
  const sigResult = await this.vault.signBytes({
6569
7821
  data: eip712Hash,
@@ -6633,7 +7885,7 @@ var AgentExecutor = class {
6633
7885
  return { tokens };
6634
7886
  }
6635
7887
  const out = [];
6636
- for (const c of Object.values(Chain9)) {
7888
+ for (const c of Object.values(Chain10)) {
6637
7889
  for (const t of VultisigSdk.getKnownTokens(c)) {
6638
7890
  if (!tokenMatchesQuery(t)) continue;
6639
7891
  out.push(t);
@@ -6716,11 +7968,11 @@ function abiEncodeParam(type, value) {
6716
7968
  }
6717
7969
  function resolveChain(name) {
6718
7970
  if (!name) return null;
6719
- if (Object.values(Chain9).includes(name)) {
7971
+ if (Object.values(Chain10).includes(name)) {
6720
7972
  return name;
6721
7973
  }
6722
7974
  const lower = name.toLowerCase();
6723
- for (const [, value] of Object.entries(Chain9)) {
7975
+ for (const [, value] of Object.entries(Chain10)) {
6724
7976
  if (typeof value === "string" && value.toLowerCase() === lower) {
6725
7977
  return value;
6726
7978
  }
@@ -6746,7 +7998,7 @@ function resolveChain(name) {
6746
7998
  xrp: "Ripple"
6747
7999
  };
6748
8000
  const aliased = aliases[lower];
6749
- if (aliased && Object.values(Chain9).includes(aliased)) {
8001
+ if (aliased && Object.values(Chain10).includes(aliased)) {
6750
8002
  return aliased;
6751
8003
  }
6752
8004
  return null;
@@ -6780,16 +8032,16 @@ function resolveChainId(chainId) {
6780
8032
  const id = typeof chainId === "string" ? parseInt(chainId, 10) : chainId;
6781
8033
  if (isNaN(id)) return null;
6782
8034
  const chainIdMap = {
6783
- 1: Chain9.Ethereum,
6784
- 56: Chain9.BSC,
6785
- 137: Chain9.Polygon,
6786
- 43114: Chain9.Avalanche,
6787
- 42161: Chain9.Arbitrum,
6788
- 10: Chain9.Optimism,
6789
- 8453: Chain9.Base,
6790
- 81457: Chain9.Blast,
6791
- 324: Chain9.Zksync,
6792
- 25: Chain9.CronosChain
8035
+ 1: Chain10.Ethereum,
8036
+ 56: Chain10.BSC,
8037
+ 137: Chain10.Polygon,
8038
+ 43114: Chain10.Avalanche,
8039
+ 42161: Chain10.Arbitrum,
8040
+ 10: Chain10.Optimism,
8041
+ 8453: Chain10.Base,
8042
+ 81457: Chain10.Blast,
8043
+ 324: Chain10.Zksync,
8044
+ 25: Chain10.CronosChain
6793
8045
  };
6794
8046
  return chainIdMap[id] || null;
6795
8047
  }
@@ -8091,7 +9343,7 @@ var cachedVersion = null;
8091
9343
  function getVersion() {
8092
9344
  if (cachedVersion) return cachedVersion;
8093
9345
  if (true) {
8094
- cachedVersion = "0.16.0";
9346
+ cachedVersion = "0.17.0";
8095
9347
  return cachedVersion;
8096
9348
  }
8097
9349
  try {
@@ -8374,7 +9626,7 @@ function readArgValue(args, optionName) {
8374
9626
  }
8375
9627
 
8376
9628
  // src/interactive/completer.ts
8377
- import { Chain as Chain10 } from "@vultisig/sdk";
9629
+ import { Chain as Chain11 } from "@vultisig/sdk";
8378
9630
  import fs3 from "fs";
8379
9631
  import path3 from "path";
8380
9632
  var COMMANDS = [
@@ -8518,7 +9770,7 @@ function completeVaultName(ctx2, partial) {
8518
9770
  return [show, partial];
8519
9771
  }
8520
9772
  function completeChainName(partial) {
8521
- const allChains = Object.values(Chain10);
9773
+ const allChains = Object.values(Chain11);
8522
9774
  const partialLower = partial.toLowerCase();
8523
9775
  const matches = allChains.filter((chain) => chain.toLowerCase().startsWith(partialLower));
8524
9776
  matches.sort();
@@ -8526,7 +9778,7 @@ function completeChainName(partial) {
8526
9778
  return [show, partial];
8527
9779
  }
8528
9780
  function findChainByName(name) {
8529
- const allChains = Object.values(Chain10);
9781
+ const allChains = Object.values(Chain11);
8530
9782
  const nameLower = name.toLowerCase();
8531
9783
  const found = allChains.find((chain) => chain.toLowerCase() === nameLower);
8532
9784
  return found ? found : null;