@zyfai/sdk 0.3.0 → 0.3.1

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.mjs CHANGED
@@ -44,6 +44,9 @@ var ENDPOINTS = {
44
44
  AUTH_CHALLENGE: "/auth/challenge",
45
45
  // User
46
46
  USER_ME: "/users/me",
47
+ USER_AGENT_MANDATE: "/users/me/agent-mandate",
48
+ USER_AGENT_ENTER_INTENTS: "/users/me/agent-enter-intents",
49
+ USER_AGENT_ENTER_INTENT_CONSUME: (actionId) => `/users/me/agent-enter-intents/${encodeURIComponent(actionId)}/consume`,
47
50
  USER_WITHDRAW: "/users/withdraw",
48
51
  PARTIAL_WITHDRAW: "/users/partial-withdraw",
49
52
  LOG_DEPOSIT: "/users/log_deposit/v2",
@@ -169,6 +172,8 @@ var HttpClient = class {
169
172
  */
170
173
  constructor(apiKey, config = {}) {
171
174
  this.authToken = null;
175
+ /** @internal Extra headers on execution API requests (e.g. MCP server channel key). */
176
+ this.extraExecutionHeaders = {};
172
177
  this.apiKey = apiKey;
173
178
  const executionApiUrl = config.executionApiUrl ?? API_ENDPOINT;
174
179
  this.dataApiBaseUrl = config.dataApiUrl ?? DATA_API_ENDPOINT;
@@ -197,9 +202,17 @@ var HttpClient = class {
197
202
  setAuthToken(token) {
198
203
  this.authToken = token;
199
204
  }
205
+ /** @internal */
206
+ setExtraExecutionHeaders(headers) {
207
+ this.extraExecutionHeaders = headers;
208
+ }
200
209
  clearAuthToken() {
201
210
  this.authToken = null;
202
211
  }
212
+ /** Whether a user Bearer token is set on this client instance. */
213
+ hasAuthToken() {
214
+ return this.authToken !== null;
215
+ }
203
216
  getOrigin() {
204
217
  return this.origin;
205
218
  }
@@ -213,6 +226,9 @@ var HttpClient = class {
213
226
  if (this.authToken) {
214
227
  config.headers["Authorization"] = `Bearer ${this.authToken}`;
215
228
  }
229
+ for (const [key, value] of Object.entries(this.extraExecutionHeaders)) {
230
+ config.headers[key] = value;
231
+ }
216
232
  return config;
217
233
  },
218
234
  (error) => {
@@ -265,6 +281,10 @@ var HttpClient = class {
265
281
  const response = await this.client.patch(url, data, config);
266
282
  return response.data;
267
283
  }
284
+ async put(url, data, config) {
285
+ const response = await this.client.put(url, data, config);
286
+ return response.data;
287
+ }
268
288
  async delete(url, config) {
269
289
  const response = await this.client.delete(url, config);
270
290
  return response.data;
@@ -611,11 +631,22 @@ function isLocalExecutionApiUrl(executionApiUrl) {
611
631
  return false;
612
632
  }
613
633
  }
634
+ function isStagingExecutionApiUrl(executionApiUrl) {
635
+ if (executionApiUrl === EXECUTION_API_BASE_URLS.staging) {
636
+ return true;
637
+ }
638
+ try {
639
+ const { hostname } = new URL(executionApiUrl);
640
+ return hostname === "staging-api.zyf.ai";
641
+ } catch {
642
+ return false;
643
+ }
644
+ }
614
645
  function shouldBypassMinPortfolioCheck(executionApiUrl) {
615
646
  if (process.env.NODE_ENV === "production") {
616
647
  return false;
617
648
  }
618
- return isLocalExecutionApiUrl(executionApiUrl);
649
+ return isLocalExecutionApiUrl(executionApiUrl) || isStagingExecutionApiUrl(executionApiUrl);
619
650
  }
620
651
 
621
652
  // src/core/ZyfaiSDK.ts
@@ -1519,7 +1550,7 @@ function enrichOnchainEarningsTotals(apiData) {
1519
1550
  const unrealized = unrealizedByToken[symbol] ?? 0;
1520
1551
  const current = currentByToken[symbol] ?? 0;
1521
1552
  totalEarningsByTokenWithFee[symbol] = formatHumanAmount(
1522
- lifetime + unrealized + current * keepRate
1553
+ (lifetime + unrealized + current) * keepRate
1523
1554
  );
1524
1555
  });
1525
1556
  const chainKeys = /* @__PURE__ */ new Set([
@@ -1543,7 +1574,7 @@ function enrichOnchainEarningsTotals(apiData) {
1543
1574
  const unrealized = parseHumanAmount(unrealizedTokens[symbol]);
1544
1575
  const current = parseHumanAmount(currentTokens[symbol]);
1545
1576
  chainMap[symbol] = formatHumanAmount(
1546
- lifetime + unrealized + current * keepRate
1577
+ (lifetime + unrealized + current) * keepRate
1547
1578
  );
1548
1579
  });
1549
1580
  totalEarningsByChainWithFee[chainId] = chainMap;
@@ -1583,6 +1614,22 @@ var DepositCreditTimeoutError = class extends Error {
1583
1614
  };
1584
1615
  var MANAGED_ASSETS = ["USDC", "WETH", "EURC", "NVDAc"];
1585
1616
  var _ZyfaiSDK = class _ZyfaiSDK {
1617
+ /**
1618
+ * Create an SDK instance bound to a partner API key.
1619
+ *
1620
+ * @param config - API key string or {@link SDKConfig} with optional `rpcUrls` and `referralSource`
1621
+ *
1622
+ * @remarks
1623
+ * `@internal` fields on {@link SDKConfig} (`executionApiUrl`, `dataApiUrl`,
1624
+ * `bypassMinPortfolio`) are for local integration tests only.
1625
+ *
1626
+ * @throws If `apiKey` is missing
1627
+ *
1628
+ * @example
1629
+ * ```typescript
1630
+ * const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
1631
+ * ```
1632
+ */
1586
1633
  constructor(config) {
1587
1634
  this.signer = null;
1588
1635
  this.walletClient = null;
@@ -1592,6 +1639,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1592
1639
  this.connectedSmartWallet = null;
1593
1640
  this.currentProvider = null;
1594
1641
  this.currentChainId = null;
1642
+ /** EOA of the active user session (bearer or SIWE). Cleared on disconnect. */
1643
+ this.sessionEoa = null;
1595
1644
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
1596
1645
  const {
1597
1646
  apiKey,
@@ -1613,6 +1662,78 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1613
1662
  this.rpcUrls = rpcUrls;
1614
1663
  this.referralSource = referralSource;
1615
1664
  }
1665
+ /**
1666
+ * Create an SDK instance with an existing Zyfai user JWT (no wallet connected).
1667
+ *
1668
+ * @group Authentication and wallet
1669
+ */
1670
+ static forUser(config, session) {
1671
+ const sdk = new _ZyfaiSDK(config);
1672
+ sdk.applyUserSession(session);
1673
+ return sdk;
1674
+ }
1675
+ /** Alias for MCP delegated grants (scoped agent JWT). */
1676
+ static forDelegatedGrant(config, session) {
1677
+ return _ZyfaiSDK.forUser(config, session);
1678
+ }
1679
+ /**
1680
+ * Attach a Zyfai user JWT for API calls without `connectAccount`.
1681
+ *
1682
+ * @group Authentication and wallet
1683
+ */
1684
+ applyUserSession(session) {
1685
+ if (!session.accessToken) {
1686
+ throw new Error("accessToken is required");
1687
+ }
1688
+ this.httpClient.setAuthToken(session.accessToken);
1689
+ this.authenticatedUserId = session.userId ?? "bearer-session";
1690
+ this.sessionEoa = session.eoa ? getAddress2(session.eoa) : null;
1691
+ }
1692
+ /**
1693
+ * @internal Attach headers to execution API requests (MCP server agent channel).
1694
+ */
1695
+ setExecutionRequestHeaders(headers) {
1696
+ this.httpClient.setExtraExecutionHeaders(headers);
1697
+ }
1698
+ /** EOA of the active user session, if one is bound. */
1699
+ getSessionEoa() {
1700
+ return this.sessionEoa;
1701
+ }
1702
+ /**
1703
+ * Complete SIWE login with a prepared message and signature (OAuth consent, MCP).
1704
+ *
1705
+ * @group Authentication and wallet
1706
+ *
1707
+ * @param params.message - SIWE message fields (same shape as login API body)
1708
+ * @param params.signature - Wallet signature over the prepared SIWE string
1709
+ * @param params.origin - Origin header value; must match `message.uri`
1710
+ */
1711
+ async authenticateWithSignature(params) {
1712
+ const origin = params.origin ?? params.message.uri;
1713
+ const loginResponse = await this.httpClient.post(
1714
+ ENDPOINTS.AUTH_LOGIN,
1715
+ {
1716
+ message: params.message,
1717
+ signature: params.signature,
1718
+ referralSource: this.referralSource
1719
+ },
1720
+ {
1721
+ headers: {
1722
+ Origin: origin
1723
+ }
1724
+ }
1725
+ );
1726
+ if (!loginResponse.accessToken) {
1727
+ throw new Error("Authentication response missing access token");
1728
+ }
1729
+ this.httpClient.setAuthToken(loginResponse.accessToken);
1730
+ this.authenticatedUserId = loginResponse.userId || null;
1731
+ this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1732
+ this.isPredeployed = loginResponse.predeployed || false;
1733
+ this.connectedSmartWallet = loginResponse.smartWallet || null;
1734
+ this.sessionEoa = getAddress2(params.message.address);
1735
+ return loginResponse;
1736
+ }
1616
1737
  /**
1617
1738
  * Warn that a legacy method is deprecated in favor of sendDeposit.
1618
1739
  * Predeployed wallets no longer require deploySafe / createSessionKey.
@@ -1634,6 +1755,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1634
1755
  if (this.authenticatedUserId !== null) {
1635
1756
  return;
1636
1757
  }
1758
+ if (this.httpClient.hasAuthToken()) {
1759
+ return;
1760
+ }
1637
1761
  const walletClient = this.getWalletClient();
1638
1762
  const userAddress = getAddress2(walletClient.account.address);
1639
1763
  const chainId = this.currentChainId || walletClient.chain?.id || 8453;
@@ -1687,6 +1811,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1687
1811
  this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1688
1812
  this.isPredeployed = loginResponse.predeployed || false;
1689
1813
  this.connectedSmartWallet = loginResponse.smartWallet || null;
1814
+ this.sessionEoa = userAddress;
1690
1815
  } catch (error) {
1691
1816
  throw new Error(
1692
1817
  `Failed to authenticate user: ${error.message}`
@@ -1697,8 +1822,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1697
1822
  * Update user profile with Smart Wallet address and chain configuration
1698
1823
  * This method requires SIWE authentication and is automatically called after deploySafe
1699
1824
  *
1700
- * @param request - User profile update data
1701
- * @returns Updated user profile information
1825
+ * @group Portfolio and execution
1826
+ *
1827
+ * @param request - Profile fields to update (per-asset settings supported)
1828
+ * @returns Updated user profile from the execution API
1829
+ *
1830
+ * @throws If strategy is invalid or authentication fails
1702
1831
  *
1703
1832
  * @example
1704
1833
  * ```typescript
@@ -1759,8 +1888,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1759
1888
  * Pause the agent by clearing all protocols
1760
1889
  * Sets the user's protocols to an empty array, effectively pausing automated operations
1761
1890
  *
1891
+ * @group Portfolio and execution
1892
+ *
1762
1893
  * @returns Response indicating success and updated user details
1763
1894
  *
1895
+ * @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
1896
+ *
1764
1897
  * @example
1765
1898
  * ```typescript
1766
1899
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1791,8 +1924,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1791
1924
  * Resume the agent by restoring protocols based on user's strategy for each asset
1792
1925
  * Fetches available protocols and assigns them based on each asset's strategy
1793
1926
  *
1927
+ * @group Portfolio and execution
1928
+ *
1794
1929
  * @returns Response indicating success and updated user details
1795
1930
  *
1931
+ * @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
1932
+ *
1796
1933
  * @example
1797
1934
  * ```typescript
1798
1935
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1831,9 +1968,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1831
1968
  * Enable splitting for the user's account
1832
1969
  * When enabled, deposits are split across multiple protocols based on minSplits setting
1833
1970
  *
1834
- * @param minSplits - Optional minimum number of protocols to split across (default: 3)
1971
+ * @group Portfolio and execution
1972
+ *
1973
+ * @param minSplits - Minimum protocols to split across (max 4)
1974
+ * @defaultValue 1
1835
1975
  * @returns Response indicating success and updated user details
1836
1976
  *
1977
+ * @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
1978
+ *
1979
+ * @throws If `minSplits` exceeds 4
1980
+ *
1837
1981
  * @example
1838
1982
  * ```typescript
1839
1983
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1866,8 +2010,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1866
2010
  * Disable splitting for the user's account
1867
2011
  * When disabled, deposits will not be split across multiple protocols
1868
2012
  *
2013
+ * @group Portfolio and execution
2014
+ *
1869
2015
  * @returns Response indicating success and updated user details
1870
2016
  *
2017
+ * @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
2018
+ *
1871
2019
  * @example
1872
2020
  * ```typescript
1873
2021
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1896,9 +2044,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1896
2044
  * Update the minimum number of splits for the user's account
1897
2045
  * This controls across how many protocols deposits should be distributed
1898
2046
  *
1899
- * @param minSplits - Minimum number of protocols to split across
2047
+ * @group Portfolio and execution
2048
+ *
2049
+ * @param minSplits - Minimum number of protocols to split across (at least 1)
1900
2050
  * @returns Response indicating success and updated user details
1901
2051
  *
2052
+ * @throws If `minSplits` is less than 1
2053
+ *
1902
2054
  * @example
1903
2055
  * ```typescript
1904
2056
  * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
@@ -1977,6 +2129,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1977
2129
  }
1978
2130
  this.authenticatedUserId = null;
1979
2131
  this.hasActiveSessionKey = false;
2132
+ this.sessionEoa = null;
1980
2133
  this.httpClient.clearAuthToken();
1981
2134
  if (this.walletClient && this.currentProvider) {
1982
2135
  const chainConfig = getChainConfig(
@@ -2000,12 +2153,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2000
2153
  }
2001
2154
  }
2002
2155
  /**
2003
- * Connect account for signing transactions
2004
- * Accepts either a private key string or a modern wallet provider
2156
+ * Connect an account for signing (SIWE and on-chain transfers).
2157
+ *
2158
+ * @remarks
2159
+ * Required before user-scoped execution calls (deposits, withdrawals, profile).
2160
+ * Data API reads typically need only the API key.
2161
+ *
2162
+ * @group Authentication and wallet
2163
+ *
2164
+ * @param account - Private key hex string or EIP-1193 wallet provider
2165
+ * @param chainId - Initial chain for RPC and SIWE
2166
+ * @defaultValue 8453
2167
+ * @returns The connected EOA address (checksum)
2005
2168
  *
2006
- * @param account - Private key string or wallet provider object
2007
- * @param chainId - Target chain ID (default: 8453 - Base)
2008
- * @returns The connected EOA address
2169
+ * @throws If the chain is unsupported or the provider returns no accounts
2009
2170
  *
2010
2171
  * @example
2011
2172
  * // With private key
@@ -2024,6 +2185,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2024
2185
  this.isPredeployed = false;
2025
2186
  this.connectedSmartWallet = null;
2026
2187
  this.currentChainId = null;
2188
+ this.sessionEoa = null;
2027
2189
  this.httpClient.clearAuthToken();
2028
2190
  if (this.currentProvider?.removeAllListeners) {
2029
2191
  try {
@@ -2091,8 +2253,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2091
2253
  return connectedAddress;
2092
2254
  }
2093
2255
  /**
2094
- * Disconnect account and clear authentication state
2095
- * Resets wallet connection, JWT token, and all authentication-related state
2256
+ * Clear the connected wallet, SIWE session, and cached smart-wallet state.
2257
+ *
2258
+ * @group Authentication and wallet
2259
+ *
2260
+ * @returns Resolves when local SDK state is cleared
2096
2261
  *
2097
2262
  * @example
2098
2263
  * ```typescript
@@ -2115,6 +2280,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2115
2280
  this.hasActiveSessionKey = false;
2116
2281
  this.isPredeployed = false;
2117
2282
  this.connectedSmartWallet = null;
2283
+ this.sessionEoa = null;
2118
2284
  this.httpClient.clearAuthToken();
2119
2285
  }
2120
2286
  /**
@@ -2181,15 +2347,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2181
2347
  });
2182
2348
  }
2183
2349
  /**
2184
- * Get smart wallet address for a user
2185
- * Returns the Safe address for an EOA (deterministic for legacy wallets,
2186
- * backend-assigned for predeployed pool wallets).
2350
+ * Resolve the Safe smart wallet for an EOA on a chain.
2351
+ *
2352
+ * @remarks
2353
+ * Predeployed pool wallets use a backend-assigned address; legacy wallets use
2354
+ * a deterministic CREATE2 address.
2355
+ *
2356
+ * @group Authentication and wallet
2187
2357
  *
2188
2358
  * @param userAddress - User's EOA address
2189
2359
  * @param chainId - Target chain ID
2190
- * @returns Smart wallet address, deployment status, and whether userAddress
2191
- * is an on-chain OwnableValidator owner (false for reserved predeployed
2192
- * wallets until the first deposit rotates ownership)
2360
+ * @returns Smart wallet address, deployment status, and on-chain ownership flag
2361
+ *
2362
+ * @throws If `userAddress` is missing or `chainId` is unsupported
2193
2363
  */
2194
2364
  async getSmartWalletAddress(userAddress, chainId) {
2195
2365
  if (!userAddress) {
@@ -2221,10 +2391,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2221
2391
  /**
2222
2392
  * Deploy Safe Smart Wallet for a user
2223
2393
  *
2224
- * @deprecated Prefer `sendDeposit()`. Predeployed Safes and session keys are
2394
+ * @deprecated Prefer {@link ZyfaiSDK.sendDeposit}. Predeployed Safes and session keys are
2225
2395
  * managed automatically on first deposit. This method remains available for
2226
2396
  * legacy flows.
2227
2397
  *
2398
+ * @see {@link ZyfaiSDK.sendDeposit}
2399
+ *
2400
+ * @group Deposits and withdrawals
2401
+ *
2228
2402
  * @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
2229
2403
  * @param chainId - Target chain ID
2230
2404
  * @param strategy - Optional strategy selection: "conservative" (default), "aggressive" or "yieldmaxxing"
@@ -2361,10 +2535,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2361
2535
  * Create session key with auto-fetched configuration from Zyfai API
2362
2536
  * This is the simplified method that automatically fetches session configuration
2363
2537
  *
2364
- * @deprecated Prefer `sendDeposit()`. Predeployed wallets already have the
2538
+ * @deprecated Prefer {@link ZyfaiSDK.sendDeposit}. Predeployed wallets already have the
2365
2539
  * agent session enabled; session activation is handled after first deposit.
2366
2540
  * This method remains available for legacy flows.
2367
2541
  *
2542
+ * @see {@link ZyfaiSDK.sendDeposit}
2543
+ *
2544
+ * @group Deposits and withdrawals
2545
+ *
2368
2546
  * @param userAddress - User's EOA or Safe address
2369
2547
  * @param chainId - Target chain ID
2370
2548
  * @returns Session key response with signature and nonces
@@ -2618,6 +2796,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2618
2796
  * @param params.chains - Chains to enable. Defaults to every chain the asset
2619
2797
  * exists on. **Additive**: chains already enabled are kept, so this cannot
2620
2798
  * be used to disable one.
2799
+ * @group Portfolio and execution
2800
+ *
2621
2801
  * @returns The updated profile for that asset
2622
2802
  *
2623
2803
  * @example
@@ -2735,7 +2915,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2735
2915
  * transfer lands on the counterfactual address and the backend deploys + hands over on first
2736
2916
  * deposit (report-deposit). Use this only to pre-provision chains ahead of time.
2737
2917
  *
2738
- * @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
2918
+ * @group Deposits and withdrawals
2919
+ *
2920
+ * @param chainIds - Chain IDs to deploy the wallet on (e.g. `[1, 42161]`)
2921
+ * @returns Deployment summary from the execution API
2922
+ *
2923
+ * @throws If `chainIds` is empty or contains an unsupported chain
2924
+ *
2925
+ * @remarks
2926
+ * Requires {@link ZyfaiSDK.connectAccount} (SIWE). Optional ahead of deposits;
2927
+ * {@link ZyfaiSDK.sendDeposit} can deploy on first deposit for predeployed wallets.
2739
2928
  */
2740
2929
  async deployOnChains(chainIds) {
2741
2930
  if (!chainIds?.length) {
@@ -2748,10 +2937,33 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2748
2937
  return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
2749
2938
  }
2750
2939
  /**
2751
- * Send a deposit from an EOA to its Safe smart wallet.
2940
+ * Transfer funds from the connected EOA to the user's Safe and register the deposit.
2941
+ *
2942
+ * @remarks
2943
+ * Execution API + on-chain ERC-20 `transfer`. Confirms the transaction, then calls
2944
+ * {@link ZyfaiSDK.logDeposit}. Pair with {@link ZyfaiSDK.waitForDepositCredit} for
2945
+ * investable balance. Custom-wallet flows: {@link ZyfaiSDK.buildDepositTransfer},
2946
+ * {@link ZyfaiSDK.logDeposit}, {@link ZyfaiSDK.getDepositStatus}.
2947
+ *
2948
+ * Requires {@link ZyfaiSDK.connectAccount}. Pass the **EOA** as `userAddress`.
2949
+ *
2950
+ * @group Deposits and withdrawals
2951
+ *
2952
+ * @param userAddress - Owner EOA (not the Safe)
2953
+ * @param chainId - Chain for the transfer
2954
+ * @param amount - Amount in least units (string integer)
2955
+ * @param asset - Asset symbol (`USDC`, `WETH`, `EURC`, `NVDAc`)
2956
+ * @param strategy - Optional first-deposit {@link Strategy}
2957
+ * @returns Transfer receipt and deposit registration (not yet credited until polled)
2958
+ *
2959
+ * @throws If validation fails, minimum portfolio is not met, Safe is unavailable, or transfer/register fails
2752
2960
  *
2753
- * Confirms the ERC-20 transfer and starts the custody-credit lifecycle. Use
2754
- * `waitForDepositCredit(result.registration.id, chainId)` to await credit.
2961
+ * @example
2962
+ * ```typescript
2963
+ * await sdk.connectAccount(provider);
2964
+ * const sent = await sdk.sendDeposit(eoa, 8453, "10000000", "USDC", "conservative");
2965
+ * await sdk.waitForDepositCredit(sent.registration.id, 8453);
2966
+ * ```
2755
2967
  */
2756
2968
  async sendDeposit(userAddress, chainId, amount, asset, strategy) {
2757
2969
  try {
@@ -2870,8 +3082,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2870
3082
  }
2871
3083
  }
2872
3084
  /**
2873
- * @deprecated Compatibility convenience method. Prefer `sendDeposit()` followed by
2874
- * `waitForDepositCredit()` when the caller owns the completion UX.
3085
+ * @deprecated Compatibility convenience method. Prefer {@link ZyfaiSDK.sendDeposit} followed by
3086
+ * {@link ZyfaiSDK.waitForDepositCredit} when the caller owns the completion UX.
3087
+ *
3088
+ * @see {@link ZyfaiSDK.sendDeposit}
3089
+ *
3090
+ * @group Deposits and withdrawals
2875
3091
  */
2876
3092
  async depositFunds(userAddress, chainId, amount, asset, strategy) {
2877
3093
  this.warnDeprecatedOnboardingMethod("depositFunds");
@@ -2891,10 +3107,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2891
3107
  };
2892
3108
  }
2893
3109
  /**
2894
- * Prepare ERC-20 transfer calldata for builders using a custom signer,
2895
- * sponsored transaction provider, or mobile wallet. Most custom-wallet
2896
- * integrations can compose this with `ensureFirstDepositSetup()` and
2897
- * `logDeposit()` instead.
3110
+ * Build ERC-20 transfer calldata for a custom signer or sponsored tx flow.
3111
+ *
3112
+ * @remarks
3113
+ * Compose with {@link ZyfaiSDK.ensureFirstDepositSetup}, submit the transfer, then
3114
+ * {@link ZyfaiSDK.logDeposit} and {@link ZyfaiSDK.waitForDepositCredit}.
3115
+ *
3116
+ * @group Deposits and withdrawals
3117
+ *
3118
+ * @param params.userAddress - Owner EOA
3119
+ * @param params.chainId - Target chain
3120
+ * @param params.amount - Least units (string integer)
3121
+ * @param params.asset - {@link SupportedAsset}
3122
+ * @returns Safe address, token, and encoded `transfer` calldata
3123
+ *
3124
+ * @throws If inputs are invalid or the Safe address cannot be resolved
2898
3125
  */
2899
3126
  async buildDepositTransfer(params) {
2900
3127
  const { userAddress, chainId, amount, asset } = params;
@@ -3001,6 +3228,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3001
3228
  * When setup runs (`applied: true`), protocol configuration is persisted
3002
3229
  * before returning. Failures throw so callers can abort before submitting a
3003
3230
  * transfer. High-level deposit methods still treat setup as best-effort.
3231
+ *
3232
+ * @group Deposits and withdrawals
3233
+ *
3234
+ * @param strategy - Optional first-deposit {@link Strategy}
3235
+ * @returns `{ applied: true }` when chain/protocol config was written; `false` if already configured
3236
+ *
3237
+ * @throws If strategy is invalid or setup did not persist
3004
3238
  */
3005
3239
  async ensureFirstDepositSetup(strategy) {
3006
3240
  if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
@@ -3022,6 +3256,30 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3022
3256
  }
3023
3257
  return { applied: true };
3024
3258
  }
3259
+ /**
3260
+ * Prepare entering a position: persist first-deposit profile when needed and
3261
+ * return ERC-20 transfer calldata for the user to sign (does not broadcast).
3262
+ *
3263
+ * @group Deposits and withdrawals
3264
+ */
3265
+ async prepareEnterPosition(params) {
3266
+ const { userAddress, chainId, amount, asset, strategy } = params;
3267
+ if (this.sessionEoa && getAddress2(userAddress) !== this.sessionEoa) {
3268
+ throw new Error("userAddress does not match authenticated session EOA");
3269
+ }
3270
+ const setup = await this.ensureFirstDepositSetup(strategy);
3271
+ const transfer = await this.buildDepositTransfer({
3272
+ userAddress,
3273
+ chainId,
3274
+ amount,
3275
+ asset
3276
+ });
3277
+ return {
3278
+ phase: "prepare_transfer",
3279
+ setup,
3280
+ transfer
3281
+ };
3282
+ }
3025
3283
  /** Best-effort first-deposit setup shared by both high-level deposit flows. */
3026
3284
  async prepareFirstDeposit(strategy) {
3027
3285
  try {
@@ -3077,8 +3335,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3077
3335
  * @param chainId - Chain ID where the deposit was made
3078
3336
  * @param txHash - Transaction hash of the deposit
3079
3337
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
3080
- * @param tokenAddress - Optional: Token address (auto-selected based on chain if not provided)
3081
- * @returns Log deposit response with success status
3338
+ * @param tokenAddress - Optional token contract (defaults per chain)
3339
+ * @returns Log deposit response with lifecycle record
3340
+ *
3341
+ * @group Deposits and withdrawals
3342
+ *
3343
+ * @throws If inputs are invalid or the execution API rejects registration
3082
3344
  *
3083
3345
  * @example
3084
3346
  * ```typescript
@@ -3129,8 +3391,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3129
3391
  }
3130
3392
  }
3131
3393
  /**
3132
- * Fetch the custody handover and balance-credit lifecycle for a registered
3133
- * deposit. A status of `credited` is required before funds are investable.
3394
+ * Fetch custody handover and balance-credit status for a registered deposit.
3395
+ *
3396
+ * @remarks
3397
+ * `status === "credited"` with `balanceCredited === true` means funds are investable.
3398
+ * Requires {@link ZyfaiSDK.connectAccount} (SIWE).
3399
+ *
3400
+ * @group Deposits and withdrawals
3401
+ *
3402
+ * @param depositId - Id from {@link LogDepositResponse} / {@link DepositResponse.registration}
3403
+ * @returns {@link DepositLifecycleResponse}
3404
+ *
3405
+ * @throws If `depositId` is missing
3134
3406
  */
3135
3407
  async getDepositStatus(depositId) {
3136
3408
  if (!depositId) {
@@ -3152,7 +3424,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3152
3424
  * ~250ms) with a ~20 second completion window. Override `timeoutMs` when a
3153
3425
  * caller intentionally wants to wait longer than the normal UX window.
3154
3426
  *
3155
- * Requires `connectAccount()` on the same SDK instance first.
3427
+ * Requires {@link ZyfaiSDK.connectAccount} on the same SDK instance.
3428
+ *
3429
+ * @group Deposits and withdrawals
3430
+ *
3431
+ * @param depositId - Deposit lifecycle id
3432
+ * @param chainId - Chain (controls poll interval and default timeout)
3433
+ * @param options - Optional `intervalMs` and `timeoutMs` overrides
3434
+ * @returns Final lifecycle record when credited
3435
+ *
3436
+ * @throws `DepositCreditTimeoutError` when the poll window elapses without credit
3437
+ * @throws If deposit recovers to EOA or polling fails
3156
3438
  */
3157
3439
  async waitForDepositCredit(depositId, chainId, options) {
3158
3440
  if (!depositId) {
@@ -3215,8 +3497,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3215
3497
  *
3216
3498
  * @param userAddress - User's address (owner of the Safe)
3217
3499
  * @param chainId - Target chain ID
3218
- * @param amount - Optional: Amount in least decimal units to withdraw (partial withdrawal). If not specified, withdraws all funds
3219
- * @returns Withdraw response with message and optional transaction hash (available once processed)
3500
+ * @param amount - Optional amount in least units (partial withdrawal); omit for full withdraw
3501
+ * @param tokenSymbol - Optional asset symbol when withdrawing a specific token
3502
+ * @returns Withdraw response with message and optional transaction hash
3503
+ *
3504
+ * @group Deposits and withdrawals
3505
+ *
3506
+ * @throws If `userAddress` or `chainId` is invalid, or the execution API rejects the request
3220
3507
  *
3221
3508
  * @example
3222
3509
  * ```typescript
@@ -3313,11 +3600,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3313
3600
  );
3314
3601
  }
3315
3602
  /**
3316
- * Get available DeFi protocols and pools for a specific chain
3603
+ * Get available DeFi protocols and pools for a specific chain.
3604
+ *
3605
+ * @group Portfolio and execution
3606
+ *
3607
+ * @remarks Execution API. Partner API key only.
3317
3608
  *
3318
3609
  * @param chainId - Target chain ID
3319
3610
  * @returns List of available protocols with their pools and APY data
3320
3611
  *
3612
+ * @throws If `chainId` is unsupported
3613
+ *
3321
3614
  * @example
3322
3615
  * ```typescript
3323
3616
  * const protocols = await sdk.getAvailableProtocols(8453);
@@ -3346,11 +3639,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3346
3639
  }
3347
3640
  }
3348
3641
  /**
3349
- * Get all active DeFi positions for a user
3642
+ * Get active DeFi positions for a user.
3643
+ *
3644
+ * @group Portfolio and execution
3645
+ *
3646
+ * @remarks Execution API (`/data/position`). Pass the **EOA**; the SDK resolves the Safe.
3350
3647
  *
3351
3648
  * @param userAddress - User's EOA address
3352
- * @param chainId - Optional chain used to resolve the Safe address (defaults to Base 8453)
3353
- * @returns User's positions across all protocols
3649
+ * @param chainId - Chain used to resolve the Safe (defaults to Base `8453`)
3650
+ * @returns User's positions across protocols
3354
3651
  *
3355
3652
  * @example
3356
3653
  * ```typescript
@@ -3430,9 +3727,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3430
3727
  * Do not add `CLAIMED` withdrawals either (the array keeps them for 24
3431
3728
  * hours); their funds are back in the Safe and already counted.
3432
3729
  *
3730
+ * @group Portfolio and execution
3731
+ *
3732
+ * @remarks Data API portfolio endpoint. See {@link PortfolioDetailed.pendingAsyncWithdrawals}
3733
+ * when using {@link Strategy | yieldmaxxing}.
3734
+ *
3433
3735
  * @param userAddress - User's EOA address
3434
3736
  * @returns Portfolio with optional fee-adjusted balance fields
3435
3737
  *
3738
+ * @throws If `userAddress` is missing
3739
+ *
3436
3740
  * @example
3437
3741
  * ```typescript
3438
3742
  * const { portfolio } = await sdk.getPortfolio(userAddress);
@@ -3487,10 +3791,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3487
3791
  // User Details Methods
3488
3792
  // ============================================================================
3489
3793
  /**
3490
- * Get current authenticated user details
3491
- * Requires SIWE authentication
3794
+ * Get the authenticated user's profile for an asset.
3492
3795
  *
3493
- * @returns User details including smart wallet, chains, protocols, etc.
3796
+ * @group Portfolio and execution
3797
+ *
3798
+ * @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
3799
+ *
3800
+ * @param asset - Asset slice of the profile to return
3801
+ * @defaultValue `"USDC"`
3802
+ * @returns User details including smart wallet, chains, and protocols
3494
3803
  *
3495
3804
  * @example
3496
3805
  * ```typescript
@@ -3537,9 +3846,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3537
3846
  // TVL & Volume Methods
3538
3847
  // ============================================================================
3539
3848
  /**
3540
- * Get total value locked (TVL) across all Zyfai accounts
3849
+ * Get total value locked (TVL) across all Zyfai accounts.
3850
+ *
3851
+ * @group Analytics and opportunities
3541
3852
  *
3542
- * @returns Total TVL in USD and breakdown by chain
3853
+ * @remarks Data API. Partner API key only; SIWE not required.
3854
+ *
3855
+ * @returns Total TVL in USD
3543
3856
  *
3544
3857
  * @example
3545
3858
  * ```typescript
@@ -3562,7 +3875,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3562
3875
  // APY Per Strategy Methods
3563
3876
  // ============================================================================
3564
3877
  /**
3565
- * Get APY per strategy for a specific chain
3878
+ * Get APY per strategy for a specific chain.
3879
+ *
3880
+ * @group Analytics and opportunities
3881
+ *
3882
+ * @remarks Data API. Partner API key only.
3566
3883
  *
3567
3884
  * @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
3568
3885
  * @param days - Time period: 7, 14, or 30
@@ -3605,7 +3922,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3605
3922
  }
3606
3923
  }
3607
3924
  /**
3608
- * Get total volume across all Zyfai accounts
3925
+ * Get total volume across all Zyfai accounts.
3926
+ *
3927
+ * @group Analytics and opportunities
3928
+ *
3929
+ * @remarks Data API. Partner API key only.
3609
3930
  *
3610
3931
  * @returns Total volume in USD
3611
3932
  *
@@ -3632,7 +3953,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3632
3953
  // Active Wallets Methods
3633
3954
  // ============================================================================
3634
3955
  /**
3635
- * Get active wallets for a specific chain
3956
+ * Get active wallets for a specific chain.
3957
+ *
3958
+ * @group Analytics and opportunities
3959
+ *
3960
+ * @remarks Data API. Partner API key only.
3636
3961
  *
3637
3962
  * @param chainId - Chain ID to filter wallets
3638
3963
  * @returns List of active wallets on the specified chain
@@ -3669,7 +3994,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3669
3994
  }
3670
3995
  }
3671
3996
  /**
3672
- * Get smart wallets associated with an EOA address
3997
+ * Get smart wallets associated with an EOA address.
3998
+ *
3999
+ * @group Analytics and opportunities
4000
+ *
4001
+ * @remarks Data API. Partner API key only.
3673
4002
  *
3674
4003
  * @param eoaAddress - EOA (externally owned account) address
3675
4004
  * @returns List of smart wallets owned by the EOA
@@ -3706,7 +4035,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3706
4035
  // First Topup & History Methods
3707
4036
  // ============================================================================
3708
4037
  /**
3709
- * Get the first topup (deposit) information for a wallet
4038
+ * Get the first topup (deposit) information for a wallet.
4039
+ *
4040
+ * @group Analytics and opportunities
4041
+ *
4042
+ * @remarks Data API. Partner API key only.
3710
4043
  *
3711
4044
  * @param walletAddress - Smart wallet address
3712
4045
  * @param chainId - Chain ID
@@ -3741,7 +4074,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3741
4074
  }
3742
4075
  }
3743
4076
  /**
3744
- * Get transaction history for a wallet
4077
+ * Get transaction history for a wallet.
4078
+ *
4079
+ * @group Analytics and opportunities
4080
+ *
4081
+ * @remarks Data API. Partner API key only.
3745
4082
  *
3746
4083
  * @param walletAddress - Smart wallet address
3747
4084
  * @param chainId - Chain ID
@@ -3797,11 +4134,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3797
4134
  // Onchain Earnings Methods (Data API v2)
3798
4135
  // ============================================================================
3799
4136
  /**
3800
- * Get onchain earnings for a wallet
4137
+ * Get onchain earnings for a wallet.
4138
+ *
4139
+ * @group Analytics and opportunities
4140
+ *
4141
+ * @remarks Data API. Partner API key only.
3801
4142
  *
3802
4143
  * Includes gross totals plus net-of-fee totals:
3803
- * `totalEarningsByTokenWithFee = lifetime + unrealized + current × (1 - feeRate)`.
3804
- * Lifetime and unrealized are never multiplied by the keep-rate.
4144
+ * `totalEarningsByTokenWithFee = (lifetime + unrealized + current) × (1 - feeRate)`.
4145
+ * Ledger buckets are gross, so the keep-rate applies to all three.
3805
4146
  *
3806
4147
  * @param walletAddress - Smart wallet address
3807
4148
  * @returns Onchain earnings data with per-token breakdowns
@@ -3950,7 +4291,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3950
4291
  // Opportunities Methods (Data API v2)
3951
4292
  // ============================================================================
3952
4293
  /**
3953
- * Get conservative (low-risk) yield opportunities
4294
+ * Get conservative (low-risk) yield opportunities.
4295
+ *
4296
+ * @group Analytics and opportunities
4297
+ *
4298
+ * @remarks Data API. Partner API key only.
3954
4299
  *
3955
4300
  * @param chainId - Optional chain ID filter
3956
4301
  * @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
@@ -4408,6 +4753,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4408
4753
  * Allows granular control over which pools to use for each protocol on each chain.
4409
4754
  * This is useful for advanced users who want to target specific pools with desired APY/risk profiles.
4410
4755
  *
4756
+ * @group Customization and simulation
4757
+ *
4758
+ * @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
4759
+ *
4411
4760
  * @param customizations - Array of customization configurations
4412
4761
  * @returns Response indicating success
4413
4762
  *
@@ -4436,6 +4785,65 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4436
4785
  * ]);
4437
4786
  * ```
4438
4787
  */
4788
+ /**
4789
+ * Get the user's agent management mandate (autonomy limits).
4790
+ *
4791
+ * @group Agent management
4792
+ */
4793
+ async getAgentMandate(oauthClientId) {
4794
+ await this.authenticateUser();
4795
+ const query = oauthClientId ? `?oauthClientId=${encodeURIComponent(oauthClientId)}` : "";
4796
+ return this.httpClient.get(
4797
+ `${ENDPOINTS.USER_AGENT_MANDATE}${query}`
4798
+ );
4799
+ }
4800
+ /**
4801
+ * Create or update the user's agent management mandate.
4802
+ *
4803
+ * @group Agent management
4804
+ */
4805
+ async setAgentMandate(request) {
4806
+ await this.authenticateUser();
4807
+ return this.httpClient.put(
4808
+ ENDPOINTS.USER_AGENT_MANDATE,
4809
+ request
4810
+ );
4811
+ }
4812
+ /**
4813
+ * Revoke the user's agent management mandate.
4814
+ *
4815
+ * @group Agent management
4816
+ */
4817
+ async revokeAgentMandate(oauthClientId) {
4818
+ await this.authenticateUser();
4819
+ return this.httpClient.delete(
4820
+ `${ENDPOINTS.USER_AGENT_MANDATE}?oauthClientId=${encodeURIComponent(oauthClientId)}`
4821
+ );
4822
+ }
4823
+ /**
4824
+ * Reserve a one-time action id before the user signs an ERC-20 transfer.
4825
+ *
4826
+ * @group Agent management
4827
+ */
4828
+ async createAgentEnterIntent(request) {
4829
+ await this.authenticateUser();
4830
+ return this.httpClient.post(
4831
+ ENDPOINTS.USER_AGENT_ENTER_INTENTS,
4832
+ request
4833
+ );
4834
+ }
4835
+ /**
4836
+ * Consume a one-time action id when registering the signed deposit.
4837
+ *
4838
+ * @group Agent management
4839
+ */
4840
+ async consumeAgentEnterIntent(actionId, request) {
4841
+ await this.authenticateUser();
4842
+ await this.httpClient.post(
4843
+ ENDPOINTS.USER_AGENT_ENTER_INTENT_CONSUME(actionId),
4844
+ request
4845
+ );
4846
+ }
4439
4847
  async customizeBatch(customizations) {
4440
4848
  try {
4441
4849
  await this.authenticateUser();
@@ -4455,8 +4863,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4455
4863
  *
4456
4864
  * Returns the list of pools available for a given protocol, optionally filtered by strategy.
4457
4865
  *
4866
+ * @group Customization and simulation
4867
+ *
4868
+ * @remarks Execution API. Partner API key only.
4869
+ *
4458
4870
  * @param protocolId - The protocol UUID
4459
- * @param strategy - Optional strategy filter ("conservative", "aggressive" or "yieldmaxxing")
4871
+ * @param strategy - Optional {@link Strategy} filter
4460
4872
  * @returns List of available pool names
4461
4873
  *
4462
4874
  * @example
@@ -4504,7 +4916,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4504
4916
  * calldata contains a "<RECEIVER>" placeholder that must be replaced with the
4505
4917
  * actual receiving address (e.g. the user's Safe) before sending the transaction.
4506
4918
  *
4507
- * @param params - Simulation parameters
4919
+ * @group Customization and simulation
4920
+ *
4921
+ * @remarks Data API simulation endpoint. Partner API key only.
4922
+ *
4923
+ * @param params - {@link SimulateBestPositionsParams}
4508
4924
  * @returns Chain-keyed map of simulated positions with calldata
4509
4925
  *
4510
4926
  * @example
@@ -4547,6 +4963,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4547
4963
  * Returns the pools that are currently configured for the authenticated user
4548
4964
  * for a given protocol and chain combination.
4549
4965
  *
4966
+ * @group Customization and simulation
4967
+ *
4968
+ * @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
4969
+ *
4550
4970
  * @param protocolId - The protocol UUID
4551
4971
  * @param chainId - The chain ID
4552
4972
  * @returns Currently selected pools and autoselect status
@@ -4654,10 +5074,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
4654
5074
  // Vault Methods (Base only)
4655
5075
  // ============================================
4656
5076
  /**
4657
- * Deposit assets into the Zyfai Vault
4658
- * Currently only supports USDC on Base chain
5077
+ * Deposit assets into the Zyfai Vault (USDC on Base by default).
5078
+ *
5079
+ * @group Vault
4659
5080
  *
4660
- * @param amount - Amount to deposit (in human readable format, e.g., "100" for 100 USDC)
5081
+ * @remarks On-chain vault flow via connected wallet. Requires {@link ZyfaiSDK.connectAccount}.
5082
+ *
5083
+ * @param amount - Human-readable amount (e.g. `"100"` USDC)
4661
5084
  * @param asset - Asset to deposit (default: "USDC")
4662
5085
  * @returns Deposit transaction result
4663
5086
  *
@@ -5006,9 +5429,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
5006
5429
  * Events: depeg, liquidity_trap, liquidity_restored, pool_status_change,
5007
5430
  * new_collateral_detected, liquidity_drop.
5008
5431
  *
5009
- * @param handlers - Callback per event type, plus onError
5010
- * @param filters - Optional protocol/pool filter sent to the server on subscribe
5011
- * @returns Cleanup function — call it to close the connection
5432
+ * @group Realtime events
5433
+ *
5434
+ * @remarks Connects to defi-api WebSocket (`WS_ENDPOINT`). Auto-reconnects every 3s until
5435
+ * the returned cleanup function is called.
5436
+ *
5437
+ * @param handlers - {@link ZyfaiEventHandlers}
5438
+ * @param filters - Optional {@link ZyfaiEventFilters} sent on subscribe
5439
+ * @returns Cleanup function — call it to close the connection and stop reconnecting
5012
5440
  *
5013
5441
  * @example
5014
5442
  * ```typescript