@zyfai/sdk 0.2.56 → 0.3.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.d.ts CHANGED
@@ -5,9 +5,14 @@ import { Chain, PublicClient, Address as Address$1 } from 'viem';
5
5
  */
6
6
  type Address = `0x${string}`;
7
7
  type Hex = `0x${string}`;
8
- type Strategy = "conservative" | "aggressive";
8
+ /**
9
+ * Public strategy names.
10
+ * `yieldmaxxing` unlocks protocols with asynchronous (delayed) withdrawals —
11
+ * see `PortfolioDetailed.pendingAsyncWithdrawals`.
12
+ */
13
+ type Strategy = "conservative" | "aggressive" | "yieldmaxxing";
9
14
  /** Public asset symbols supported by the SDK */
10
- type SupportedAsset = "USDC" | "WETH" | "EURC";
15
+ type SupportedAsset = "USDC" | "WETH" | "EURC" | "NVDAc";
11
16
  interface RpcUrlsConfig {
12
17
  1?: string;
13
18
  8453?: string;
@@ -17,6 +22,12 @@ interface SDKConfig {
17
22
  apiKey: string;
18
23
  rpcUrls?: RpcUrlsConfig;
19
24
  referralSource?: string;
25
+ /** @internal Local integration tests only — not part of the public SDK contract. */
26
+ executionApiUrl?: string;
27
+ /** @internal Local integration tests only — not part of the public SDK contract. */
28
+ dataApiUrl?: string;
29
+ /** @internal Override client-side minimum portfolio checks (local integration). */
30
+ bypassMinPortfolio?: boolean;
20
31
  }
21
32
  interface DeploySafeResponse {
22
33
  success: boolean;
@@ -121,6 +132,7 @@ interface staleBalances {
121
132
  tokenSymbol: string;
122
133
  balance: string;
123
134
  isPending: boolean;
135
+ updatedAt?: string;
124
136
  }
125
137
  interface Portfolio {
126
138
  user?: string;
@@ -128,6 +140,9 @@ interface Portfolio {
128
140
  chains?: number[];
129
141
  strategy?: string;
130
142
  smartWallet?: Address;
143
+ hasBalance?: boolean;
144
+ predeployed?: boolean;
145
+ ownershipTransferred?: boolean;
131
146
  positions?: PositionSlot[];
132
147
  hasActiveSessionKey?: boolean;
133
148
  newSessionKeyAvailable?: boolean;
@@ -148,11 +163,87 @@ interface PortfolioAssetBalance {
148
163
  }
149
164
  type PortfolioByAssetType = Record<string, PortfolioAssetBalance>;
150
165
  type PortfolioByChain = Record<string, PortfolioByAssetType>;
166
+ /**
167
+ * Lifecycle of an asynchronous (delayed) withdrawal.
168
+ * - `REQUESTED`: redemption asked, protocol has not released the funds yet
169
+ * - `CLAIMABLE`: protocol released the funds, claim transaction is queued
170
+ * - `CLAIMED`: funds are back in the Safe (or forwarded to the EOA)
171
+ * - `FAILED`: not claimable past `estimatedClaimAt`; the position is restored
172
+ * and the request is retried on the next cycle
173
+ */
174
+ type AsyncWithdrawalStatus = "REQUESTED" | "CLAIMABLE" | "CLAIMED" | "FAILED";
175
+ /**
176
+ * A redemption in flight on a protocol with a delayed withdrawal
177
+ * (Ipor, Superform). Funds are neither in `positions` nor in the Safe
178
+ * balance while the request is `REQUESTED` or `CLAIMABLE`.
179
+ */
180
+ interface AsyncWithdrawal {
181
+ id: string;
182
+ status: AsyncWithdrawalStatus;
183
+ chainId: number;
184
+ /** Pool / vault identifier, e.g. "NVDAC". */
185
+ pool: string;
186
+ /**
187
+ * Redeemed amount in the token's least units, hex-encoded like every other
188
+ * balance in the payload (e.g. `"0x98967f"`). Read it with `BigInt`, then
189
+ * apply `token.decimals`.
190
+ */
191
+ amount: string;
192
+ token?: {
193
+ id?: string;
194
+ name?: string;
195
+ symbol?: string;
196
+ decimals?: number;
197
+ address?: string;
198
+ chainId?: number;
199
+ icon?: string;
200
+ };
201
+ protocol?: {
202
+ id?: string;
203
+ name?: string;
204
+ imageUrl?: string;
205
+ icon?: string;
206
+ metadata?: {
207
+ /** Nominal redemption delay advertised by the protocol, in days. */
208
+ asyncWithdrawalDays?: number;
209
+ };
210
+ };
211
+ /**
212
+ * `"user_eoa"` when the user initiated the withdrawal (claimed funds go to
213
+ * the EOA); absent when the rebalancer did (funds get redeployed).
214
+ */
215
+ withdrawalTarget?: string | null;
216
+ /** ISO timestamp when the protocol is expected to allow claiming. */
217
+ estimatedClaimAt?: string | null;
218
+ /** ISO timestamp of the successful claim (`CLAIMED` only). */
219
+ claimedAt?: string | null;
220
+ requestTxHash?: string | null;
221
+ claimTxHash?: string | null;
222
+ /** Failed claim attempts so far — the cron retries until `estimatedClaimAt`. */
223
+ retryCount?: number;
224
+ /** User-facing copy when the protocol temporarily refuses claims. */
225
+ statusMessage?: string | null;
226
+ createdAt?: string;
227
+ updatedAt?: string;
228
+ }
151
229
  interface PortfolioDetailed {
152
230
  hasBalance?: boolean;
153
- staleBalances?: string[];
231
+ /** Idle Safe balances above the rebalance threshold, across all chains. */
232
+ staleBalances?: staleBalances[];
154
233
  hasActiveSessionKey?: boolean;
155
234
  positions?: PositionSlot[];
235
+ /**
236
+ * Redemptions in flight: `REQUESTED` and `CLAIMABLE`, plus `CLAIMED` from
237
+ * the last 24 hours. Only the first two hold funds that are missing from
238
+ * `portfolioByAssetType` — see the total-balance note on `getPortfolio`.
239
+ */
240
+ pendingAsyncWithdrawals?: AsyncWithdrawal[];
241
+ /**
242
+ * Per-token copy explaining a temporary protocol pause (e.g. tokenized
243
+ * stocks over the weekend), keyed by token symbol.
244
+ */
245
+ pauseMessageByToken?: Record<string, string>;
246
+ /** Positions + idle Safe balances, summed per asset type. */
156
247
  portfolioByAssetType?: PortfolioByAssetType;
157
248
  portfolioByChain?: PortfolioByChain;
158
249
  }
@@ -381,13 +472,13 @@ interface Opportunity {
381
472
  tvl?: number;
382
473
  asset?: string;
383
474
  risk?: string;
384
- strategyType: "conservative" | "aggressive";
475
+ strategyType: Strategy;
385
476
  status?: string;
386
477
  }
387
478
  interface OpportunitiesResponse {
388
479
  success: boolean;
389
480
  chainId?: number;
390
- strategyType: "conservative" | "aggressive";
481
+ strategyType: Strategy;
391
482
  data: Opportunity[];
392
483
  }
393
484
  interface ApyPosition {
@@ -435,10 +526,24 @@ interface DepositResponse {
435
526
  txHash: string;
436
527
  smartWallet: string;
437
528
  amount: string;
529
+ /** Current lifecycle state; high-level methods return pending after their normal completion window. */
530
+ registration: DepositLifecycleResponse;
531
+ }
532
+ type DepositLifecycleStatus = "handover_pending" | "credited" | "recovered_to_eoa";
533
+ interface DepositLifecycleResponse {
534
+ id: string;
535
+ status: DepositLifecycleStatus;
536
+ balanceCredited: boolean;
537
+ statusUrl: string;
438
538
  }
439
539
  interface LogDepositResponse {
440
540
  success: boolean;
441
541
  message: string;
542
+ deposit: DepositLifecycleResponse;
543
+ }
544
+ interface WaitForDepositCreditOptions {
545
+ intervalMs?: number;
546
+ timeoutMs?: number;
442
547
  }
443
548
  interface WithdrawResponse {
444
549
  success: boolean;
@@ -481,7 +586,7 @@ interface SimulateBestPositionsParams {
481
586
  amount: number;
482
587
  token: string;
483
588
  networks: number | number[];
484
- strategy: "conservative" | "aggressive";
589
+ strategy: Strategy;
485
590
  minSplit?: number;
486
591
  protocols?: string[];
487
592
  pools?: string[];
@@ -760,10 +865,12 @@ declare class ZyfaiSDK {
760
865
  private rpcUrls?;
761
866
  private referralSource?;
762
867
  /**
763
- * Warn that a legacy method is deprecated in favor of depositFunds.
868
+ * Warn that a legacy method is deprecated in favor of sendDeposit.
764
869
  * Predeployed wallets no longer require deploySafe / createSessionKey.
765
870
  */
766
871
  private warnDeprecatedOnboardingMethod;
872
+ private readonly executionApiUrl;
873
+ private readonly bypassMinPortfolio;
767
874
  constructor(config: SDKConfig | string);
768
875
  /**
769
876
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
@@ -968,20 +1075,21 @@ declare class ZyfaiSDK {
968
1075
  /**
969
1076
  * Deploy Safe Smart Wallet for a user
970
1077
  *
971
- * @deprecated Prefer `depositFunds()`. Predeployed Safes and session keys are
1078
+ * @deprecated Prefer `sendDeposit()`. Predeployed Safes and session keys are
972
1079
  * managed automatically on first deposit. This method remains available for
973
1080
  * legacy flows.
974
1081
  *
975
1082
  * @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
976
1083
  * @param chainId - Target chain ID
977
- * @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
1084
+ * @param strategy - Optional strategy selection: "conservative" (default), "aggressive" or "yieldmaxxing"
978
1085
  * @param createSessionKey - If true, automatically creates a session key after deployment (default: false)
979
1086
  * @returns Deployment response with Safe address and transaction hash
980
1087
  *
981
1088
  * @example
982
1089
  * ```typescript
983
- * // Preferred: depositFunds handles predeployed wallet onboarding
984
- * await sdk.depositFunds(userAddress, 8453, amount, "USDC");
1090
+ * // Preferred: sendDeposit handles predeployed wallet onboarding
1091
+ * const sent = await sdk.sendDeposit(userAddress, 8453, amount, "USDC");
1092
+ * await sdk.waitForDepositCredit(sent.registration.id, 8453);
985
1093
  *
986
1094
  * // Legacy: deploy with default conservative strategy
987
1095
  * await sdk.deploySafe(userAddress, 8453);
@@ -992,7 +1100,7 @@ declare class ZyfaiSDK {
992
1100
  * Create session key with auto-fetched configuration from Zyfai API
993
1101
  * This is the simplified method that automatically fetches session configuration
994
1102
  *
995
- * @deprecated Prefer `depositFunds()`. Predeployed wallets already have the
1103
+ * @deprecated Prefer `sendDeposit()`. Predeployed wallets already have the
996
1104
  * agent session enabled; session activation is handled after first deposit.
997
1105
  * This method remains available for legacy flows.
998
1106
  *
@@ -1002,8 +1110,9 @@ declare class ZyfaiSDK {
1002
1110
  *
1003
1111
  * @example
1004
1112
  * ```typescript
1005
- * // Preferred: depositFunds handles session onboarding for predeployed wallets
1006
- * await sdk.depositFunds(userAddress, 8453, amount, "USDC");
1113
+ * // Preferred: sendDeposit handles session onboarding for predeployed wallets
1114
+ * const sent = await sdk.sendDeposit(userAddress, 8453, amount, "USDC");
1115
+ * await sdk.waitForDepositCredit(sent.registration.id, 8453);
1007
1116
  *
1008
1117
  * // Legacy:
1009
1118
  * const result = await sdk.createSessionKey(userAddress, 8453);
@@ -1026,7 +1135,7 @@ declare class ZyfaiSDK {
1026
1135
  * asset/chain/strategy combo.
1027
1136
  * 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
1028
1137
  *
1029
- * Called from `deploySafe` after every path, and from `depositFunds` on
1138
+ * Called from `deploySafe` after every path, and from `sendDeposit` on
1030
1139
  * the account's first deposit (when USDC chains are still empty).
1031
1140
  *
1032
1141
  * @internal
@@ -1037,11 +1146,51 @@ declare class ZyfaiSDK {
1037
1146
  * @internal
1038
1147
  */
1039
1148
  private updateUserProtocolsForAsset;
1149
+ /**
1150
+ * Switch one asset to a strategy and select the protocols that go with it.
1151
+ *
1152
+ * `updateUserProfile` stores a strategy but does not compute a protocol
1153
+ * list, so on its own it leaves the asset with nothing to deploy into. This
1154
+ * method does both in one call: it resolves the protocols that support the
1155
+ * asset on the requested chains under the requested strategy, drops those
1156
+ * with no pool available, and persists strategy, chains and protocols
1157
+ * together.
1158
+ *
1159
+ * Mostly needed for assets that are not set up by the account's first
1160
+ * deposit, or to change an existing account's strategy — `sendDeposit`
1161
+ * ignores its `strategy` argument after the first deposit.
1162
+ *
1163
+ * @param params.asset - Asset to configure
1164
+ * @param params.strategy - Strategy to apply; defaults to the one already
1165
+ * stored for this asset (`"conservative"` on a fresh account), which lets
1166
+ * you recompute a protocol list without changing the strategy
1167
+ * @param params.chains - Chains to enable. Defaults to every chain the asset
1168
+ * exists on. **Additive**: chains already enabled are kept, so this cannot
1169
+ * be used to disable one.
1170
+ * @returns The updated profile for that asset
1171
+ *
1172
+ * @example
1173
+ * ```typescript
1174
+ * // NVDAc only lives in async protocols, so it needs "yieldmaxxing".
1175
+ * // Chains default to Base, the only chain it exists on.
1176
+ * const profile = await sdk.setAssetStrategy({
1177
+ * asset: "NVDAc",
1178
+ * strategy: "yieldmaxxing",
1179
+ * });
1180
+ * console.log(profile.protocols); // Ipor + Superform
1181
+ * ```
1182
+ */
1183
+ setAssetStrategy(params: {
1184
+ asset: SupportedAsset;
1185
+ strategy?: Strategy;
1186
+ chains?: SupportedChainId[];
1187
+ }): Promise<UpdateUserProfileResponse>;
1040
1188
  /**
1041
1189
  * Drop protocols that have no pools on any of the selected chains for the
1042
- * requested asset. Uses the /customization/pools endpoint with
1043
- * `degen_strategy` as the master strategy so the response includes both
1044
- * safe and degen pools — mirrors the front-end behavior.
1190
+ * requested asset. The /customization/pools endpoint filters server-side on
1191
+ * the strategy, and each tier is a superset of the previous one, so the
1192
+ * caller's strategy must be passed through — asking for `degen_strategy`
1193
+ * returns an empty pool set for async-only assets.
1045
1194
  * @internal
1046
1195
  */
1047
1196
  private filterProtocolIdsWithPools;
@@ -1053,47 +1202,6 @@ declare class ZyfaiSDK {
1053
1202
  * Convert session nonces from bigint[] to number[]
1054
1203
  */
1055
1204
  private normalizeSessionNonces;
1056
- /**
1057
- * Deposit funds from EOA to Safe smart wallet
1058
- * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
1059
- *
1060
- * Token address is selected from `asset` for the given chain:
1061
- * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161): USDC or WETH
1062
- * - Ethereum Mainnet (1), Base (8453): EURC
1063
- *
1064
- * On the account's first deposit (USDC profile has no chains yet), patches
1065
- * protocol selection for USDC, WETH, and EURC across all supported chains
1066
- * (EURC on Mainnet/Base only) before the transfer and log_deposit.
1067
- * Pass `strategy` to select protocols for that first-deposit setup
1068
- * (same role as the former `deploySafe` strategy argument).
1069
- *
1070
- * Minimum portfolio balance enforced (Safe balance + deposit amount):
1071
- * - Stablecoins: `MIN_PORTFOLIO_BALANCE` (Mainnet 10,000 USDC/EURC; Base/Arbitrum 100)
1072
- * - WETH: about $10,000 on Mainnet, $100 on Base/Arbitrum, from Data API `/price?token=eth`
1073
- *
1074
- * @param userAddress - User's address (owner of the Safe)
1075
- * @param chainId - Target chain ID
1076
- * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1077
- * @param asset - Asset symbol: "USDC", "WETH", or "EURC".
1078
- * EURC is supported on Ethereum Mainnet and Base only.
1079
- * @param strategy - Optional strategy for first-deposit protocol patching:
1080
- * "conservative" (default) or "aggressive"
1081
- * @returns Deposit response with transaction hash
1082
- *
1083
- * @example
1084
- * ```typescript
1085
- * // Deposit 10,000 USDC (6 decimals) to Safe on Base
1086
- * const result = await sdk.depositFunds(
1087
- * "0xUser...",
1088
- * 8453,
1089
- * "10000000000",
1090
- * "USDC"
1091
- * );
1092
- *
1093
- * // First deposit with aggressive strategy
1094
- * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
1095
- * ```
1096
- */
1097
1205
  /**
1098
1206
  * Deploy the connected predeployed (pool) wallet on one or more chains.
1099
1207
  *
@@ -1104,7 +1212,7 @@ declare class ZyfaiSDK {
1104
1212
  * resolves once all requested chains have landed on-chain. Idempotent — chains
1105
1213
  * already deployed are a no-op.
1106
1214
  *
1107
- * Optional for deposits: `depositFunds` no longer pre-deploys the target chain — the ERC20
1215
+ * Optional for deposits: `sendDeposit` no longer pre-deploys the target chain — the ERC20
1108
1216
  * transfer lands on the counterfactual address and the backend deploys + hands over on first
1109
1217
  * deposit (report-deposit). Use this only to pre-provision chains ahead of time.
1110
1218
  *
@@ -1116,16 +1224,67 @@ declare class ZyfaiSDK {
1116
1224
  chains: number[];
1117
1225
  status: string;
1118
1226
  }>;
1227
+ /**
1228
+ * Send a deposit from an EOA to its Safe smart wallet.
1229
+ *
1230
+ * Confirms the ERC-20 transfer and starts the custody-credit lifecycle. Use
1231
+ * `waitForDepositCredit(result.registration.id, chainId)` to await credit.
1232
+ */
1233
+ sendDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1234
+ /**
1235
+ * @deprecated Compatibility convenience method. Prefer `sendDeposit()` followed by
1236
+ * `waitForDepositCredit()` when the caller owns the completion UX.
1237
+ */
1119
1238
  depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1239
+ /**
1240
+ * Prepare ERC-20 transfer calldata for builders using a custom signer,
1241
+ * sponsored transaction provider, or mobile wallet. Most custom-wallet
1242
+ * integrations can compose this with `ensureFirstDepositSetup()` and
1243
+ * `logDeposit()` instead.
1244
+ */
1245
+ buildDepositTransfer(params: {
1246
+ userAddress: string;
1247
+ chainId: SupportedChainId;
1248
+ amount: string;
1249
+ asset: SupportedAsset;
1250
+ }): Promise<{
1251
+ safeAddress: Address;
1252
+ tokenAddress: Address;
1253
+ to: Address;
1254
+ data: Hex;
1255
+ value: "0";
1256
+ }>;
1257
+ /** Apply the same per-asset minimum portfolio rule as sendDeposit. */
1258
+ private enforceMinimumPortfolioBalance;
1259
+ /**
1260
+ * Idempotently apply the first-deposit profile configuration for builders
1261
+ * composing an advanced custom transfer flow. Most custom-wallet
1262
+ * integrations can use this with `buildDepositTransfer()` and `logDeposit()`.
1263
+ *
1264
+ * When setup runs (`applied: true`), protocol configuration is persisted
1265
+ * before returning. Failures throw so callers can abort before submitting a
1266
+ * transfer. High-level deposit methods still treat setup as best-effort.
1267
+ */
1268
+ ensureFirstDepositSetup(strategy?: Strategy): Promise<{
1269
+ applied: boolean;
1270
+ }>;
1271
+ /** Best-effort first-deposit setup shared by both high-level deposit flows. */
1272
+ private prepareFirstDeposit;
1273
+ /** Shared post-transfer registration path for every deposit flow. */
1274
+ private registerDeposit;
1120
1275
  /**
1121
1276
  * Log a deposit that was executed client-side.
1122
1277
  *
1123
- * `depositFunds()` already calls this after the ERC20 transfer. If you send the
1278
+ * `sendDeposit()` already calls this after the ERC20 transfer. If you send the
1124
1279
  * transfer yourself (front, Privy, Biconomy, custom wallet) you **must** call
1125
1280
  * `logDeposit` — otherwise the backend never sees the deposit: a reserved pool
1126
1281
  * wallet stays reserved (no ownership rotation), and yield/agent tracking does
1127
1282
  * not start.
1128
1283
  *
1284
+ * Requires `connectAccount()` on the same SDK instance first (SIWE user JWT).
1285
+ * The SDK API key alone is not enough — `log_deposit` returns 401 without a
1286
+ * Bearer token.
1287
+ *
1129
1288
  * Use this method when you execute the deposit transaction yourself and need to
1130
1289
  * register it with the Zyfai backend.
1131
1290
  *
@@ -1161,12 +1320,57 @@ declare class ZyfaiSDK {
1161
1320
  * ```
1162
1321
  */
1163
1322
  logDeposit(chainId: SupportedChainId, txHash: string, amount: string, tokenAddress?: string): Promise<LogDepositResponse>;
1323
+ /**
1324
+ * Fetch the custody handover and balance-credit lifecycle for a registered
1325
+ * deposit. A status of `credited` is required before funds are investable.
1326
+ */
1327
+ getDepositStatus(depositId: string): Promise<DepositLifecycleResponse>;
1328
+ /**
1329
+ * Await deposit credit after `logDeposit` returns `handover_pending`.
1330
+ *
1331
+ * Polls `getDepositStatus` until `status === "credited"` and
1332
+ * `balanceCredited === true`. Rejects on recovery, timeout, or poll errors.
1333
+ *
1334
+ * Poll interval and timeout are chain-specific. Mainnet defaults to a 2s
1335
+ * interval and 1 minute ceiling; Base/Arbitrum use tighter polling (~500ms /
1336
+ * ~250ms) with a ~20 second completion window. Override `timeoutMs` when a
1337
+ * caller intentionally wants to wait longer than the normal UX window.
1338
+ *
1339
+ * Requires `connectAccount()` on the same SDK instance first.
1340
+ */
1341
+ waitForDepositCredit(depositId: string, chainId: SupportedChainId, options?: WaitForDepositCreditOptions): Promise<DepositLifecycleResponse>;
1164
1342
  /**
1165
1343
  * Withdraw funds from Safe smart wallet
1166
1344
  * Initiates a withdrawal request to the Zyfai API
1167
1345
  * Note: The withdrawal is processed asynchronously, so txHash may not be immediately available
1168
1346
  * Funds are always withdrawn to the Safe owner's address (userAddress)
1169
1347
  *
1348
+ * **Delayed withdrawals.** Positions held under the `"yieldmaxxing"`
1349
+ * strategy sit in protocols that cannot be exited on demand. For those the
1350
+ * backend transfers the immediately available portion, then queues a
1351
+ * redemption for the rest and forwards the funds to the EOA once the
1352
+ * protocol releases them — about a day on Ipor, three on Superform. No
1353
+ * further call is needed, but the returned `txHash` only covers the
1354
+ * immediate portion. Track the remainder through
1355
+ * `getPortfolio().portfolio.pendingAsyncWithdrawals`, whose entries carry a
1356
+ * `status` and an `estimatedClaimAt`.
1357
+ *
1358
+ * When every source is an async pool nothing settles on-chain at that point,
1359
+ * so `txHash` is `undefined` on a successful call.
1360
+ *
1361
+ * **One redemption per pool at a time.** While an entry for a pool is
1362
+ * `REQUESTED` or `CLAIMABLE`, the backend drops a further withdrawal aimed at
1363
+ * that same pool — the protocols behind it (ERC-7540) hold a single request
1364
+ * slot per user. This method throws rather than reporting that no-op as a
1365
+ * success. It only throws when nothing the call could reach is withdrawable:
1366
+ * another pool, another asset or an idle Safe balance still goes through.
1367
+ *
1368
+ * Once requested, that amount can no longer be withdrawn: it is gone from
1369
+ * both the position snapshot and the Safe balance, so a second call silently
1370
+ * returns only what is left. Validate user-entered amounts against
1371
+ * `portfolioByAssetType`, not against the total that includes in-flight
1372
+ * funds — see `getPortfolio`.
1373
+ *
1170
1374
  * @param userAddress - User's address (owner of the Safe)
1171
1375
  * @param chainId - Target chain ID
1172
1376
  * @param amount - Optional: Amount in least decimal units to withdraw (partial withdrawal). If not specified, withdraws all funds
@@ -1187,6 +1391,14 @@ declare class ZyfaiSDK {
1187
1391
  * ```
1188
1392
  */
1189
1393
  withdrawFunds(userAddress: string, chainId: SupportedChainId, amount?: string, tokenSymbol?: string): Promise<WithdrawResponse>;
1394
+ /**
1395
+ * Turn a withdrawal the backend would silently drop — one aimed only at
1396
+ * async pools that already hold an in-flight redemption — into an error, so
1397
+ * the caller gets an answer rather than a `success: true` no-op.
1398
+ *
1399
+ * @internal
1400
+ */
1401
+ private assertAsyncRedemptionSlotFree;
1190
1402
  /**
1191
1403
  * Get available DeFi protocols and pools for a specific chain
1192
1404
  *
@@ -1231,6 +1443,29 @@ declare class ZyfaiSDK {
1231
1443
  * Note: portfolio balances are live; earnings used for the fee may be from
1232
1444
  * a snapshot, so net values can differ slightly from a fully live calc.
1233
1445
  *
1446
+ * **Total balance.** `portfolioByAssetType` sums deployed positions and idle
1447
+ * Safe balances, and nothing else. Under the `"yieldmaxxing"` strategy a
1448
+ * redemption in flight has already left its position and has not landed in
1449
+ * the Safe yet, so its funds appear in no balance field at all. That makes
1450
+ * two distinct numbers:
1451
+ *
1452
+ * ```
1453
+ * total = portfolioByAssetType[assetType].balance
1454
+ * + sum(pendingAsyncWithdrawals where REQUESTED or CLAIMABLE)
1455
+ *
1456
+ * requestable = portfolioByAssetType[assetType].balance
1457
+ * ```
1458
+ *
1459
+ * An in-flight amount is no longer withdrawable: `withdrawFunds` only reaches
1460
+ * the current positions and idle balances, so calling it again neither speeds
1461
+ * those funds up nor errors. They reach the EOA on their own. Cap any
1462
+ * user-entered withdrawal amount at `requestable`, never at `total`.
1463
+ *
1464
+ * Do not add `staleBalances` on top — those are the same idle balances
1465
+ * `portfolioByAssetType` already counts, exposed as a per-chain view.
1466
+ * Do not add `CLAIMED` withdrawals either (the array keeps them for 24
1467
+ * hours); their funds are back in the Safe and already counted.
1468
+ *
1234
1469
  * @param userAddress - User's EOA address
1235
1470
  * @returns Portfolio with optional fee-adjusted balance fields
1236
1471
  *
@@ -1238,6 +1473,11 @@ declare class ZyfaiSDK {
1238
1473
  * ```typescript
1239
1474
  * const { portfolio } = await sdk.getPortfolio(userAddress);
1240
1475
  * console.log(portfolio.portfolioByAssetType?.usdc?.balanceWithFee);
1476
+ *
1477
+ * // Funds still locked in an async redemption
1478
+ * const inFlight = (portfolio.pendingAsyncWithdrawals ?? []).filter(
1479
+ * (w) => w.status === "REQUESTED" || w.status === "CLAIMABLE"
1480
+ * );
1241
1481
  * ```
1242
1482
  */
1243
1483
  getPortfolio(userAddress: string): Promise<PortfolioDetailedResponse>;
@@ -1273,7 +1513,7 @@ declare class ZyfaiSDK {
1273
1513
  *
1274
1514
  * @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
1275
1515
  * @param days - Time period: 7, 14, or 30
1276
- * @param strategy - Strategy type: "conservative" (default) or "aggressive"
1516
+ * @param strategy - Strategy type: "conservative" (default), "aggressive" or "yieldmaxxing"
1277
1517
  * @param chainId - Optional chain ID filter
1278
1518
  * @param tokenSymbol - Optional token symbol filter (e.g. "USDC", "WETH", "WBTC")
1279
1519
  * @returns APY per strategy for a specific chain
@@ -1450,6 +1690,24 @@ declare class ZyfaiSDK {
1450
1690
  * ```
1451
1691
  */
1452
1692
  getAggressiveOpportunities(chainId?: number, asset?: string, status?: "live" | "not_live"): Promise<OpportunitiesResponse>;
1693
+ /**
1694
+ * Get yieldmaxxing opportunities — pools reachable only with the
1695
+ * `"yieldmaxxing"` strategy, including protocols whose withdrawals are
1696
+ * asynchronous (Ipor, Superform). Exiting these pools takes about a day
1697
+ * on Ipor and three on Superform; track the redemption through
1698
+ * `getPortfolio().portfolio.pendingAsyncWithdrawals`.
1699
+ *
1700
+ * @param chainId - Optional chain ID filter
1701
+ * @param asset - Optional asset filter (e.g. "USDC", "WETH")
1702
+ * @returns List of yieldmaxxing opportunities
1703
+ *
1704
+ * @example
1705
+ * ```typescript
1706
+ * const opportunities = await sdk.getAsyncOpportunities(8453);
1707
+ * opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
1708
+ * ```
1709
+ */
1710
+ getAsyncOpportunities(chainId?: number, asset?: string, status?: "live" | "not_live"): Promise<OpportunitiesResponse>;
1453
1711
  /**
1454
1712
  * Get active conservative opportunities (status = "live") with risk and utilization data
1455
1713
  * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
@@ -1606,7 +1864,7 @@ declare class ZyfaiSDK {
1606
1864
  * Returns the list of pools available for a given protocol, optionally filtered by strategy.
1607
1865
  *
1608
1866
  * @param protocolId - The protocol UUID
1609
- * @param strategy - Optional strategy filter ("conservative" or "aggressive")
1867
+ * @param strategy - Optional strategy filter ("conservative", "aggressive" or "yieldmaxxing")
1610
1868
  * @returns List of available pool names
1611
1869
  *
1612
1870
  * @example
@@ -1622,7 +1880,7 @@ declare class ZyfaiSDK {
1622
1880
  * );
1623
1881
  * ```
1624
1882
  */
1625
- getAvailablePools(protocolId: string, strategy?: "conservative" | "aggressive"): Promise<GetPoolsResponse>;
1883
+ getAvailablePools(protocolId: string, strategy?: Strategy): Promise<GetPoolsResponse>;
1626
1884
  /**
1627
1885
  * Simulate the best yield positions for a given amount, splitting it across
1628
1886
  * the top-ranked pools (up to minSplit positions) for the requested chains/strategy.
@@ -1858,6 +2116,50 @@ declare function createBankrProvider(config: BankrProviderConfig): {
1858
2116
  };
1859
2117
  type BankrProvider = ReturnType<typeof createBankrProvider>;
1860
2118
 
2119
+ /**
2120
+ * API Endpoints Configuration
2121
+ *
2122
+ * Base URLs are grouped by environment. Default exports always target production;
2123
+ * use the maps or named constants for staging/local stacks (integration tests,
2124
+ * examples, internal tooling).
2125
+ */
2126
+
2127
+ type BackendEnvironment = "production" | "staging" | "local";
2128
+ /** Execution API (zyfai-api) origin — no `/api/v1` suffix. */
2129
+ declare const EXECUTION_API_BASE_URLS: {
2130
+ readonly production: "https://api.zyf.ai";
2131
+ readonly staging: "https://staging-api.zyf.ai";
2132
+ readonly local: "http://localhost:3000";
2133
+ };
2134
+ /** Data API (zyfai-defi-api) origin — no `/api/v2` suffix. */
2135
+ declare const DATA_API_BASE_URLS: {
2136
+ readonly production: "https://defiapi.zyf.ai";
2137
+ readonly staging: "https://staging-defiapi.zyf.ai";
2138
+ /** Both backends default to port 3000 locally; run one at a time or override PORT. */
2139
+ readonly local: "http://localhost:3000";
2140
+ };
2141
+ /** Defi-api WebSocket URL (includes `/ws/events` path). */
2142
+ declare const WS_URLS: {
2143
+ readonly production: "wss://defiapi.zyf.ai/ws/events";
2144
+ readonly staging: "wss://staging-defiapi.zyf.ai/ws/events";
2145
+ readonly local: "ws://localhost:3000/ws/events";
2146
+ };
2147
+ /** Production execution API — default for the public SDK. */
2148
+ declare const API_ENDPOINT: "https://api.zyf.ai";
2149
+ /** Production data API — default for the public SDK. */
2150
+ declare const DATA_API_ENDPOINT: "https://defiapi.zyf.ai";
2151
+ /** Production defi-api WebSocket — default for the public SDK. */
2152
+ declare const WS_ENDPOINT: "wss://defiapi.zyf.ai/ws/events";
2153
+ declare const STAGING_EXECUTION_API_BASE_URL: "https://staging-api.zyf.ai";
2154
+ declare const STAGING_DATA_API_BASE_URL: "https://staging-defiapi.zyf.ai";
2155
+ declare const STAGING_WS_URL: "wss://staging-defiapi.zyf.ai/ws/events";
2156
+ declare const LOCAL_EXECUTION_API_BASE_URL: "http://localhost:3000";
2157
+ declare const LOCAL_DATA_API_BASE_URL: "http://localhost:3000";
2158
+ declare const LOCAL_WS_URL: "ws://localhost:3000/ws/events";
2159
+ declare function getExecutionApiBaseUrl(environment?: BackendEnvironment): string;
2160
+ declare function getDataApiBaseUrl(environment?: BackendEnvironment): string;
2161
+ declare function getWsUrl(environment?: BackendEnvironment): string;
2162
+
1861
2163
  declare const VAULT_ADDRESS: "0xD580071c47d4a667858B5FafAb85BC9C609beC5D";
1862
2164
 
1863
2165
  /**
@@ -1904,4 +2206,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
1904
2206
  */
1905
2207
  declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
1906
2208
 
1907
- export { ALLOWED_HISTORY_DAYS, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryFeeData, type HistoryPosition, type HistoryRebalanceLog, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
2209
+ export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type AsyncWithdrawal, type AsyncWithdrawalStatus, type BackendEnvironment, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DATA_API_BASE_URLS, DATA_API_ENDPOINT, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryFeeData, type HistoryPosition, type HistoryRebalanceLog, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, LOCAL_DATA_API_BASE_URL, LOCAL_EXECUTION_API_BASE_URL, LOCAL_WS_URL, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, STAGING_DATA_API_BASE_URL, STAGING_EXECUTION_API_BASE_URL, STAGING_WS_URL, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, WS_ENDPOINT, WS_URLS, type WaitForDepositCreditOptions, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getSupportedChainIds, getWsUrl, isSupportedChain, type staleBalances };