@zyfai/sdk 0.3.0 → 0.4.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.
package/dist/index.js CHANGED
@@ -112,6 +112,13 @@ var ENDPOINTS = {
112
112
  AUTH_CHALLENGE: "/auth/challenge",
113
113
  // User
114
114
  USER_ME: "/users/me",
115
+ USER_ASSET_TYPE_SETTINGS: "/users/asset-type-settings",
116
+ AGENT_DEPOSIT_SETUP: "/users/me/agent-deposit-setup",
117
+ USER_AGENT_DEPOSIT_INTENTS: "/users/me/agent-deposit-intents",
118
+ USER_AGENT_DEPOSIT_INTENT: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}`,
119
+ USER_AGENT_DEPOSIT_INTENT_CONSUME: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}/consume`,
120
+ USER_AGENT_DEPOSIT_INTENT_COMPLETE: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}/complete`,
121
+ AGENT_DEPOSIT_INTENT_RESOLVE: "/agent-deposit-intents/resolve",
115
122
  USER_WITHDRAW: "/users/withdraw",
116
123
  PARTIAL_WITHDRAW: "/users/partial-withdraw",
117
124
  LOG_DEPOSIT: "/users/log_deposit/v2",
@@ -237,6 +244,8 @@ var HttpClient = class {
237
244
  */
238
245
  constructor(apiKey, config = {}) {
239
246
  this.authToken = null;
247
+ /** @internal Extra headers on execution API requests (e.g. MCP server channel key). */
248
+ this.extraExecutionHeaders = {};
240
249
  this.apiKey = apiKey;
241
250
  const executionApiUrl = config.executionApiUrl ?? API_ENDPOINT;
242
251
  this.dataApiBaseUrl = config.dataApiUrl ?? DATA_API_ENDPOINT;
@@ -265,9 +274,17 @@ var HttpClient = class {
265
274
  setAuthToken(token) {
266
275
  this.authToken = token;
267
276
  }
277
+ /** @internal */
278
+ setExtraExecutionHeaders(headers) {
279
+ this.extraExecutionHeaders = headers;
280
+ }
268
281
  clearAuthToken() {
269
282
  this.authToken = null;
270
283
  }
284
+ /** Whether a user Bearer token is set on this client instance. */
285
+ hasAuthToken() {
286
+ return this.authToken !== null;
287
+ }
271
288
  getOrigin() {
272
289
  return this.origin;
273
290
  }
@@ -281,6 +298,9 @@ var HttpClient = class {
281
298
  if (this.authToken) {
282
299
  config.headers["Authorization"] = `Bearer ${this.authToken}`;
283
300
  }
301
+ for (const [key, value] of Object.entries(this.extraExecutionHeaders)) {
302
+ config.headers[key] = value;
303
+ }
284
304
  return config;
285
305
  },
286
306
  (error) => {
@@ -333,6 +353,10 @@ var HttpClient = class {
333
353
  const response = await this.client.patch(url, data, config);
334
354
  return response.data;
335
355
  }
356
+ async put(url, data, config) {
357
+ const response = await this.client.put(url, data, config);
358
+ return response.data;
359
+ }
336
360
  async delete(url, config) {
337
361
  const response = await this.client.delete(url, config);
338
362
  return response.data;
@@ -679,11 +703,22 @@ function isLocalExecutionApiUrl(executionApiUrl) {
679
703
  return false;
680
704
  }
681
705
  }
706
+ function isStagingExecutionApiUrl(executionApiUrl) {
707
+ if (executionApiUrl === EXECUTION_API_BASE_URLS.staging) {
708
+ return true;
709
+ }
710
+ try {
711
+ const { hostname } = new URL(executionApiUrl);
712
+ return hostname === "staging-api.zyf.ai";
713
+ } catch {
714
+ return false;
715
+ }
716
+ }
682
717
  function shouldBypassMinPortfolioCheck(executionApiUrl) {
683
718
  if (process.env.NODE_ENV === "production") {
684
719
  return false;
685
720
  }
686
- return isLocalExecutionApiUrl(executionApiUrl);
721
+ return isLocalExecutionApiUrl(executionApiUrl) || isStagingExecutionApiUrl(executionApiUrl);
687
722
  }
688
723
 
689
724
  // src/core/ZyfaiSDK.ts
@@ -1567,7 +1602,7 @@ function enrichOnchainEarningsTotals(apiData) {
1567
1602
  const unrealized = unrealizedByToken[symbol] ?? 0;
1568
1603
  const current = currentByToken[symbol] ?? 0;
1569
1604
  totalEarningsByTokenWithFee[symbol] = formatHumanAmount(
1570
- lifetime + unrealized + current * keepRate
1605
+ (lifetime + unrealized + current) * keepRate
1571
1606
  );
1572
1607
  });
1573
1608
  const chainKeys = /* @__PURE__ */ new Set([
@@ -1591,7 +1626,7 @@ function enrichOnchainEarningsTotals(apiData) {
1591
1626
  const unrealized = parseHumanAmount(unrealizedTokens[symbol]);
1592
1627
  const current = parseHumanAmount(currentTokens[symbol]);
1593
1628
  chainMap[symbol] = formatHumanAmount(
1594
- lifetime + unrealized + current * keepRate
1629
+ (lifetime + unrealized + current) * keepRate
1595
1630
  );
1596
1631
  });
1597
1632
  totalEarningsByChainWithFee[chainId] = chainMap;
@@ -1631,15 +1666,35 @@ var DepositCreditTimeoutError = class extends Error {
1631
1666
  };
1632
1667
  var MANAGED_ASSETS = ["USDC", "WETH", "EURC", "NVDAc"];
1633
1668
  var _ZyfaiSDK = class _ZyfaiSDK {
1669
+ /**
1670
+ * Create an SDK instance bound to a partner API key.
1671
+ *
1672
+ * @param config - API key string or {@link SDKConfig} with optional `rpcUrls` and `referralSource`
1673
+ *
1674
+ * @remarks
1675
+ * `@internal` fields on {@link SDKConfig} (`executionApiUrl`, `dataApiUrl`,
1676
+ * `bypassMinPortfolio`) are for local integration tests only.
1677
+ *
1678
+ * @throws If `apiKey` is missing
1679
+ *
1680
+ * @example
1681
+ * ```typescript
1682
+ * const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
1683
+ * ```
1684
+ */
1634
1685
  constructor(config) {
1635
1686
  this.signer = null;
1636
1687
  this.walletClient = null;
1637
1688
  this.authenticatedUserId = null;
1638
1689
  this.hasActiveSessionKey = false;
1639
1690
  this.isPredeployed = false;
1691
+ /** False until SIWE login or GET /users/me has set `isPredeployed`. */
1692
+ this.predeployedResolved = false;
1640
1693
  this.connectedSmartWallet = null;
1641
1694
  this.currentProvider = null;
1642
1695
  this.currentChainId = null;
1696
+ /** EOA of the active user session (bearer or SIWE). Cleared on disconnect. */
1697
+ this.sessionEoa = null;
1643
1698
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
1644
1699
  const {
1645
1700
  apiKey,
@@ -1661,6 +1716,84 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1661
1716
  this.rpcUrls = rpcUrls;
1662
1717
  this.referralSource = referralSource;
1663
1718
  }
1719
+ /**
1720
+ * Create an SDK instance with an existing Zyfai user JWT (no wallet connected).
1721
+ *
1722
+ * @group Authentication and wallet
1723
+ */
1724
+ static forUser(config, session) {
1725
+ const sdk = new _ZyfaiSDK(config);
1726
+ sdk.applyUserSession(session);
1727
+ return sdk;
1728
+ }
1729
+ /** Alias for MCP delegated grants (scoped agent JWT). */
1730
+ static forDelegatedGrant(config, session) {
1731
+ return _ZyfaiSDK.forUser(config, session);
1732
+ }
1733
+ /**
1734
+ * Attach a Zyfai user JWT for API calls without `connectAccount`.
1735
+ *
1736
+ * @group Authentication and wallet
1737
+ */
1738
+ applyUserSession(session) {
1739
+ if (!session.accessToken) {
1740
+ throw new Error("accessToken is required");
1741
+ }
1742
+ this.httpClient.setAuthToken(session.accessToken);
1743
+ this.authenticatedUserId = session.userId ?? "bearer-session";
1744
+ this.sessionEoa = session.eoa ? (0, import_viem4.getAddress)(session.eoa) : null;
1745
+ this.sessionChannel = session.channel;
1746
+ this.isPredeployed = false;
1747
+ this.predeployedResolved = false;
1748
+ this.connectedSmartWallet = null;
1749
+ }
1750
+ /**
1751
+ * @internal Attach headers to execution API requests (MCP server agent channel).
1752
+ */
1753
+ setExecutionRequestHeaders(headers) {
1754
+ this.httpClient.setExtraExecutionHeaders(headers);
1755
+ }
1756
+ /** EOA of the active user session, if one is bound. */
1757
+ getSessionEoa() {
1758
+ return this.sessionEoa;
1759
+ }
1760
+ /**
1761
+ * Complete SIWE login with a prepared message and signature (OAuth consent, MCP).
1762
+ *
1763
+ * @group Authentication and wallet
1764
+ *
1765
+ * @param params.message - SIWE message fields (same shape as login API body)
1766
+ * @param params.signature - Wallet signature over the prepared SIWE string
1767
+ * @param params.origin - Origin header value; must match `message.uri`
1768
+ */
1769
+ async authenticateWithSignature(params) {
1770
+ const origin = params.origin ?? params.message.uri;
1771
+ const loginResponse = await this.httpClient.post(
1772
+ ENDPOINTS.AUTH_LOGIN,
1773
+ {
1774
+ message: params.message,
1775
+ signature: params.signature,
1776
+ referralSource: this.referralSource
1777
+ },
1778
+ {
1779
+ headers: {
1780
+ Origin: origin
1781
+ }
1782
+ }
1783
+ );
1784
+ if (!loginResponse.accessToken) {
1785
+ throw new Error("Authentication response missing access token");
1786
+ }
1787
+ this.httpClient.setAuthToken(loginResponse.accessToken);
1788
+ this.authenticatedUserId = loginResponse.userId || null;
1789
+ this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1790
+ this.isPredeployed = loginResponse.predeployed || false;
1791
+ this.predeployedResolved = true;
1792
+ this.connectedSmartWallet = loginResponse.smartWallet || null;
1793
+ this.sessionEoa = (0, import_viem4.getAddress)(params.message.address);
1794
+ this.sessionChannel = void 0;
1795
+ return loginResponse;
1796
+ }
1664
1797
  /**
1665
1798
  * Warn that a legacy method is deprecated in favor of sendDeposit.
1666
1799
  * Predeployed wallets no longer require deploySafe / createSessionKey.
@@ -1682,6 +1815,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1682
1815
  if (this.authenticatedUserId !== null) {
1683
1816
  return;
1684
1817
  }
1818
+ if (this.httpClient.hasAuthToken()) {
1819
+ return;
1820
+ }
1685
1821
  const walletClient = this.getWalletClient();
1686
1822
  const userAddress = (0, import_viem4.getAddress)(walletClient.account.address);
1687
1823
  const chainId = this.currentChainId || walletClient.chain?.id || 8453;
@@ -1734,7 +1870,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1734
1870
  this.authenticatedUserId = loginResponse.userId || null;
1735
1871
  this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1736
1872
  this.isPredeployed = loginResponse.predeployed || false;
1873
+ this.predeployedResolved = true;
1737
1874
  this.connectedSmartWallet = loginResponse.smartWallet || null;
1875
+ this.sessionEoa = userAddress;
1738
1876
  } catch (error) {
1739
1877
  throw new Error(
1740
1878
  `Failed to authenticate user: ${error.message}`
@@ -1745,8 +1883,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1745
1883
  * Update user profile with Smart Wallet address and chain configuration
1746
1884
  * This method requires SIWE authentication and is automatically called after deploySafe
1747
1885
  *
1748
- * @param request - User profile update data
1749
- * @returns Updated user profile information
1886
+ * @group Portfolio and execution
1887
+ *
1888
+ * @param request - Profile fields to update (per-asset settings supported)
1889
+ * @returns Updated user profile from the execution API
1890
+ *
1891
+ * @throws If strategy is invalid or authentication fails
1750
1892
  *
1751
1893
  * @example
1752
1894
  * ```typescript
@@ -1807,8 +1949,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1807
1949
  * Pause the agent by clearing all protocols
1808
1950
  * Sets the user's protocols to an empty array, effectively pausing automated operations
1809
1951
  *
1952
+ * @group Portfolio and execution
1953
+ *
1810
1954
  * @returns Response indicating success and updated user details
1811
1955
  *
1956
+ * @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
1957
+ *
1812
1958
  * @example
1813
1959
  * ```typescript
1814
1960
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1839,8 +1985,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1839
1985
  * Resume the agent by restoring protocols based on user's strategy for each asset
1840
1986
  * Fetches available protocols and assigns them based on each asset's strategy
1841
1987
  *
1988
+ * @group Portfolio and execution
1989
+ *
1842
1990
  * @returns Response indicating success and updated user details
1843
1991
  *
1992
+ * @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
1993
+ *
1844
1994
  * @example
1845
1995
  * ```typescript
1846
1996
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1879,9 +2029,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1879
2029
  * Enable splitting for the user's account
1880
2030
  * When enabled, deposits are split across multiple protocols based on minSplits setting
1881
2031
  *
1882
- * @param minSplits - Optional minimum number of protocols to split across (default: 3)
2032
+ * @group Portfolio and execution
2033
+ *
2034
+ * @param minSplits - Minimum protocols to split across (max 4)
2035
+ * @defaultValue 1
1883
2036
  * @returns Response indicating success and updated user details
1884
2037
  *
2038
+ * @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
2039
+ *
2040
+ * @throws If `minSplits` exceeds 4
2041
+ *
1885
2042
  * @example
1886
2043
  * ```typescript
1887
2044
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1914,8 +2071,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1914
2071
  * Disable splitting for the user's account
1915
2072
  * When disabled, deposits will not be split across multiple protocols
1916
2073
  *
2074
+ * @group Portfolio and execution
2075
+ *
1917
2076
  * @returns Response indicating success and updated user details
1918
2077
  *
2078
+ * @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
2079
+ *
1919
2080
  * @example
1920
2081
  * ```typescript
1921
2082
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1944,9 +2105,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1944
2105
  * Update the minimum number of splits for the user's account
1945
2106
  * This controls across how many protocols deposits should be distributed
1946
2107
  *
1947
- * @param minSplits - Minimum number of protocols to split across
2108
+ * @group Portfolio and execution
2109
+ *
2110
+ * @param minSplits - Minimum number of protocols to split across (at least 1)
1948
2111
  * @returns Response indicating success and updated user details
1949
2112
  *
2113
+ * @throws If `minSplits` is less than 1
2114
+ *
1950
2115
  * @example
1951
2116
  * ```typescript
1952
2117
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -2025,6 +2190,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2025
2190
  }
2026
2191
  this.authenticatedUserId = null;
2027
2192
  this.hasActiveSessionKey = false;
2193
+ this.sessionEoa = null;
2028
2194
  this.httpClient.clearAuthToken();
2029
2195
  if (this.walletClient && this.currentProvider) {
2030
2196
  const chainConfig = getChainConfig(
@@ -2048,12 +2214,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2048
2214
  }
2049
2215
  }
2050
2216
  /**
2051
- * Connect account for signing transactions
2052
- * Accepts either a private key string or a modern wallet provider
2217
+ * Connect an account for signing (SIWE and on-chain transfers).
2218
+ *
2219
+ * @remarks
2220
+ * Required before user-scoped execution calls (deposits, withdrawals, profile).
2221
+ * Data API reads typically need only the API key.
2053
2222
  *
2054
- * @param account - Private key string or wallet provider object
2055
- * @param chainId - Target chain ID (default: 8453 - Base)
2056
- * @returns The connected EOA address
2223
+ * @group Authentication and wallet
2224
+ *
2225
+ * @param account - Private key hex string or EIP-1193 wallet provider
2226
+ * @param chainId - Initial chain for RPC and SIWE
2227
+ * @defaultValue 8453
2228
+ * @returns The connected EOA address (checksum)
2229
+ *
2230
+ * @throws If the chain is unsupported or the provider returns no accounts
2057
2231
  *
2058
2232
  * @example
2059
2233
  * // With private key
@@ -2070,8 +2244,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2070
2244
  }
2071
2245
  this.authenticatedUserId = null;
2072
2246
  this.isPredeployed = false;
2247
+ this.predeployedResolved = false;
2073
2248
  this.connectedSmartWallet = null;
2074
2249
  this.currentChainId = null;
2250
+ this.sessionEoa = null;
2251
+ this.sessionChannel = void 0;
2075
2252
  this.httpClient.clearAuthToken();
2076
2253
  if (this.currentProvider?.removeAllListeners) {
2077
2254
  try {
@@ -2139,8 +2316,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2139
2316
  return connectedAddress;
2140
2317
  }
2141
2318
  /**
2142
- * Disconnect account and clear authentication state
2143
- * Resets wallet connection, JWT token, and all authentication-related state
2319
+ * Clear the connected wallet, SIWE session, and cached smart-wallet state.
2320
+ *
2321
+ * @group Authentication and wallet
2322
+ *
2323
+ * @returns Resolves when local SDK state is cleared
2144
2324
  *
2145
2325
  * @example
2146
2326
  * ```typescript
@@ -2162,7 +2342,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2162
2342
  this.authenticatedUserId = null;
2163
2343
  this.hasActiveSessionKey = false;
2164
2344
  this.isPredeployed = false;
2345
+ this.predeployedResolved = false;
2165
2346
  this.connectedSmartWallet = null;
2347
+ this.sessionEoa = null;
2348
+ this.sessionChannel = void 0;
2166
2349
  this.httpClient.clearAuthToken();
2167
2350
  }
2168
2351
  /**
@@ -2189,13 +2372,25 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2189
2372
  }
2190
2373
  }
2191
2374
  /**
2192
- * True when userAddress is the currently connected/authenticated wallet.
2375
+ * True when userAddress is the signer, wallet client, or agent session EOA.
2193
2376
  * @private
2194
2377
  */
2195
2378
  isConnectedUser(userAddress) {
2196
- const connected = this.signer?.address ?? this.walletClient?.account?.address;
2379
+ const connected = this.signer?.address ?? this.walletClient?.account?.address ?? this.sessionEoa;
2197
2380
  return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
2198
2381
  }
2382
+ /**
2383
+ * SIWE login sets predeployed. Agent sessions (`forUser`) do not, so read it
2384
+ * from the user record before allowing a transfer to an undeployed pool Safe.
2385
+ * @private
2386
+ */
2387
+ async hydrateSessionWallet() {
2388
+ if (this.predeployedResolved || !this.sessionEoa) return;
2389
+ const me = await this.httpClient.get(ENDPOINTS.USER_ME);
2390
+ this.isPredeployed = !!me?.predeployed;
2391
+ this.connectedSmartWallet = me?.smartWallet || null;
2392
+ this.predeployedResolved = true;
2393
+ }
2199
2394
  /**
2200
2395
  * Resolve the Safe address: backend-assigned for the connected predeployed
2201
2396
  * user, registered agent for everyone else. If none, CREATE2-derive when
@@ -2229,15 +2424,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2229
2424
  });
2230
2425
  }
2231
2426
  /**
2232
- * Get smart wallet address for a user
2233
- * Returns the Safe address for an EOA (deterministic for legacy wallets,
2234
- * backend-assigned for predeployed pool wallets).
2427
+ * Resolve the Safe smart wallet for an EOA on a chain.
2428
+ *
2429
+ * @remarks
2430
+ * Predeployed pool wallets use a backend-assigned address; legacy wallets use
2431
+ * a deterministic CREATE2 address.
2432
+ *
2433
+ * @group Authentication and wallet
2235
2434
  *
2236
2435
  * @param userAddress - User's EOA address
2237
2436
  * @param chainId - Target chain ID
2238
- * @returns Smart wallet address, deployment status, and whether userAddress
2239
- * is an on-chain OwnableValidator owner (false for reserved predeployed
2240
- * wallets until the first deposit rotates ownership)
2437
+ * @returns Smart wallet address, deployment status, and on-chain ownership flag
2438
+ *
2439
+ * @throws If `userAddress` is missing or `chainId` is unsupported
2241
2440
  */
2242
2441
  async getSmartWalletAddress(userAddress, chainId) {
2243
2442
  if (!userAddress) {
@@ -2269,10 +2468,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2269
2468
  /**
2270
2469
  * Deploy Safe Smart Wallet for a user
2271
2470
  *
2272
- * @deprecated Prefer `sendDeposit()`. Predeployed Safes and session keys are
2471
+ * @deprecated Prefer {@link ZyfaiSDK.sendDeposit}. Predeployed Safes and session keys are
2273
2472
  * managed automatically on first deposit. This method remains available for
2274
2473
  * legacy flows.
2275
2474
  *
2475
+ * @see {@link ZyfaiSDK.sendDeposit}
2476
+ *
2477
+ * @group Deposits and withdrawals
2478
+ *
2276
2479
  * @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
2277
2480
  * @param chainId - Target chain ID
2278
2481
  * @param strategy - Optional strategy selection: "conservative" (default), "aggressive" or "yieldmaxxing"
@@ -2409,10 +2612,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2409
2612
  * Create session key with auto-fetched configuration from Zyfai API
2410
2613
  * This is the simplified method that automatically fetches session configuration
2411
2614
  *
2412
- * @deprecated Prefer `sendDeposit()`. Predeployed wallets already have the
2615
+ * @deprecated Prefer {@link ZyfaiSDK.sendDeposit}. Predeployed wallets already have the
2413
2616
  * agent session enabled; session activation is handled after first deposit.
2414
2617
  * This method remains available for legacy flows.
2415
2618
  *
2619
+ * @see {@link ZyfaiSDK.sendDeposit}
2620
+ *
2621
+ * @group Deposits and withdrawals
2622
+ *
2416
2623
  * @param userAddress - User's EOA or Safe address
2417
2624
  * @param chainId - Target chain ID
2418
2625
  * @returns Session key response with signature and nonces
@@ -2638,6 +2845,43 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2638
2845
  asset,
2639
2846
  internalStrategy
2640
2847
  );
2848
+ const mandateChainId = chains.find((c) => !existingChains.includes(c)) ?? chains[0];
2849
+ return await this.persistDiscoveredAssetProfile(
2850
+ asset,
2851
+ effectiveChains,
2852
+ withPools,
2853
+ strategy,
2854
+ mandateChainId
2855
+ );
2856
+ }
2857
+ /**
2858
+ * Persist protocol discovery for one asset (user PATCH or agent deposit-setup).
2859
+ * @internal
2860
+ */
2861
+ async persistDiscoveredAssetProfile(asset, effectiveChains, withPools, strategy, agentDepositChainId) {
2862
+ const internalAsset = convertAssetInternally(asset);
2863
+ const assetSettings = {
2864
+ chains: effectiveChains,
2865
+ protocols: withPools
2866
+ };
2867
+ if (strategy !== void 0) {
2868
+ assetSettings.rebalanceStrategy = toInternalStrategy(strategy);
2869
+ }
2870
+ if (this.sessionChannel === "agent") {
2871
+ const chainId = agentDepositChainId ?? effectiveChains[effectiveChains.length - 1] ?? effectiveChains[0];
2872
+ await this.httpClient.post(
2873
+ ENDPOINTS.AGENT_DEPOSIT_SETUP,
2874
+ {
2875
+ asset,
2876
+ chainId,
2877
+ strategy,
2878
+ assetTypeSettings: {
2879
+ [internalAsset]: assetSettings
2880
+ }
2881
+ }
2882
+ );
2883
+ return await this.getUserDetails(asset);
2884
+ }
2641
2885
  return await this.updateUserProfile({
2642
2886
  asset,
2643
2887
  protocols: withPools,
@@ -2666,6 +2910,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2666
2910
  * @param params.chains - Chains to enable. Defaults to every chain the asset
2667
2911
  * exists on. **Additive**: chains already enabled are kept, so this cannot
2668
2912
  * be used to disable one.
2913
+ * @group Portfolio and execution
2914
+ *
2669
2915
  * @returns The updated profile for that asset
2670
2916
  *
2671
2917
  * @example
@@ -2783,7 +3029,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2783
3029
  * transfer lands on the counterfactual address and the backend deploys + hands over on first
2784
3030
  * deposit (report-deposit). Use this only to pre-provision chains ahead of time.
2785
3031
  *
2786
- * @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
3032
+ * @group Deposits and withdrawals
3033
+ *
3034
+ * @param chainIds - Chain IDs to deploy the wallet on (e.g. `[1, 42161]`)
3035
+ * @returns Deployment summary from the execution API
3036
+ *
3037
+ * @throws If `chainIds` is empty or contains an unsupported chain
3038
+ *
3039
+ * @remarks
3040
+ * Requires {@link ZyfaiSDK.connectAccount} (SIWE). Optional ahead of deposits;
3041
+ * {@link ZyfaiSDK.sendDeposit} can deploy on first deposit for predeployed wallets.
2787
3042
  */
2788
3043
  async deployOnChains(chainIds) {
2789
3044
  if (!chainIds?.length) {
@@ -2796,10 +3051,33 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2796
3051
  return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
2797
3052
  }
2798
3053
  /**
2799
- * Send a deposit from an EOA to its Safe smart wallet.
3054
+ * Transfer funds from the connected EOA to the user's Safe and register the deposit.
3055
+ *
3056
+ * @remarks
3057
+ * Execution API + on-chain ERC-20 `transfer`. Confirms the transaction, then calls
3058
+ * {@link ZyfaiSDK.logDeposit}. Pair with {@link ZyfaiSDK.waitForDepositCredit} for
3059
+ * investable balance. Custom-wallet flows: {@link ZyfaiSDK.buildDepositTransfer},
3060
+ * {@link ZyfaiSDK.logDeposit}, {@link ZyfaiSDK.getDepositStatus}.
3061
+ *
3062
+ * Requires {@link ZyfaiSDK.connectAccount}. Pass the **EOA** as `userAddress`.
3063
+ *
3064
+ * @group Deposits and withdrawals
3065
+ *
3066
+ * @param userAddress - Owner EOA (not the Safe)
3067
+ * @param chainId - Chain for the transfer
3068
+ * @param amount - Amount in least units (string integer)
3069
+ * @param asset - Asset symbol (`USDC`, `WETH`, `EURC`, `NVDAc`)
3070
+ * @param strategy - Optional first-deposit {@link Strategy}
3071
+ * @returns Transfer receipt and deposit registration (not yet credited until polled)
3072
+ *
3073
+ * @throws If validation fails, minimum portfolio is not met, Safe is unavailable, or transfer/register fails
2800
3074
  *
2801
- * Confirms the ERC-20 transfer and starts the custody-credit lifecycle. Use
2802
- * `waitForDepositCredit(result.registration.id, chainId)` to await credit.
3075
+ * @example
3076
+ * ```typescript
3077
+ * await sdk.connectAccount(provider);
3078
+ * const sent = await sdk.sendDeposit(eoa, 8453, "10000000", "USDC", "conservative");
3079
+ * await sdk.waitForDepositCredit(sent.registration.id, 8453);
3080
+ * ```
2803
3081
  */
2804
3082
  async sendDeposit(userAddress, chainId, amount, asset, strategy) {
2805
3083
  try {
@@ -2850,6 +3128,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2850
3128
  } else {
2851
3129
  await this.authenticateUser();
2852
3130
  }
3131
+ await this.hydrateSessionWallet();
2853
3132
  const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
2854
3133
  if (!safeAddress) {
2855
3134
  throw new Error("Smart wallet address is not available");
@@ -2918,8 +3197,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2918
3197
  }
2919
3198
  }
2920
3199
  /**
2921
- * @deprecated Compatibility convenience method. Prefer `sendDeposit()` followed by
2922
- * `waitForDepositCredit()` when the caller owns the completion UX.
3200
+ * @deprecated Compatibility convenience method. Prefer {@link ZyfaiSDK.sendDeposit} followed by
3201
+ * {@link ZyfaiSDK.waitForDepositCredit} when the caller owns the completion UX.
3202
+ *
3203
+ * @see {@link ZyfaiSDK.sendDeposit}
3204
+ *
3205
+ * @group Deposits and withdrawals
2923
3206
  */
2924
3207
  async depositFunds(userAddress, chainId, amount, asset, strategy) {
2925
3208
  this.warnDeprecatedOnboardingMethod("depositFunds");
@@ -2939,10 +3222,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2939
3222
  };
2940
3223
  }
2941
3224
  /**
2942
- * Prepare ERC-20 transfer calldata for builders using a custom signer,
2943
- * sponsored transaction provider, or mobile wallet. Most custom-wallet
2944
- * integrations can compose this with `ensureFirstDepositSetup()` and
2945
- * `logDeposit()` instead.
3225
+ * Build ERC-20 transfer calldata for a custom signer or sponsored tx flow.
3226
+ *
3227
+ * @remarks
3228
+ * Compose with {@link ZyfaiSDK.ensureFirstDepositSetup}, submit the transfer, then
3229
+ * {@link ZyfaiSDK.logDeposit} and {@link ZyfaiSDK.waitForDepositCredit}.
3230
+ *
3231
+ * @group Deposits and withdrawals
3232
+ *
3233
+ * @param params.userAddress - Owner EOA
3234
+ * @param params.chainId - Target chain
3235
+ * @param params.amount - Least units (string integer)
3236
+ * @param params.asset - {@link SupportedAsset}
3237
+ * @returns Safe address, token, and encoded `transfer` calldata
3238
+ *
3239
+ * @throws If inputs are invalid or the Safe address cannot be resolved
2946
3240
  */
2947
3241
  async buildDepositTransfer(params) {
2948
3242
  const { userAddress, chainId, amount, asset } = params;
@@ -2961,6 +3255,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2961
3255
  )}.`
2962
3256
  );
2963
3257
  }
3258
+ await this.hydrateSessionWallet();
2964
3259
  const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
2965
3260
  if (!safeAddress) {
2966
3261
  throw new Error("Smart wallet address is not available");
@@ -3049,6 +3344,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3049
3344
  * When setup runs (`applied: true`), protocol configuration is persisted
3050
3345
  * before returning. Failures throw so callers can abort before submitting a
3051
3346
  * transfer. High-level deposit methods still treat setup as best-effort.
3347
+ *
3348
+ * @group Deposits and withdrawals
3349
+ *
3350
+ * @param strategy - Optional first-deposit {@link Strategy}
3351
+ * @returns `{ applied: true }` when chain/protocol config was written; `false` if already configured
3352
+ *
3353
+ * @throws If strategy is invalid or setup did not persist
3052
3354
  */
3053
3355
  async ensureFirstDepositSetup(strategy) {
3054
3356
  if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
@@ -3070,6 +3372,67 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3070
3372
  }
3071
3373
  return { applied: true };
3072
3374
  }
3375
+ /**
3376
+ * Idempotently configure the deposit asset for a single chain before MCP prepare.
3377
+ *
3378
+ * @internal
3379
+ */
3380
+ async ensureDepositProfileForPrepare(params) {
3381
+ const { strategy, asset, chainId } = params;
3382
+ if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
3383
+ throw new Error(
3384
+ `Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
3385
+ );
3386
+ }
3387
+ await this.authenticateUser();
3388
+ const details = await this.getUserDetails(asset);
3389
+ if (details.chains?.includes(chainId)) {
3390
+ return { applied: false };
3391
+ }
3392
+ const allProtocols = await this.httpClient.get(
3393
+ ENDPOINTS.PROTOCOLS()
3394
+ );
3395
+ await this.updateUserProtocolsForAsset(
3396
+ asset,
3397
+ [chainId],
3398
+ strategy,
3399
+ allProtocols
3400
+ );
3401
+ const afterSetup = await this.getUserDetails(asset);
3402
+ if (!afterSetup.chains?.includes(chainId)) {
3403
+ throw new Error(
3404
+ `First-deposit setup did not persist ${asset} chain ${chainId} configuration.`
3405
+ );
3406
+ }
3407
+ return { applied: true };
3408
+ }
3409
+ /**
3410
+ * Prepare a deposit: persist first-deposit profile when needed and return
3411
+ * ERC-20 transfer calldata for the user to sign (does not broadcast).
3412
+ *
3413
+ * @group Deposits and withdrawals
3414
+ */
3415
+ async prepareDeposit(params) {
3416
+ const { userAddress, chainId, amount, asset } = params;
3417
+ if (this.sessionEoa && (0, import_viem4.getAddress)(userAddress) !== this.sessionEoa) {
3418
+ throw new Error("userAddress does not match authenticated session EOA");
3419
+ }
3420
+ const setup = await this.ensureDepositProfileForPrepare({
3421
+ asset,
3422
+ chainId
3423
+ });
3424
+ const transfer = await this.buildDepositTransfer({
3425
+ userAddress,
3426
+ chainId,
3427
+ amount,
3428
+ asset
3429
+ });
3430
+ return {
3431
+ phase: "prepare_transfer",
3432
+ setup,
3433
+ transfer
3434
+ };
3435
+ }
3073
3436
  /** Best-effort first-deposit setup shared by both high-level deposit flows. */
3074
3437
  async prepareFirstDeposit(strategy) {
3075
3438
  try {
@@ -3125,8 +3488,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3125
3488
  * @param chainId - Chain ID where the deposit was made
3126
3489
  * @param txHash - Transaction hash of the deposit
3127
3490
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
3128
- * @param tokenAddress - Optional: Token address (auto-selected based on chain if not provided)
3129
- * @returns Log deposit response with success status
3491
+ * @param tokenAddress - Optional token contract (defaults per chain)
3492
+ * @returns Log deposit response with lifecycle record
3493
+ *
3494
+ * @group Deposits and withdrawals
3495
+ *
3496
+ * @throws If inputs are invalid or the execution API rejects registration
3130
3497
  *
3131
3498
  * @example
3132
3499
  * ```typescript
@@ -3177,8 +3544,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3177
3544
  }
3178
3545
  }
3179
3546
  /**
3180
- * Fetch the custody handover and balance-credit lifecycle for a registered
3181
- * deposit. A status of `credited` is required before funds are investable.
3547
+ * Fetch custody handover and balance-credit status for a registered deposit.
3548
+ *
3549
+ * @remarks
3550
+ * `status === "credited"` with `balanceCredited === true` means funds are investable.
3551
+ * Requires {@link ZyfaiSDK.connectAccount} (SIWE).
3552
+ *
3553
+ * @group Deposits and withdrawals
3554
+ *
3555
+ * @param depositId - Id from {@link LogDepositResponse} / {@link DepositResponse.registration}
3556
+ * @returns {@link DepositLifecycleResponse}
3557
+ *
3558
+ * @throws If `depositId` is missing
3182
3559
  */
3183
3560
  async getDepositStatus(depositId) {
3184
3561
  if (!depositId) {
@@ -3200,7 +3577,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3200
3577
  * ~250ms) with a ~20 second completion window. Override `timeoutMs` when a
3201
3578
  * caller intentionally wants to wait longer than the normal UX window.
3202
3579
  *
3203
- * Requires `connectAccount()` on the same SDK instance first.
3580
+ * Requires {@link ZyfaiSDK.connectAccount} on the same SDK instance.
3581
+ *
3582
+ * @group Deposits and withdrawals
3583
+ *
3584
+ * @param depositId - Deposit lifecycle id
3585
+ * @param chainId - Chain (controls poll interval and default timeout)
3586
+ * @param options - Optional `intervalMs` and `timeoutMs` overrides
3587
+ * @returns Final lifecycle record when credited
3588
+ *
3589
+ * @throws `DepositCreditTimeoutError` when the poll window elapses without credit
3590
+ * @throws If deposit recovers to EOA or polling fails
3204
3591
  */
3205
3592
  async waitForDepositCredit(depositId, chainId, options) {
3206
3593
  if (!depositId) {
@@ -3263,8 +3650,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3263
3650
  *
3264
3651
  * @param userAddress - User's address (owner of the Safe)
3265
3652
  * @param chainId - Target chain ID
3266
- * @param amount - Optional: Amount in least decimal units to withdraw (partial withdrawal). If not specified, withdraws all funds
3267
- * @returns Withdraw response with message and optional transaction hash (available once processed)
3653
+ * @param amount - Optional amount in least units (partial withdrawal); omit for full withdraw
3654
+ * @param tokenSymbol - Optional asset symbol when withdrawing a specific token
3655
+ * @returns Withdraw response with message and optional transaction hash
3656
+ *
3657
+ * @group Deposits and withdrawals
3658
+ *
3659
+ * @throws If `userAddress` or `chainId` is invalid, or the execution API rejects the request
3268
3660
  *
3269
3661
  * @example
3270
3662
  * ```typescript
@@ -3361,11 +3753,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3361
3753
  );
3362
3754
  }
3363
3755
  /**
3364
- * Get available DeFi protocols and pools for a specific chain
3756
+ * Get available DeFi protocols and pools for a specific chain.
3757
+ *
3758
+ * @group Portfolio and execution
3759
+ *
3760
+ * @remarks Execution API. Partner API key only.
3365
3761
  *
3366
3762
  * @param chainId - Target chain ID
3367
3763
  * @returns List of available protocols with their pools and APY data
3368
3764
  *
3765
+ * @throws If `chainId` is unsupported
3766
+ *
3369
3767
  * @example
3370
3768
  * ```typescript
3371
3769
  * const protocols = await sdk.getAvailableProtocols(8453);
@@ -3394,11 +3792,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3394
3792
  }
3395
3793
  }
3396
3794
  /**
3397
- * Get all active DeFi positions for a user
3795
+ * Get active DeFi positions for a user.
3796
+ *
3797
+ * @group Portfolio and execution
3798
+ *
3799
+ * @remarks Execution API (`/data/position`). Pass the **EOA**; the SDK resolves the Safe.
3398
3800
  *
3399
3801
  * @param userAddress - User's EOA address
3400
- * @param chainId - Optional chain used to resolve the Safe address (defaults to Base 8453)
3401
- * @returns User's positions across all protocols
3802
+ * @param chainId - Chain used to resolve the Safe (defaults to Base `8453`)
3803
+ * @returns User's positions across protocols
3402
3804
  *
3403
3805
  * @example
3404
3806
  * ```typescript
@@ -3478,9 +3880,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3478
3880
  * Do not add `CLAIMED` withdrawals either (the array keeps them for 24
3479
3881
  * hours); their funds are back in the Safe and already counted.
3480
3882
  *
3883
+ * @group Portfolio and execution
3884
+ *
3885
+ * @remarks Data API portfolio endpoint. See {@link PortfolioDetailed.pendingAsyncWithdrawals}
3886
+ * when using {@link Strategy | yieldmaxxing}.
3887
+ *
3481
3888
  * @param userAddress - User's EOA address
3482
3889
  * @returns Portfolio with optional fee-adjusted balance fields
3483
3890
  *
3891
+ * @throws If `userAddress` is missing
3892
+ *
3484
3893
  * @example
3485
3894
  * ```typescript
3486
3895
  * const { portfolio } = await sdk.getPortfolio(userAddress);
@@ -3535,10 +3944,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3535
3944
  // User Details Methods
3536
3945
  // ============================================================================
3537
3946
  /**
3538
- * Get current authenticated user details
3539
- * Requires SIWE authentication
3947
+ * Get the authenticated user's profile for an asset.
3540
3948
  *
3541
- * @returns User details including smart wallet, chains, protocols, etc.
3949
+ * @group Portfolio and execution
3950
+ *
3951
+ * @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
3952
+ *
3953
+ * @param asset - Asset slice of the profile to return
3954
+ * @defaultValue `"USDC"`
3955
+ * @returns User details including smart wallet, chains, and protocols
3542
3956
  *
3543
3957
  * @example
3544
3958
  * ```typescript
@@ -3585,9 +3999,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3585
3999
  // TVL & Volume Methods
3586
4000
  // ============================================================================
3587
4001
  /**
3588
- * Get total value locked (TVL) across all Zyfai accounts
4002
+ * Get total value locked (TVL) across all Zyfai accounts.
4003
+ *
4004
+ * @group Analytics and opportunities
4005
+ *
4006
+ * @remarks Data API. Partner API key only; SIWE not required.
3589
4007
  *
3590
- * @returns Total TVL in USD and breakdown by chain
4008
+ * @returns Total TVL in USD
3591
4009
  *
3592
4010
  * @example
3593
4011
  * ```typescript
@@ -3610,7 +4028,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3610
4028
  // APY Per Strategy Methods
3611
4029
  // ============================================================================
3612
4030
  /**
3613
- * Get APY per strategy for a specific chain
4031
+ * Get APY per strategy for a specific chain.
4032
+ *
4033
+ * @group Analytics and opportunities
4034
+ *
4035
+ * @remarks Data API. Partner API key only.
3614
4036
  *
3615
4037
  * @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
3616
4038
  * @param days - Time period: 7, 14, or 30
@@ -3653,7 +4075,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3653
4075
  }
3654
4076
  }
3655
4077
  /**
3656
- * Get total volume across all Zyfai accounts
4078
+ * Get total volume across all Zyfai accounts.
4079
+ *
4080
+ * @group Analytics and opportunities
4081
+ *
4082
+ * @remarks Data API. Partner API key only.
3657
4083
  *
3658
4084
  * @returns Total volume in USD
3659
4085
  *
@@ -3680,7 +4106,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3680
4106
  // Active Wallets Methods
3681
4107
  // ============================================================================
3682
4108
  /**
3683
- * Get active wallets for a specific chain
4109
+ * Get active wallets for a specific chain.
4110
+ *
4111
+ * @group Analytics and opportunities
4112
+ *
4113
+ * @remarks Data API. Partner API key only.
3684
4114
  *
3685
4115
  * @param chainId - Chain ID to filter wallets
3686
4116
  * @returns List of active wallets on the specified chain
@@ -3717,7 +4147,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3717
4147
  }
3718
4148
  }
3719
4149
  /**
3720
- * Get smart wallets associated with an EOA address
4150
+ * Get smart wallets associated with an EOA address.
4151
+ *
4152
+ * @group Analytics and opportunities
4153
+ *
4154
+ * @remarks Data API. Partner API key only.
3721
4155
  *
3722
4156
  * @param eoaAddress - EOA (externally owned account) address
3723
4157
  * @returns List of smart wallets owned by the EOA
@@ -3754,7 +4188,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3754
4188
  // First Topup & History Methods
3755
4189
  // ============================================================================
3756
4190
  /**
3757
- * Get the first topup (deposit) information for a wallet
4191
+ * Get the first topup (deposit) information for a wallet.
4192
+ *
4193
+ * @group Analytics and opportunities
4194
+ *
4195
+ * @remarks Data API. Partner API key only.
3758
4196
  *
3759
4197
  * @param walletAddress - Smart wallet address
3760
4198
  * @param chainId - Chain ID
@@ -3789,7 +4227,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3789
4227
  }
3790
4228
  }
3791
4229
  /**
3792
- * Get transaction history for a wallet
4230
+ * Get transaction history for a wallet.
4231
+ *
4232
+ * @group Analytics and opportunities
4233
+ *
4234
+ * @remarks Data API. Partner API key only.
3793
4235
  *
3794
4236
  * @param walletAddress - Smart wallet address
3795
4237
  * @param chainId - Chain ID
@@ -3845,11 +4287,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3845
4287
  // Onchain Earnings Methods (Data API v2)
3846
4288
  // ============================================================================
3847
4289
  /**
3848
- * Get onchain earnings for a wallet
4290
+ * Get onchain earnings for a wallet.
4291
+ *
4292
+ * @group Analytics and opportunities
4293
+ *
4294
+ * @remarks Data API. Partner API key only.
3849
4295
  *
3850
4296
  * Includes gross totals plus net-of-fee totals:
3851
- * `totalEarningsByTokenWithFee = lifetime + unrealized + current × (1 - feeRate)`.
3852
- * Lifetime and unrealized are never multiplied by the keep-rate.
4297
+ * `totalEarningsByTokenWithFee = (lifetime + unrealized + current) × (1 - feeRate)`.
4298
+ * Ledger buckets are gross, so the keep-rate applies to all three.
3853
4299
  *
3854
4300
  * @param walletAddress - Smart wallet address
3855
4301
  * @returns Onchain earnings data with per-token breakdowns
@@ -3998,7 +4444,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3998
4444
  // Opportunities Methods (Data API v2)
3999
4445
  // ============================================================================
4000
4446
  /**
4001
- * Get conservative (low-risk) yield opportunities
4447
+ * Get conservative (low-risk) yield opportunities.
4448
+ *
4449
+ * @group Analytics and opportunities
4450
+ *
4451
+ * @remarks Data API. Partner API key only.
4002
4452
  *
4003
4453
  * @param chainId - Optional chain ID filter
4004
4454
  * @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
@@ -4456,6 +4906,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4456
4906
  * Allows granular control over which pools to use for each protocol on each chain.
4457
4907
  * This is useful for advanced users who want to target specific pools with desired APY/risk profiles.
4458
4908
  *
4909
+ * @group Customization and simulation
4910
+ *
4911
+ * @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
4912
+ *
4459
4913
  * @param customizations - Array of customization configurations
4460
4914
  * @returns Response indicating success
4461
4915
  *
@@ -4484,6 +4938,73 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4484
4938
  * ]);
4485
4939
  * ```
4486
4940
  */
4941
+ /**
4942
+ * Get persisted per-asset-type management settings (strategy, chains, protocols).
4943
+ *
4944
+ * @group Agent management
4945
+ */
4946
+ async getAssetTypeSettings() {
4947
+ await this.authenticateUser();
4948
+ return this.httpClient.get(ENDPOINTS.USER_ASSET_TYPE_SETTINGS);
4949
+ }
4950
+ /**
4951
+ * Reserve a one-time action id before the user signs an ERC-20 transfer.
4952
+ *
4953
+ * @group Agent management
4954
+ */
4955
+ async createAgentDepositIntent(request) {
4956
+ await this.authenticateUser();
4957
+ return this.httpClient.post(
4958
+ ENDPOINTS.USER_AGENT_DEPOSIT_INTENTS,
4959
+ request
4960
+ );
4961
+ }
4962
+ /**
4963
+ * Consume a one-time action id when registering the signed deposit.
4964
+ *
4965
+ * @group Agent management
4966
+ */
4967
+ async consumeAgentDepositIntent(actionId, request) {
4968
+ await this.authenticateUser();
4969
+ return this.httpClient.post(
4970
+ ENDPOINTS.USER_AGENT_DEPOSIT_INTENT_CONSUME(actionId),
4971
+ request
4972
+ );
4973
+ }
4974
+ /**
4975
+ * Poll MCP deposit-intent status (agent delegated session).
4976
+ *
4977
+ * @group Agent management
4978
+ */
4979
+ async getAgentDepositIntentStatus(actionId) {
4980
+ await this.authenticateUser();
4981
+ return this.httpClient.get(
4982
+ ENDPOINTS.USER_AGENT_DEPOSIT_INTENT(actionId)
4983
+ );
4984
+ }
4985
+ /**
4986
+ * Mark intent complete after the user signed on zyf.ai (SIWE session).
4987
+ *
4988
+ * @group Agent management
4989
+ */
4990
+ async completeAgentDepositIntent(actionId, request) {
4991
+ await this.authenticateUser();
4992
+ return this.httpClient.post(
4993
+ ENDPOINTS.USER_AGENT_DEPOSIT_INTENT_COMPLETE(actionId),
4994
+ request
4995
+ );
4996
+ }
4997
+ /**
4998
+ * Resolve a signing ticket from prepare_deposit (no user auth).
4999
+ *
5000
+ * @group Agent management
5001
+ */
5002
+ async resolveAgentDepositIntentTicket(ticket) {
5003
+ const query = `?ticket=${encodeURIComponent(ticket)}`;
5004
+ return this.httpClient.get(
5005
+ `${ENDPOINTS.AGENT_DEPOSIT_INTENT_RESOLVE}${query}`
5006
+ );
5007
+ }
4487
5008
  async customizeBatch(customizations) {
4488
5009
  try {
4489
5010
  await this.authenticateUser();
@@ -4503,8 +5024,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4503
5024
  *
4504
5025
  * Returns the list of pools available for a given protocol, optionally filtered by strategy.
4505
5026
  *
5027
+ * @group Customization and simulation
5028
+ *
5029
+ * @remarks Execution API. Partner API key only.
5030
+ *
4506
5031
  * @param protocolId - The protocol UUID
4507
- * @param strategy - Optional strategy filter ("conservative", "aggressive" or "yieldmaxxing")
5032
+ * @param strategy - Optional {@link Strategy} filter
4508
5033
  * @returns List of available pool names
4509
5034
  *
4510
5035
  * @example
@@ -4552,7 +5077,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4552
5077
  * calldata contains a "<RECEIVER>" placeholder that must be replaced with the
4553
5078
  * actual receiving address (e.g. the user's Safe) before sending the transaction.
4554
5079
  *
4555
- * @param params - Simulation parameters
5080
+ * @group Customization and simulation
5081
+ *
5082
+ * @remarks Data API simulation endpoint. Partner API key only.
5083
+ *
5084
+ * @param params - {@link SimulateBestPositionsParams}
4556
5085
  * @returns Chain-keyed map of simulated positions with calldata
4557
5086
  *
4558
5087
  * @example
@@ -4595,6 +5124,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4595
5124
  * Returns the pools that are currently configured for the authenticated user
4596
5125
  * for a given protocol and chain combination.
4597
5126
  *
5127
+ * @group Customization and simulation
5128
+ *
5129
+ * @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
5130
+ *
4598
5131
  * @param protocolId - The protocol UUID
4599
5132
  * @param chainId - The chain ID
4600
5133
  * @returns Currently selected pools and autoselect status
@@ -4702,10 +5235,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4702
5235
  // Vault Methods (Base only)
4703
5236
  // ============================================
4704
5237
  /**
4705
- * Deposit assets into the Zyfai Vault
4706
- * Currently only supports USDC on Base chain
5238
+ * Deposit assets into the Zyfai Vault (USDC on Base by default).
5239
+ *
5240
+ * @group Vault
4707
5241
  *
4708
- * @param amount - Amount to deposit (in human readable format, e.g., "100" for 100 USDC)
5242
+ * @remarks On-chain vault flow via connected wallet. Requires {@link ZyfaiSDK.connectAccount}.
5243
+ *
5244
+ * @param amount - Human-readable amount (e.g. `"100"` USDC)
4709
5245
  * @param asset - Asset to deposit (default: "USDC")
4710
5246
  * @returns Deposit transaction result
4711
5247
  *
@@ -5054,9 +5590,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
5054
5590
  * Events: depeg, liquidity_trap, liquidity_restored, pool_status_change,
5055
5591
  * new_collateral_detected, liquidity_drop.
5056
5592
  *
5057
- * @param handlers - Callback per event type, plus onError
5058
- * @param filters - Optional protocol/pool filter sent to the server on subscribe
5059
- * @returns Cleanup function — call it to close the connection
5593
+ * @group Realtime events
5594
+ *
5595
+ * @remarks Connects to defi-api WebSocket (`WS_ENDPOINT`). Auto-reconnects every 3s until
5596
+ * the returned cleanup function is called.
5597
+ *
5598
+ * @param handlers - {@link ZyfaiEventHandlers}
5599
+ * @param filters - Optional {@link ZyfaiEventFilters} sent on subscribe
5600
+ * @returns Cleanup function — call it to close the connection and stop reconnecting
5060
5601
  *
5061
5602
  * @example
5062
5603
  * ```typescript