@owney/sdk 0.7.28-beta.6 → 0.7.28-beta.8

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/index.cjs CHANGED
@@ -351,6 +351,9 @@ var NAME_TO_CHAIN_ID = Object.entries(
351
351
  acc[name.toLowerCase()] = Number(id);
352
352
  return acc;
353
353
  }, {});
354
+ NAME_TO_CHAIN_ID.mainnet = 1;
355
+ NAME_TO_CHAIN_ID["ethereum mainnet"] = 1;
356
+ NAME_TO_CHAIN_ID["arbitrum one"] = 42161;
354
357
  function resolveChainId(chain) {
355
358
  const asNum = Number(chain);
356
359
  if (Number.isFinite(asNum) && asNum > 0) return asNum;
@@ -1470,9 +1473,22 @@ var ZyfaiAgent = class _ZyfaiAgent {
1470
1473
  this.sdk.getUserDetails(asset),
1471
1474
  this.sdk.getAvailableProtocols(chainId)
1472
1475
  ]);
1476
+ debugLog("zyfai:protocol-sync", `${asset}: profile before sync`, {
1477
+ chains: current.chains,
1478
+ protocols: current.protocols,
1479
+ strategy: current.strategy
1480
+ });
1481
+ if ((current.chains?.length ?? 0) === 0 && (current.protocols?.length ?? 0) === 0) {
1482
+ debugLog(
1483
+ "zyfai:protocol-sync",
1484
+ `${asset}: skipping untouched profile until first deposit`
1485
+ );
1486
+ return;
1487
+ }
1473
1488
  const update = buildProtocolMergeUpdate(available, current, asset);
1474
1489
  if (!update) return;
1475
1490
  await this.sdk.updateUserProfile(update);
1491
+ debugLog("zyfai:protocol-sync", `${asset}: wrote profile update`, update);
1476
1492
  } catch (error) {
1477
1493
  console.warn(
1478
1494
  "[zyfai] ensureProtocolsSynced failed (non-fatal):",
@@ -1514,6 +1530,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
1514
1530
  // --- IAgent: Account lifecycle ---
1515
1531
  async activateAgent(state, chainId) {
1516
1532
  try {
1533
+ debugLog("zyfai:activation", "starting", {
1534
+ walletAddress: state.walletAddress,
1535
+ chainId
1536
+ });
1517
1537
  await this.connectAuth(state, chainId);
1518
1538
  const validChainId = isValidChainId(chainId);
1519
1539
  await Promise.all([
@@ -1525,6 +1545,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1525
1545
  // validator, so pool-wallet users see no prompt. Non-fatal.
1526
1546
  this.ensureSessionKeyIfDeployed(validChainId)
1527
1547
  ]);
1548
+ debugLog("zyfai:activation", "completed", { chainId: validChainId });
1528
1549
  } catch (error) {
1529
1550
  throw error;
1530
1551
  }
@@ -1607,6 +1628,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1607
1628
  */
1608
1629
  async applyPoolPolicy(policy, opts = {}) {
1609
1630
  try {
1631
+ await this.sdk.ensureFirstDepositSetup("aggressive");
1610
1632
  const { protocols: universe } = await this.sdk.getAvailableProtocols(
1611
1633
  this.supportedChainIds[0]
1612
1634
  );
@@ -1737,9 +1759,11 @@ var ZyfaiAgent = class _ZyfaiAgent {
1737
1759
  * Persist an explicitly saved deposit-time draft at Zyfai profile level.
1738
1760
  * Pool choices are merged into protocol/chain records and each active asset
1739
1761
  * is kept at aggressive unless the draft includes a yieldmaxxing-only pool.
1762
+ * The whole operation must succeed before the caller starts moving funds.
1740
1763
  */
1741
1764
  async setPoolSelection(selection) {
1742
1765
  try {
1766
+ await this.sdk.ensureFirstDepositSetup("aggressive");
1743
1767
  const byPair = /* @__PURE__ */ new Map();
1744
1768
  for (const entry of selection.selections) {
1745
1769
  const pair = `${entry.protocolId}:${entry.chainId}`;
@@ -1747,39 +1771,31 @@ var ZyfaiAgent = class _ZyfaiAgent {
1747
1771
  group.push(entry);
1748
1772
  byPair.set(pair, group);
1749
1773
  }
1750
- const customizations = (await Promise.all(
1774
+ const customizations = await Promise.all(
1751
1775
  [...byPair.values()].map(async (scoped) => {
1752
1776
  const { protocolId, chainId } = scoped[0];
1753
- try {
1754
- const [current, rawAvailable] = await Promise.all([
1755
- this.sdk.getSelectedPools(protocolId, chainId),
1756
- this.sdk.getAvailablePools(protocolId, "yieldmaxxing")
1757
- ]);
1758
- const allAvailableNames = mapAvailablePools(rawAvailable).filter((pool) => pool.chainId === chainId).map((pool) => pool.name);
1759
- return {
1760
- protocolId,
1761
- chainId,
1762
- pools: mergeScopedPoolNames(
1763
- {
1764
- pools: current.pools ?? [],
1765
- autoselect: current.autoselect
1766
- },
1767
- scoped,
1768
- allAvailableNames
1769
- ),
1770
- // An explicit Save freezes exactly the choices the user saw.
1771
- // This also lets an empty list disable the pair deliberately.
1772
- autoselect: false
1773
- };
1774
- } catch (error) {
1775
- console.warn(
1776
- `[zyfai] setPoolSelection: preserving ${protocolId}/${chainId} failed; skipping the pair:`,
1777
- error instanceof Error ? error.message : String(error)
1778
- );
1779
- return null;
1780
- }
1777
+ const [current, rawAvailable] = await Promise.all([
1778
+ this.sdk.getSelectedPools(protocolId, chainId),
1779
+ this.sdk.getAvailablePools(protocolId, "yieldmaxxing")
1780
+ ]);
1781
+ const allAvailableNames = mapAvailablePools(rawAvailable).filter((pool) => pool.chainId === chainId).map((pool) => pool.name);
1782
+ return {
1783
+ protocolId,
1784
+ chainId,
1785
+ pools: mergeScopedPoolNames(
1786
+ {
1787
+ pools: current.pools ?? [],
1788
+ autoselect: current.autoselect
1789
+ },
1790
+ scoped,
1791
+ allAvailableNames
1792
+ ),
1793
+ // An explicit Save freezes exactly the choices the user saw.
1794
+ // This also lets an empty list disable the pair deliberately.
1795
+ autoselect: false
1796
+ };
1781
1797
  })
1782
- )).filter((value) => value !== null);
1798
+ );
1783
1799
  if (customizations.length > 0) {
1784
1800
  await this.sdk.customizeBatch(customizations);
1785
1801
  }
@@ -1797,9 +1813,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
1797
1813
  );
1798
1814
  } catch (error) {
1799
1815
  console.warn(
1800
- "[zyfai] setPoolSelection failed (non-fatal):",
1816
+ "[zyfai] setPoolSelection failed:",
1801
1817
  error instanceof Error ? error.message : String(error)
1802
1818
  );
1819
+ throw error;
1803
1820
  }
1804
1821
  }
1805
1822
  /**
@@ -1808,17 +1825,18 @@ var ZyfaiAgent = class _ZyfaiAgent {
1808
1825
  * pairs and assets asked about. A pair still on autoselect, or one whose
1809
1826
  * lookup fails, is left out so the caller falls back to its default for it.
1810
1827
  */
1811
- async getPoolSelection(params) {
1828
+ async getPoolSelection(state, chainId, params) {
1829
+ await this.connectAuth(state, chainId);
1812
1830
  const [pairs, strategies] = await Promise.all([
1813
1831
  Promise.all(
1814
- params.pairs.map(async ({ protocolId, chainId }) => {
1832
+ params.pairs.map(async ({ protocolId, chainId: chainId2 }) => {
1815
1833
  try {
1816
1834
  const current = await this.sdk.getSelectedPools(
1817
1835
  protocolId,
1818
- chainId
1836
+ chainId2
1819
1837
  );
1820
1838
  if (current.autoselect) return null;
1821
- return { protocolId, chainId, pools: current.pools ?? [] };
1839
+ return { protocolId, chainId: chainId2, pools: current.pools ?? [] };
1822
1840
  } catch {
1823
1841
  return null;
1824
1842
  }
@@ -2135,6 +2153,33 @@ var ZyfaiAgent = class _ZyfaiAgent {
2135
2153
  const validChainId = isValidChainId(chainId);
2136
2154
  await this.ensureConnected(state, validChainId);
2137
2155
  if (depositCallback) {
2156
+ debugLog("zyfai:first-deposit", "starting sponsored deposit setup", {
2157
+ asset,
2158
+ chainId: validChainId,
2159
+ requestedStrategy: "aggressive"
2160
+ });
2161
+ const setupResult = await this.sdk.ensureFirstDepositSetup("aggressive");
2162
+ debugLog("zyfai:first-deposit", "setup call completed", {
2163
+ requestedStrategy: "aggressive",
2164
+ setupResult
2165
+ });
2166
+ if (isOwneyDebug()) {
2167
+ try {
2168
+ const profileAfterSetup = await this.sdk.getUserDetails(
2169
+ asset === "WETH" ? "WETH" : "USDC"
2170
+ );
2171
+ debugLog("zyfai:first-deposit", "profile immediately after setup", {
2172
+ asset,
2173
+ strategy: profileAfterSetup.strategy,
2174
+ chains: profileAfterSetup.chains,
2175
+ protocols: profileAfterSetup.protocols
2176
+ });
2177
+ } catch (debugError) {
2178
+ debugLog("zyfai:first-deposit", "post-setup profile read failed", {
2179
+ error: debugError instanceof Error ? debugError.message : String(debugError)
2180
+ });
2181
+ }
2182
+ }
2138
2183
  const smartWallet = await this.ensureWalletDeployed(
2139
2184
  this.getAddress(),
2140
2185
  validChainId
@@ -2152,7 +2197,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
2152
2197
  return { txHash, smartWallet, amount };
2153
2198
  }
2154
2199
  await this.ensureWalletDeployed(this.getAddress(), validChainId);
2155
- const raw = await this.sdk.depositFunds(
2200
+ const raw = await this.sdk.sendDeposit(
2156
2201
  this.getAddress(),
2157
2202
  validChainId,
2158
2203
  amount,
@@ -2349,6 +2394,19 @@ var ZyfaiAgent = class _ZyfaiAgent {
2349
2394
  async ensureAutoSelectProtocols(state, chainId, asset) {
2350
2395
  await this.connectAuth(state, chainId);
2351
2396
  const current = await this.sdk.getUserDetails(asset);
2397
+ debugLog("zyfai:auto-select", `${asset}: profile before check`, {
2398
+ autoSelectProtocols: current.autoSelectProtocols,
2399
+ chains: current.chains,
2400
+ protocols: current.protocols,
2401
+ strategy: current.strategy
2402
+ });
2403
+ if ((current.chains?.length ?? 0) === 0) {
2404
+ debugLog(
2405
+ "zyfai:auto-select",
2406
+ `${asset}: skipping untouched profile until first deposit`
2407
+ );
2408
+ return false;
2409
+ }
2352
2410
  const update = buildAutoSelectUpdate(
2353
2411
  {
2354
2412
  autoSelectProtocols: current.autoSelectProtocols,
@@ -2359,6 +2417,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
2359
2417
  );
2360
2418
  if (!update) return false;
2361
2419
  await this.sdk.updateUserProfile(update);
2420
+ debugLog("zyfai:auto-select", `${asset}: wrote profile update`, update);
2362
2421
  return true;
2363
2422
  }
2364
2423
  // --- IAgent: Discovery (no wallet required) ---
@@ -3427,7 +3486,14 @@ async function executeSwap(deps, options) {
3427
3486
  try {
3428
3487
  result = quote.rail === "classic" ? await runClassic(deps, options) : quote.rail === "fusion" ? await runSameChainFusion(deps, options, walletAddress) : await runFusion(deps, options, walletAddress);
3429
3488
  } catch (error) {
3430
- if (!stoppedWatching(error)) throw error;
3489
+ if (!stoppedWatching(error)) {
3490
+ if (quote.rail !== "fusion") throw error;
3491
+ const now = await deps.readTargetBalance().catch(() => before);
3492
+ if (now <= before) throw error;
3493
+ debugLog("owney-sdk", "swap: rail said no but the funds are here", {
3494
+ message: error instanceof Error ? error.message : String(error)
3495
+ });
3496
+ }
3431
3497
  railError = error;
3432
3498
  debugLog("owney-sdk", "swap: rail failed, checking whether funds landed", {
3433
3499
  message: error instanceof Error ? error.message : String(error)
@@ -6804,6 +6870,8 @@ var OwneySDK = class {
6804
6870
  * `assets` say which protocol/chain lists and strategies to read.
6805
6871
  */
6806
6872
  async getPoolSelection(params) {
6873
+ const state = this.requireState();
6874
+ const chainId = this.requireChainId();
6807
6875
  await this.ensureAgentsInitialized();
6808
6876
  const agent = this.getAgent(params.agentId ?? "zyfai");
6809
6877
  if (!agent.getPoolSelection) {
@@ -6812,7 +6880,7 @@ var OwneySDK = class {
6812
6880
  `Agent ${agent.id} does not support pool customization`
6813
6881
  );
6814
6882
  }
6815
- return agent.getPoolSelection({
6883
+ return agent.getPoolSelection(state, chainId, {
6816
6884
  pairs: params.pairs,
6817
6885
  assets: params.assets
6818
6886
  });
package/dist/index.d.cts CHANGED
@@ -949,7 +949,7 @@ interface IAgent {
949
949
  * Read back what `setPoolSelection` saved, for the pairs and assets given,
950
950
  * so the Pools step can open on the user's own choices. Optional. (ROUT-650)
951
951
  */
952
- getPoolSelection?(params: {
952
+ getPoolSelection?(state: ConnectionState, chainId: number, params: {
953
953
  pairs: Array<{
954
954
  protocolId: string;
955
955
  chainId: number;
package/dist/index.d.ts CHANGED
@@ -949,7 +949,7 @@ interface IAgent {
949
949
  * Read back what `setPoolSelection` saved, for the pairs and assets given,
950
950
  * so the Pools step can open on the user's own choices. Optional. (ROUT-650)
951
951
  */
952
- getPoolSelection?(params: {
952
+ getPoolSelection?(state: ConnectionState, chainId: number, params: {
953
953
  pairs: Array<{
954
954
  protocolId: string;
955
955
  chainId: number;
package/dist/index.js CHANGED
@@ -311,6 +311,9 @@ var NAME_TO_CHAIN_ID = Object.entries(
311
311
  acc[name.toLowerCase()] = Number(id);
312
312
  return acc;
313
313
  }, {});
314
+ NAME_TO_CHAIN_ID.mainnet = 1;
315
+ NAME_TO_CHAIN_ID["ethereum mainnet"] = 1;
316
+ NAME_TO_CHAIN_ID["arbitrum one"] = 42161;
314
317
  function resolveChainId(chain) {
315
318
  const asNum = Number(chain);
316
319
  if (Number.isFinite(asNum) && asNum > 0) return asNum;
@@ -1430,9 +1433,22 @@ var ZyfaiAgent = class _ZyfaiAgent {
1430
1433
  this.sdk.getUserDetails(asset),
1431
1434
  this.sdk.getAvailableProtocols(chainId)
1432
1435
  ]);
1436
+ debugLog("zyfai:protocol-sync", `${asset}: profile before sync`, {
1437
+ chains: current.chains,
1438
+ protocols: current.protocols,
1439
+ strategy: current.strategy
1440
+ });
1441
+ if ((current.chains?.length ?? 0) === 0 && (current.protocols?.length ?? 0) === 0) {
1442
+ debugLog(
1443
+ "zyfai:protocol-sync",
1444
+ `${asset}: skipping untouched profile until first deposit`
1445
+ );
1446
+ return;
1447
+ }
1433
1448
  const update = buildProtocolMergeUpdate(available, current, asset);
1434
1449
  if (!update) return;
1435
1450
  await this.sdk.updateUserProfile(update);
1451
+ debugLog("zyfai:protocol-sync", `${asset}: wrote profile update`, update);
1436
1452
  } catch (error) {
1437
1453
  console.warn(
1438
1454
  "[zyfai] ensureProtocolsSynced failed (non-fatal):",
@@ -1474,6 +1490,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
1474
1490
  // --- IAgent: Account lifecycle ---
1475
1491
  async activateAgent(state, chainId) {
1476
1492
  try {
1493
+ debugLog("zyfai:activation", "starting", {
1494
+ walletAddress: state.walletAddress,
1495
+ chainId
1496
+ });
1477
1497
  await this.connectAuth(state, chainId);
1478
1498
  const validChainId = isValidChainId(chainId);
1479
1499
  await Promise.all([
@@ -1485,6 +1505,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1485
1505
  // validator, so pool-wallet users see no prompt. Non-fatal.
1486
1506
  this.ensureSessionKeyIfDeployed(validChainId)
1487
1507
  ]);
1508
+ debugLog("zyfai:activation", "completed", { chainId: validChainId });
1488
1509
  } catch (error) {
1489
1510
  throw error;
1490
1511
  }
@@ -1567,6 +1588,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1567
1588
  */
1568
1589
  async applyPoolPolicy(policy, opts = {}) {
1569
1590
  try {
1591
+ await this.sdk.ensureFirstDepositSetup("aggressive");
1570
1592
  const { protocols: universe } = await this.sdk.getAvailableProtocols(
1571
1593
  this.supportedChainIds[0]
1572
1594
  );
@@ -1697,9 +1719,11 @@ var ZyfaiAgent = class _ZyfaiAgent {
1697
1719
  * Persist an explicitly saved deposit-time draft at Zyfai profile level.
1698
1720
  * Pool choices are merged into protocol/chain records and each active asset
1699
1721
  * is kept at aggressive unless the draft includes a yieldmaxxing-only pool.
1722
+ * The whole operation must succeed before the caller starts moving funds.
1700
1723
  */
1701
1724
  async setPoolSelection(selection) {
1702
1725
  try {
1726
+ await this.sdk.ensureFirstDepositSetup("aggressive");
1703
1727
  const byPair = /* @__PURE__ */ new Map();
1704
1728
  for (const entry of selection.selections) {
1705
1729
  const pair = `${entry.protocolId}:${entry.chainId}`;
@@ -1707,39 +1731,31 @@ var ZyfaiAgent = class _ZyfaiAgent {
1707
1731
  group.push(entry);
1708
1732
  byPair.set(pair, group);
1709
1733
  }
1710
- const customizations = (await Promise.all(
1734
+ const customizations = await Promise.all(
1711
1735
  [...byPair.values()].map(async (scoped) => {
1712
1736
  const { protocolId, chainId } = scoped[0];
1713
- try {
1714
- const [current, rawAvailable] = await Promise.all([
1715
- this.sdk.getSelectedPools(protocolId, chainId),
1716
- this.sdk.getAvailablePools(protocolId, "yieldmaxxing")
1717
- ]);
1718
- const allAvailableNames = mapAvailablePools(rawAvailable).filter((pool) => pool.chainId === chainId).map((pool) => pool.name);
1719
- return {
1720
- protocolId,
1721
- chainId,
1722
- pools: mergeScopedPoolNames(
1723
- {
1724
- pools: current.pools ?? [],
1725
- autoselect: current.autoselect
1726
- },
1727
- scoped,
1728
- allAvailableNames
1729
- ),
1730
- // An explicit Save freezes exactly the choices the user saw.
1731
- // This also lets an empty list disable the pair deliberately.
1732
- autoselect: false
1733
- };
1734
- } catch (error) {
1735
- console.warn(
1736
- `[zyfai] setPoolSelection: preserving ${protocolId}/${chainId} failed; skipping the pair:`,
1737
- error instanceof Error ? error.message : String(error)
1738
- );
1739
- return null;
1740
- }
1737
+ const [current, rawAvailable] = await Promise.all([
1738
+ this.sdk.getSelectedPools(protocolId, chainId),
1739
+ this.sdk.getAvailablePools(protocolId, "yieldmaxxing")
1740
+ ]);
1741
+ const allAvailableNames = mapAvailablePools(rawAvailable).filter((pool) => pool.chainId === chainId).map((pool) => pool.name);
1742
+ return {
1743
+ protocolId,
1744
+ chainId,
1745
+ pools: mergeScopedPoolNames(
1746
+ {
1747
+ pools: current.pools ?? [],
1748
+ autoselect: current.autoselect
1749
+ },
1750
+ scoped,
1751
+ allAvailableNames
1752
+ ),
1753
+ // An explicit Save freezes exactly the choices the user saw.
1754
+ // This also lets an empty list disable the pair deliberately.
1755
+ autoselect: false
1756
+ };
1741
1757
  })
1742
- )).filter((value) => value !== null);
1758
+ );
1743
1759
  if (customizations.length > 0) {
1744
1760
  await this.sdk.customizeBatch(customizations);
1745
1761
  }
@@ -1757,9 +1773,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
1757
1773
  );
1758
1774
  } catch (error) {
1759
1775
  console.warn(
1760
- "[zyfai] setPoolSelection failed (non-fatal):",
1776
+ "[zyfai] setPoolSelection failed:",
1761
1777
  error instanceof Error ? error.message : String(error)
1762
1778
  );
1779
+ throw error;
1763
1780
  }
1764
1781
  }
1765
1782
  /**
@@ -1768,17 +1785,18 @@ var ZyfaiAgent = class _ZyfaiAgent {
1768
1785
  * pairs and assets asked about. A pair still on autoselect, or one whose
1769
1786
  * lookup fails, is left out so the caller falls back to its default for it.
1770
1787
  */
1771
- async getPoolSelection(params) {
1788
+ async getPoolSelection(state, chainId, params) {
1789
+ await this.connectAuth(state, chainId);
1772
1790
  const [pairs, strategies] = await Promise.all([
1773
1791
  Promise.all(
1774
- params.pairs.map(async ({ protocolId, chainId }) => {
1792
+ params.pairs.map(async ({ protocolId, chainId: chainId2 }) => {
1775
1793
  try {
1776
1794
  const current = await this.sdk.getSelectedPools(
1777
1795
  protocolId,
1778
- chainId
1796
+ chainId2
1779
1797
  );
1780
1798
  if (current.autoselect) return null;
1781
- return { protocolId, chainId, pools: current.pools ?? [] };
1799
+ return { protocolId, chainId: chainId2, pools: current.pools ?? [] };
1782
1800
  } catch {
1783
1801
  return null;
1784
1802
  }
@@ -2095,6 +2113,33 @@ var ZyfaiAgent = class _ZyfaiAgent {
2095
2113
  const validChainId = isValidChainId(chainId);
2096
2114
  await this.ensureConnected(state, validChainId);
2097
2115
  if (depositCallback) {
2116
+ debugLog("zyfai:first-deposit", "starting sponsored deposit setup", {
2117
+ asset,
2118
+ chainId: validChainId,
2119
+ requestedStrategy: "aggressive"
2120
+ });
2121
+ const setupResult = await this.sdk.ensureFirstDepositSetup("aggressive");
2122
+ debugLog("zyfai:first-deposit", "setup call completed", {
2123
+ requestedStrategy: "aggressive",
2124
+ setupResult
2125
+ });
2126
+ if (isOwneyDebug()) {
2127
+ try {
2128
+ const profileAfterSetup = await this.sdk.getUserDetails(
2129
+ asset === "WETH" ? "WETH" : "USDC"
2130
+ );
2131
+ debugLog("zyfai:first-deposit", "profile immediately after setup", {
2132
+ asset,
2133
+ strategy: profileAfterSetup.strategy,
2134
+ chains: profileAfterSetup.chains,
2135
+ protocols: profileAfterSetup.protocols
2136
+ });
2137
+ } catch (debugError) {
2138
+ debugLog("zyfai:first-deposit", "post-setup profile read failed", {
2139
+ error: debugError instanceof Error ? debugError.message : String(debugError)
2140
+ });
2141
+ }
2142
+ }
2098
2143
  const smartWallet = await this.ensureWalletDeployed(
2099
2144
  this.getAddress(),
2100
2145
  validChainId
@@ -2112,7 +2157,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
2112
2157
  return { txHash, smartWallet, amount };
2113
2158
  }
2114
2159
  await this.ensureWalletDeployed(this.getAddress(), validChainId);
2115
- const raw = await this.sdk.depositFunds(
2160
+ const raw = await this.sdk.sendDeposit(
2116
2161
  this.getAddress(),
2117
2162
  validChainId,
2118
2163
  amount,
@@ -2309,6 +2354,19 @@ var ZyfaiAgent = class _ZyfaiAgent {
2309
2354
  async ensureAutoSelectProtocols(state, chainId, asset) {
2310
2355
  await this.connectAuth(state, chainId);
2311
2356
  const current = await this.sdk.getUserDetails(asset);
2357
+ debugLog("zyfai:auto-select", `${asset}: profile before check`, {
2358
+ autoSelectProtocols: current.autoSelectProtocols,
2359
+ chains: current.chains,
2360
+ protocols: current.protocols,
2361
+ strategy: current.strategy
2362
+ });
2363
+ if ((current.chains?.length ?? 0) === 0) {
2364
+ debugLog(
2365
+ "zyfai:auto-select",
2366
+ `${asset}: skipping untouched profile until first deposit`
2367
+ );
2368
+ return false;
2369
+ }
2312
2370
  const update = buildAutoSelectUpdate(
2313
2371
  {
2314
2372
  autoSelectProtocols: current.autoSelectProtocols,
@@ -2319,6 +2377,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
2319
2377
  );
2320
2378
  if (!update) return false;
2321
2379
  await this.sdk.updateUserProfile(update);
2380
+ debugLog("zyfai:auto-select", `${asset}: wrote profile update`, update);
2322
2381
  return true;
2323
2382
  }
2324
2383
  // --- IAgent: Discovery (no wallet required) ---
@@ -3397,7 +3456,14 @@ async function executeSwap(deps, options) {
3397
3456
  try {
3398
3457
  result = quote.rail === "classic" ? await runClassic(deps, options) : quote.rail === "fusion" ? await runSameChainFusion(deps, options, walletAddress) : await runFusion(deps, options, walletAddress);
3399
3458
  } catch (error) {
3400
- if (!stoppedWatching(error)) throw error;
3459
+ if (!stoppedWatching(error)) {
3460
+ if (quote.rail !== "fusion") throw error;
3461
+ const now = await deps.readTargetBalance().catch(() => before);
3462
+ if (now <= before) throw error;
3463
+ debugLog("owney-sdk", "swap: rail said no but the funds are here", {
3464
+ message: error instanceof Error ? error.message : String(error)
3465
+ });
3466
+ }
3401
3467
  railError = error;
3402
3468
  debugLog("owney-sdk", "swap: rail failed, checking whether funds landed", {
3403
3469
  message: error instanceof Error ? error.message : String(error)
@@ -6785,6 +6851,8 @@ var OwneySDK = class {
6785
6851
  * `assets` say which protocol/chain lists and strategies to read.
6786
6852
  */
6787
6853
  async getPoolSelection(params) {
6854
+ const state = this.requireState();
6855
+ const chainId = this.requireChainId();
6788
6856
  await this.ensureAgentsInitialized();
6789
6857
  const agent = this.getAgent(params.agentId ?? "zyfai");
6790
6858
  if (!agent.getPoolSelection) {
@@ -6793,7 +6861,7 @@ var OwneySDK = class {
6793
6861
  `Agent ${agent.id} does not support pool customization`
6794
6862
  );
6795
6863
  }
6796
- return agent.getPoolSelection({
6864
+ return agent.getPoolSelection(state, chainId, {
6797
6865
  pairs: params.pairs,
6798
6866
  assets: params.assets
6799
6867
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.28-beta.6",
3
+ "version": "0.7.28-beta.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "test:watch": "vitest"
24
24
  },
25
25
  "dependencies": {
26
- "@zyfai/sdk": "0.2.57",
26
+ "@zyfai/sdk": "0.11.2",
27
27
  "siwe": "^3.0.0",
28
28
  "viem": "^2.48.1"
29
29
  },