@zyfai/sdk 0.9.0 → 0.11.2

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/README.md CHANGED
@@ -421,12 +421,13 @@ Transfer tokens to your Safe smart wallet. Token address is automatically select
421
421
 
422
422
  - **Ethereum Mainnet (1), Base (8453), Arbitrum (42161)**: USDC (default) or WETH
423
423
  - **Ethereum Mainnet (1), Base (8453)**: EURC (6 decimals; not available on Arbitrum)
424
+ - **Ethereum Mainnet (1) only**: USDT and PYUSD (6 decimals)
424
425
  - **Base (8453) only**: NVDAc (8 decimals) — tokenized NVIDIA equity, see [Tokenized equities](#tokenized-equities-nvdac)
425
426
 
426
427
  **Minimum portfolio balance (enforced on Safe balance + deposit amount):**
427
428
 
428
- - Ethereum Mainnet (1) / USDC or EURC: 10,000 units
429
- - Base (8453) and Arbitrum (42161) / USDC or EURC: 10 units
429
+ - Ethereum Mainnet (1) / USDC, EURC, USDT, or PYUSD: 10,000 units
430
+ - Base (8453) and Arbitrum (42161) / USDC or EURC: 10 units (EURC is not on Arbitrum)
430
431
  - WETH: about **$10,000** of ETH on Ethereum Mainnet, **$10** on Base and Arbitrum
431
432
  - NVDAc: about **$10** on Base
432
433
 
@@ -465,13 +466,27 @@ if (credited.status === "credited") {
465
466
  **Note:**
466
467
 
467
468
  - Amount must be in least decimal units. For USDC (6 decimals): 1 USDC = 1000000
468
- - `asset` is required (`"USDC"`, `"WETH"`, `"EURC"`, or `"NVDAc"` — EURC on Mainnet/Base only, NVDAc on Base only); token address is selected from that for the chain. Depositing an asset on a chain where it does not exist throws before any transfer.
469
+ - `asset` is required (`"USDC"`, `"WETH"`, `"EURC"`, `"USDT"`, `"PYUSD"`, or `"NVDAc"` — EURC on Mainnet/Base, USDT and PYUSD on Mainnet, NVDAc on Base); token address is selected from that for the chain. Depositing an asset on a chain where it does not exist throws before any transfer.
469
470
  - The total Safe balance must meet the per-asset minimum after the deposit (see above). WETH uses a live ETH/USD price, so the wei threshold moves with the market.
470
471
  - Call `connectAccount()` on the **same** `ZyfaiSDK` instance before `sendDeposit()`. The method uses that session's JWT when it calls `log_deposit` after the transfer.
471
- - `sendDeposit()` confirms the ERC-20 transaction and registers its lifecycle, then returns its ID. Call `waitForDepositCredit()` only when the UI needs to wait for custody credit; otherwise track it later with `getDepositStatus()`.
472
+ - `sendDeposit(userAddress, chainId, amount, asset)` still transfers that collateral when the wallet already holds it. Pass an object with `spendToken` when the wallet holds a different token or the same token on another chain: the execution API quotes Relay, the wallet signs, and the Safe receives `asset`. Same-chain ETH into WETH wraps in the wallet (`spendToken: "ETH"`). `sendDirectDeposit` and `sendSwapDeposit` are the two steps `sendDeposit` chooses between. Optional `slippageBps` on a swap defaults to 200 (max 500) and is fixed when the funding order is created. Omit it to use the server default. A later `sendSwapDeposit({ orderId })` ignores a new `slippageBps` and signs the stored order.
473
+
474
+ ```typescript
475
+ const swapped = await sdk.sendDeposit({
476
+ userAddress,
477
+ chainId: 8453,
478
+ asset: "WETH",
479
+ amount: "10000000",
480
+ spendToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
481
+ spendChainId: 42161,
482
+ slippageBps: 200,
483
+ });
484
+ ```
485
+
486
+ - `sendDeposit()` confirms the transfer (or the Relay fill) and registers its lifecycle, then returns its ID. Call `waitForDepositPosition()` when the UI should wait until allocation finishes. `waitForDepositCredit()` is the shorter wait for credited balance only.
472
487
  - `depositFunds()` remains a compatibility wrapper that calls both steps and waits through the normal completion window; it **rejects** if credit is not confirmed in that window (track in-flight deposits with `getDepositStatus()` or call `waitForDepositCredit()` with a longer `timeoutMs`).
473
488
  - If first-deposit protocol patching fails, the transfer still runs. `sendDeposit()` throws if deposit registration is not accepted; retry `logDeposit()` after `connectAccount()`.
474
- - **First deposit only** (before transfer + `log_deposit`): if the USDC profile has no `chains` yet, the SDK patches protocols for **USDC, WETH, EURC, and NVDAc**, each across the chains it exists on (EURC on Mainnet/Base, NVDAc on Base → `assetTypeSettings.[usdc|eth|eurc|nvdac]`). Pass optional `strategy` (`"conservative"` default, `"aggressive"` or `"yieldmaxxing"`) — same role as the former `deploySafe` strategy argument. Later deposits skip this.
489
+ - **First deposit only** (before transfer + `log_deposit`): if the USDC profile has no `chains` yet, the SDK patches protocols for **USDC, WETH, EURC, USDT, PYUSD, and NVDAc**, each across the chains it exists on (EURC on Mainnet/Base, USDT and PYUSD on Mainnet, NVDAc on Base → `assetTypeSettings.[usdc|eth|eurc|usdt|pyusd|nvdac]`). Pass optional `strategy` (`"conservative"` default, `"aggressive"` or `"yieldmaxxing"`) — same role as the former `deploySafe` strategy argument. Later deposits skip this.
475
490
  - **`strategy` is ignored on later deposits, and no error is raised.** Re-running the patch would overwrite a protocol selection the user may have customised, so passing `"yieldmaxxing"` to an account that has already deposited leaves it on its current strategy. To change an existing account, use `setStrategyWithProtocols` or `setAssetStrategy` (not `updateUserProfile` alone):
476
491
 
477
492
  ```typescript
@@ -843,7 +858,7 @@ console.log("Active protocols:", userDetails.user.protocols.length); // Should b
843
858
 
844
859
  **Note**:
845
860
  - User must be authenticated (automatically done via `connectAccount()`)
846
- - Clears protocols for USDC, WETH, EURC, and NVDAc
861
+ - Clears protocols for USDC, WETH, EURC, USDT, PYUSD, and NVDAc
847
862
  - To resume operations, call `resumeAgent()` or `updateUserProfile()` with the desired protocols
848
863
 
849
864
  #### Splitting Management
@@ -1298,11 +1313,18 @@ main();
1298
1313
 
1299
1314
  ### Example 2: Browser Integration with React
1300
1315
 
1316
+ Demo only. Constructing the SDK in the page ships the API key in the bundle, so it is public. A native app binary can be unpacked the same way. In production, keep the key on your backend and proxy calls to Zyfai. The user still signs SIWE on the device.
1317
+
1318
+ The key alone cannot move funds: deposits and withdrawals need that user's SIWE session and their signature. It can call the data APIs on your quota, list the wallets onboarded under the key (and their TVL), and register extra wallets onto the key.
1319
+
1320
+ CORS applies only when a **browser** calls Zyfai directly. Send us the page origin to whitelist. An iOS or Android app, and a server-side proxy, do not send a browser `Origin` and do not need one.
1321
+
1301
1322
  ```typescript
1302
1323
  import { ZyfaiSDK } from "@zyfai/sdk";
1303
1324
  import { useState } from "react";
1304
1325
 
1305
1326
  function SafeDeployment() {
1327
+ // Demo only — this value ends up in the client bundle.
1306
1328
  const [sdk] = useState(() => new ZyfaiSDK(process.env.ZYFAI_API_KEY!));
1307
1329
 
1308
1330
  const [userAddress, setUserAddress] = useState<string>("");
@@ -1401,8 +1423,8 @@ try {
1401
1423
 
1402
1424
  ## Best Practices
1403
1425
 
1404
- 1. **Store API Keys Securely**: Never commit API keys to version control
1405
- 2. **Use Environment Variables**: Store keys in `.env` files
1426
+ 1. **Store API Keys Securely**: Never commit API keys to version control. Do not ship the key in a frontend bundle or a mobile binary; proxy from your backend. See the note on the React example above.
1427
+ 2. **Use Environment Variables**: Store keys in `.env` files on the server, not in a `NEXT_PUBLIC_` / client env var
1406
1428
  3. **Check Deployment Status**: Always check if Safe is already deployed before deploying
1407
1429
  4. **Handle Errors Gracefully**: Implement proper error handling for all SDK methods
1408
1430
  5. **Validate Chain IDs**: Ensure you're using supported chains (Ethereum Mainnet, Base, Arbitrum)
@@ -1461,7 +1483,7 @@ If `withdrawFunds` returns without a `txHash`, the withdrawal is being processed
1461
1483
 
1462
1484
  ### Data API CORS Errors
1463
1485
 
1464
- Some Data API endpoints may require server-side CORS configuration. If you see CORS errors for endpoints like `onchain-earnings`, `calculate-onchain-earnings`, or `opportunities`, contact Zyfai support to ensure your origin is whitelisted.
1486
+ CORS is enforced by the browser. A native app or a server-side proxy does not need an origin on the whitelist, and the proxy's own URL is not one. If a web page calls `api.zyf.ai` or `defiapi.zyf.ai` directly and you see CORS errors (for example on `onchain-earnings`, `calculate-onchain-earnings`, or `opportunities`), contact Zyfai support with the **page** origin, such as `https://app.example.com`.
1465
1487
 
1466
1488
  ## Integration testing
1467
1489
 
package/dist/index.d.mts CHANGED
@@ -3,6 +3,7 @@ import { Chain, PublicClient, Address as Address$1 } from 'viem';
3
3
  /**
4
4
  * Public TypeScript types for `@zyfai/sdk` request/response shapes and events.
5
5
  */
6
+
6
7
  /** Checksummed Ethereum address. */
7
8
  type Address = `0x${string}`;
8
9
  /** Hex-encoded byte string (e.g. signatures, calldata). */
@@ -615,19 +616,130 @@ interface DepositResponse {
615
616
  smartWallet: string;
616
617
  /** Deposited amount in least units (decimal string). */
617
618
  amount: string;
619
+ /**
620
+ * How the collateral reached the Safe.
621
+ * `direct` transfers the collateral itself. `swap` converts another token
622
+ * through Relay. `wrap` turns same-chain native ETH into WETH, then transfers it.
623
+ */
624
+ route?: "direct" | "swap" | "wrap";
625
+ /** Relay funding order id when `route` is `swap`. */
626
+ orderId?: string;
618
627
  /**
619
628
  * Deposit lifecycle record. After `sendDeposit`, status is usually
620
629
  * `handover_pending` until {@link ZyfaiSDK.waitForDepositCredit} completes.
621
630
  */
622
631
  registration: DepositLifecycleResponse;
623
632
  }
633
+ /**
634
+ * Spend a token that is not already the destination collateral.
635
+ * The execution API quotes Relay; the connected wallet signs the steps.
636
+ */
637
+ interface SwapDepositParams {
638
+ /** Funding wallet EOA. */
639
+ userAddress: string;
640
+ /** Chain the spent token is on. May differ from the deposit chain. */
641
+ originChainId: number;
642
+ /** Spent token contract. The zero address is native ETH. */
643
+ originCurrency: string;
644
+ /** Spend amount in the origin token's least units. */
645
+ originAmount: string;
646
+ /** Chain the collateral should arrive on. */
647
+ destinationChainId: SupportedChainId;
648
+ /**
649
+ * Collateral Relay should deliver (`USDC`, `WETH`, `EURC`, `cbBTC`, …).
650
+ * The server resolves the contract.
651
+ */
652
+ destinationAsset: string;
653
+ /** Optional first-deposit {@link Strategy}. */
654
+ strategy?: Strategy;
655
+ /**
656
+ * Max slippage tolerance in basis points (default 200; max 500).
657
+ * Stored on the funding order at quote time. Ignored when `orderId` is set;
658
+ * the stored order's value is used on sign.
659
+ */
660
+ slippageBps?: number;
661
+ /**
662
+ * Existing review quote to sign. Origin chain, origin token, destination
663
+ * chain, and destination asset must match that order. Omit to create a new
664
+ * funding order.
665
+ */
666
+ orderId?: string;
667
+ }
668
+ /** Review quote for a Relay swap deposit. The wallet has not signed yet. */
669
+ interface SwapDepositQuote {
670
+ orderId: string;
671
+ status: string;
672
+ spend: string;
673
+ expectedOutput: string;
674
+ minimumOutput: string;
675
+ destinationChainId: number;
676
+ destinationCurrency: string;
677
+ destinationAsset: string;
678
+ fees: {
679
+ name?: string;
680
+ amount?: string;
681
+ amountUsd?: string;
682
+ }[];
683
+ investEligible: boolean;
684
+ expiresAt: string | null;
685
+ timeEstimate?: number | null;
686
+ }
687
+ /** Stored Relay funding order, including any linked deposit lifecycle. */
688
+ interface SwapDepositOrder {
689
+ id: string;
690
+ status: string;
691
+ depositId: string | null;
692
+ sourceTxHashes: string[];
693
+ destinationTxHashes: string[];
694
+ /** Chain the spent token is on. */
695
+ originChainId: number;
696
+ /** Spent token contract stored with the order. */
697
+ originCurrency: string;
698
+ destinationChainId: number;
699
+ destinationCurrency: string;
700
+ destinationAsset: string;
701
+ minimumOutput: string | null;
702
+ providerStatus?: string | null;
703
+ lastError?: string | null;
704
+ }
705
+ /**
706
+ * `sendDeposit` input. Omit `spendToken` to transfer `asset` on `chainId`.
707
+ * Set `spendToken` when the wallet holds a different token or chain.
708
+ */
709
+ interface SendDepositParams {
710
+ userAddress: string;
711
+ /** Chain the collateral should arrive on. */
712
+ chainId: SupportedChainId;
713
+ /** Collateral that should land in the Safe. */
714
+ asset: string;
715
+ /**
716
+ * Least units of the token being spent.
717
+ * For a direct deposit this is the collateral amount.
718
+ */
719
+ amount: string;
720
+ strategy?: Strategy;
721
+ /**
722
+ * Token the wallet spends. A collateral symbol or its contract on `chainId`
723
+ * stays a direct deposit. Anything else is swapped into `asset`.
724
+ */
725
+ spendToken?: string;
726
+ /** Chain the spend token is on. Defaults to `chainId`. */
727
+ spendChainId?: number;
728
+ /**
729
+ * Max slippage tolerance in basis points when this call swaps (default 200;
730
+ * max 500). Ignored for a direct transfer or a same-chain ETH wrap.
731
+ * Fixed when the funding order is created.
732
+ */
733
+ slippageBps?: number;
734
+ }
624
735
  /**
625
736
  * Custody handover and balance-credit states for a registered deposit.
626
737
  *
627
738
  * @remarks
628
739
  * `credited` with `balanceCredited: true` means funds are investable.
629
740
  */
630
- type DepositLifecycleStatus = "handover_pending" | "credited" | "recovered_to_eoa";
741
+ type DepositLifecycleStatus = "handover_pending" | "credited" | "recovered_to_eoa" | "position_pending" | "positioned";
742
+ type DepositPositionOutcome = "pending" | "positioned" | "skipped" | "failed";
631
743
  /** Deposit registration and credit lifecycle (execution API). */
632
744
  interface DepositLifecycleResponse {
633
745
  /** Lifecycle id — pass to {@link ZyfaiSDK.getDepositStatus} / {@link ZyfaiSDK.waitForDepositCredit}. */
@@ -637,6 +749,32 @@ interface DepositLifecycleResponse {
637
749
  balanceCredited: boolean;
638
750
  /** Backend URL for status polling (informational). */
639
751
  statusUrl: string;
752
+ positionOutcome?: DepositPositionOutcome | null;
753
+ crosschain?: boolean;
754
+ executionTxHash?: string | null;
755
+ }
756
+ type WithdrawLifecycleStatus = "accepted" | "redeeming" | "transferring" | "async_requesting" | "async_cooldown" | "async_claiming" | "completed" | "failed";
757
+ interface WithdrawAsyncLeg {
758
+ id: string;
759
+ protocol: string;
760
+ pool: string;
761
+ status: string;
762
+ estimatedClaimAt?: string | null;
763
+ requestTxHash?: string | null;
764
+ claimTxHash?: string | null;
765
+ }
766
+ interface WithdrawLifecycleResponse {
767
+ id: string;
768
+ status: WithdrawLifecycleStatus;
769
+ chainId: number;
770
+ tokenSymbol?: string | null;
771
+ syncSettled: boolean;
772
+ syncTxHash?: string | null;
773
+ asyncLegs: WithdrawAsyncLeg[];
774
+ failedAsyncIds: string[];
775
+ lastError?: string | null;
776
+ statusUrl: string;
777
+ estimatedClaimAt?: string | null;
640
778
  }
641
779
  interface LogDepositResponse {
642
780
  success: boolean;
@@ -650,6 +788,22 @@ interface WaitForDepositCreditOptions {
650
788
  /** Maximum wait before throwing `DepositCreditTimeoutError`. */
651
789
  timeoutMs?: number;
652
790
  }
791
+ /** Polling overrides for {@link ZyfaiSDK.waitForDepositPosition}. */
792
+ interface WaitForDepositPositionOptions {
793
+ intervalMs?: number;
794
+ timeoutMs?: number;
795
+ }
796
+ /** Polling overrides for {@link ZyfaiSDK.waitForWithdrawSettlement}. */
797
+ interface WaitForWithdrawSettlementOptions {
798
+ intervalMs?: number;
799
+ timeoutMs?: number;
800
+ }
801
+ /** Polling overrides for {@link ZyfaiSDK.waitForWithdrawComplete}. */
802
+ interface WaitForWithdrawCompleteOptions {
803
+ intervalMs?: number;
804
+ timeoutMs?: number;
805
+ cooldownIntervalMs?: number;
806
+ }
653
807
  /** Polling overrides for {@link ZyfaiSDK.waitForAgentDepositIntent}. */
654
808
  interface WaitForAgentDepositIntentOptions {
655
809
  intervalMs?: number;
@@ -670,6 +824,8 @@ interface WithdrawResponse {
670
824
  type: "full" | "partial";
671
825
  /** Withdrawn amount in least units (decimal string). */
672
826
  amount: string;
827
+ /** Lifecycle id for {@link ZyfaiSDK.getWithdrawStatus} / withdraw poll helpers. */
828
+ lifecycle?: WithdrawLifecycleResponse;
673
829
  }
674
830
  interface AddWalletToSdkResponse {
675
831
  success: boolean;
@@ -996,20 +1152,6 @@ type DailyApyHistoryPeriod = `${AllowedHistoryDays}D`;
996
1152
  * Zyfai SDK Main Class
997
1153
  */
998
1154
 
999
- /**
1000
- * Client for Zyfai execution (`api.zyf.ai`) and intelligence (`defiapi.zyf.ai`) APIs.
1001
- *
1002
- * @remarks
1003
- * The connected wallet from {@link ZyfaiSDK.connectAccount} is used for **signing only**
1004
- * (SIWE, on-chain transfers). Pass the user's **EOA** as `userAddress` on execution
1005
- * methods; the backend resolves the assigned Safe.
1006
- *
1007
- * First-time onboarding uses predeployed Safes: {@link ZyfaiSDK.sendDeposit} handles
1008
- * session and deploy-on-first-deposit without {@link ZyfaiSDK.deploySafe} or
1009
- * {@link ZyfaiSDK.createSessionKey}.
1010
- *
1011
- * @see {@link https://docs.zyf.ai/docs/sdk/agent-quickstart | Agent quickstart}
1012
- */
1013
1155
  declare class ZyfaiSDK {
1014
1156
  private httpClient;
1015
1157
  private signer;
@@ -1536,14 +1678,14 @@ declare class ZyfaiSDK {
1536
1678
  status: string;
1537
1679
  }>;
1538
1680
  /**
1539
- * Transfer funds from the connected EOA to the user's Safe and register the deposit.
1681
+ * Transfer a collateral token the wallet already holds into the Safe.
1540
1682
  *
1541
1683
  * @remarks
1542
- * Execution API + on-chain ERC-20 `transfer`. Confirms the transaction, then calls
1543
- * {@link ZyfaiSDK.logDeposit}. Pair with {@link ZyfaiSDK.waitForDepositCredit} for
1544
- * investable balance. Custom-wallet flows: {@link ZyfaiSDK.buildDepositTransfer},
1545
- * {@link ZyfaiSDK.logDeposit}, {@link ZyfaiSDK.getDepositStatus}.
1684
+ * Use this when the connected wallet holds the strategy collateral on the
1685
+ * deposit chain. {@link ZyfaiSDK.sendDeposit} calls this automatically in
1686
+ * that case. A different token uses {@link ZyfaiSDK.sendSwapDeposit}.
1546
1687
  *
1688
+ * Confirms the ERC-20 `transfer`, then calls {@link ZyfaiSDK.logDeposit}.
1547
1689
  * Requires {@link ZyfaiSDK.connectAccount}. Pass the **EOA** as `userAddress`.
1548
1690
  *
1549
1691
  * @group Deposits and withdrawals
@@ -1551,20 +1693,178 @@ declare class ZyfaiSDK {
1551
1693
  * @param userAddress - Owner EOA (not the Safe)
1552
1694
  * @param chainId - Chain for the transfer
1553
1695
  * @param amount - Amount in least units (string integer)
1554
- * @param asset - Asset symbol (`USDC`, `WETH`, `EURC`, `NVDAc`)
1696
+ * @param asset - Collateral symbol (`USDC`, `WETH`, `EURC`, `NVDAc`)
1555
1697
  * @param strategy - Optional first-deposit {@link Strategy}
1556
- * @returns Transfer receipt and deposit registration (not yet credited until polled)
1698
+ * @returns Transfer receipt and deposit registration
1557
1699
  *
1558
- * @throws If validation fails, minimum portfolio is not met, Safe is unavailable, or transfer/register fails
1700
+ * @throws If validation fails, the minimum portfolio is not met, the Safe is unavailable, or transfer/register fails
1701
+ *
1702
+ * @see {@link ZyfaiSDK.sendDeposit}
1559
1703
  *
1560
1704
  * @example
1561
1705
  * ```typescript
1562
1706
  * await sdk.connectAccount(provider);
1563
- * const sent = await sdk.sendDeposit(eoa, 8453, "10000000", "USDC", "conservative");
1564
- * await sdk.waitForDepositCredit(sent.registration.id, 8453);
1707
+ * const sent = await sdk.sendDirectDeposit(eoa, 8453, "10000000", "USDC", "conservative");
1708
+ * await sdk.waitForDepositPosition(sent.registration.id, 8453);
1709
+ * ```
1710
+ */
1711
+ sendDirectDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1712
+ /**
1713
+ * Fund the Safe with a collateral the wallet already holds, or swap another token into it.
1714
+ *
1715
+ * @remarks
1716
+ * The positional call is unchanged: `asset` must be a collateral symbol, and
1717
+ * the wallet transfers that token on `chainId`.
1718
+ *
1719
+ * The object form spends `spendToken`. When that token is the destination
1720
+ * collateral on `chainId`, this is a direct deposit. Any other token is
1721
+ * quoted through Relay and delivered as `asset`. Same-chain native ETH into
1722
+ * WETH is wrapped in the wallet, because Relay rejects that pair.
1723
+ * Optional `slippageBps` on a swap defaults to 200 (max 500) and is fixed
1724
+ * when the funding order is created.
1725
+ *
1726
+ * Requires {@link ZyfaiSDK.connectAccount}. Pass the **EOA** as `userAddress`.
1727
+ * Follow with {@link ZyfaiSDK.waitForDepositPosition} when the caller should
1728
+ * wait until the deposit is allocated.
1729
+ *
1730
+ * @group Deposits and withdrawals
1731
+ *
1732
+ * @param userAddress - Owner EOA, or a {@link SendDepositParams} object
1733
+ * @param chainId - Deposit chain when using the positional form
1734
+ * @param amount - Least units of the token being spent
1735
+ * @param asset - Collateral that should land in the Safe
1736
+ * @param strategy - Optional first-deposit {@link Strategy}
1737
+ * @returns Transfer receipt and deposit registration
1738
+ *
1739
+ * @throws If the route cannot be quoted, the transfer fails, or registration fails
1740
+ *
1741
+ * @example
1742
+ * ```typescript
1743
+ * await sdk.connectAccount(provider);
1744
+ * // Wallet already holds USDC on Base.
1745
+ * const direct = await sdk.sendDeposit(eoa, 8453, "10000000", "USDC");
1746
+ *
1747
+ * // Wallet holds a different token. Relay delivers USDC to the Safe.
1748
+ * const swapped = await sdk.sendDeposit({
1749
+ * userAddress: eoa,
1750
+ * chainId: 8453,
1751
+ * asset: "USDC",
1752
+ * amount: "1000000000000000000",
1753
+ * spendToken: "0xTokenOnBase",
1754
+ * });
1755
+ * await sdk.waitForDepositPosition(swapped.registration.id, 8453);
1565
1756
  * ```
1566
1757
  */
1567
1758
  sendDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1759
+ sendDeposit(params: SendDepositParams): Promise<DepositResponse>;
1760
+ /**
1761
+ * Resolve a deposit without signing.
1762
+ *
1763
+ * @remarks
1764
+ * A collateral the wallet already holds on `chainId` returns `route: "direct"`.
1765
+ * Same-chain native ETH into WETH returns `route: "wrap"`. Any other spend
1766
+ * token returns a Relay review quote (`route: "swap"`). Nothing is signed.
1767
+ * Optional `slippageBps` (default 200, max 500) is stored on that funding
1768
+ * order and reused when the quote is refreshed for signing.
1769
+ *
1770
+ * @group Deposits and withdrawals
1771
+ *
1772
+ * @param params - Destination collateral and optional spend token
1773
+ * @returns The route, and a review quote when a swap is required
1774
+ *
1775
+ * @throws If the spend token or destination collateral is not supported
1776
+ */
1777
+ quoteDeposit(params: SendDepositParams): Promise<{
1778
+ route: "direct" | "wrap";
1779
+ asset: string;
1780
+ chainId: SupportedChainId;
1781
+ amount: string;
1782
+ } | ({
1783
+ route: "swap";
1784
+ } & SwapDepositQuote)>;
1785
+ /**
1786
+ * Quote a Relay swap that delivers a collateral token to the Safe.
1787
+ *
1788
+ * @remarks
1789
+ * Creates a funding order on the execution API. The connected wallet does
1790
+ * not sign. Pass `orderId` to {@link ZyfaiSDK.sendSwapDeposit} to sign the
1791
+ * refreshed quote, or call {@link ZyfaiSDK.sendDeposit} to quote and sign
1792
+ * in one step.
1793
+ *
1794
+ * Same-chain native ETH into WETH is rejected here. Use {@link ZyfaiSDK.sendDeposit}
1795
+ * with `spendToken: "ETH"`, which wraps in the wallet.
1796
+ *
1797
+ * Optional `slippageBps` defaults to 200 (max 500) and is fixed when this
1798
+ * funding order is created. Sign-time refresh reuses the stored value.
1799
+ *
1800
+ * @group Deposits and withdrawals
1801
+ *
1802
+ * @param params - Origin token, destination collateral, and funding wallet
1803
+ * @returns Review quote. Not yet signed.
1804
+ *
1805
+ * @throws If the server rejects the pair, the amount, or the quote
1806
+ */
1807
+ quoteSwapDeposit(params: SwapDepositParams): Promise<SwapDepositQuote>;
1808
+ /**
1809
+ * Read a Relay funding order, including a linked deposit once credit starts.
1810
+ *
1811
+ * @group Deposits and withdrawals
1812
+ *
1813
+ * @param orderId - Id from {@link ZyfaiSDK.quoteSwapDeposit}
1814
+ * @returns Stored order
1815
+ *
1816
+ * @throws If `orderId` is missing
1817
+ */
1818
+ getSwapDeposit(orderId: string): Promise<SwapDepositOrder>;
1819
+ /**
1820
+ * Swap or bridge a token into a Zyfai collateral, then register the deposit.
1821
+ *
1822
+ * @remarks
1823
+ * The execution API quotes Relay with the Safe as recipient. This method
1824
+ * refreshes that quote, signs the steps with the connected wallet, waits
1825
+ * for the collateral transfer into the Safe, and calls {@link ZyfaiSDK.logDeposit}.
1826
+ * Credit still requires that verified transfer. A refund or failed fill does
1827
+ * not register a deposit.
1828
+ *
1829
+ * Requires {@link ZyfaiSDK.connectAccount}. Origin chains other than
1830
+ * Ethereum, Base, and Arbitrum need an EIP-1193 wallet that can sign there.
1831
+ *
1832
+ * Optional `slippageBps` defaults to 200 (max 500) and is fixed when the
1833
+ * funding order is created. A later call that passes `orderId` ignores
1834
+ * `slippageBps` and signs the stored order.
1835
+ *
1836
+ * @group Deposits and withdrawals
1837
+ *
1838
+ * @param params - Origin token and destination collateral
1839
+ * @returns Destination transfer and deposit registration
1840
+ *
1841
+ * @throws If the quote, signature, fill, or registration fails, or if
1842
+ * `orderId` names a funding order whose origin or destination differs from
1843
+ * this call
1844
+ *
1845
+ * @see {@link ZyfaiSDK.sendDeposit}
1846
+ *
1847
+ * @example
1848
+ * ```typescript
1849
+ * await sdk.connectAccount(provider);
1850
+ * const sent = await sdk.sendSwapDeposit({
1851
+ * userAddress: eoa,
1852
+ * originChainId: 42161,
1853
+ * originCurrency: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
1854
+ * originAmount: "10000000",
1855
+ * destinationChainId: 8453,
1856
+ * destinationAsset: "WETH",
1857
+ * });
1858
+ * ```
1859
+ */
1860
+ sendSwapDeposit(params: SwapDepositParams): Promise<DepositResponse>;
1861
+ private sendRoutedDeposit;
1862
+ /** Portfolio floor used by a direct deposit, applied before a wrap or swap spends. */
1863
+ private assertCollateralMinimum;
1864
+ private assertSwapDepositParams;
1865
+ private walletClientForOrigin;
1866
+ private wrapNativeEth;
1867
+ private waitForRelayCreditTx;
1568
1868
  /**
1569
1869
  * @deprecated Compatibility convenience method. Prefer {@link ZyfaiSDK.sendDeposit} followed by
1570
1870
  * {@link ZyfaiSDK.waitForDepositCredit} when the caller owns the completion UX.
@@ -1630,6 +1930,16 @@ declare class ZyfaiSDK {
1630
1930
  * @internal
1631
1931
  */
1632
1932
  private ensureDepositProfileForPrepare;
1933
+ /**
1934
+ * Persist the deposit asset on one chain before a signing page runs the transfer or swap.
1935
+ * Does not build calldata and does not check the portfolio minimum.
1936
+ */
1937
+ ensureDepositAssetOnChain(params: {
1938
+ asset: SupportedAsset;
1939
+ chainId: SupportedChainId;
1940
+ }): Promise<{
1941
+ applied: boolean;
1942
+ }>;
1633
1943
  /**
1634
1944
  * Prepare a deposit: persist first-deposit profile when needed and return
1635
1945
  * ERC-20 transfer calldata for the user to sign (does not broadcast).
@@ -1749,6 +2059,21 @@ declare class ZyfaiSDK {
1749
2059
  * @throws If deposit recovers to EOA or polling fails
1750
2060
  */
1751
2061
  waitForDepositCredit(depositId: string, chainId: SupportedChainId, options?: WaitForDepositCreditOptions): Promise<DepositLifecycleResponse>;
2062
+ /**
2063
+ * Poll deposit status until funds are allocated to a protocol position, skipped, or failed.
2064
+ * Crosschain deposits resolve once the bridge tx is recorded (`crosschain: true`, `executionTxHash` set);
2065
+ * the destination-chain allocation is not tracked on this lifecycle.
2066
+ */
2067
+ waitForDepositPosition(depositId: string, chainId: SupportedChainId, options?: WaitForDepositPositionOptions): Promise<DepositLifecycleResponse>;
2068
+ getWithdrawStatus(withdrawalId: string): Promise<WithdrawLifecycleResponse>;
2069
+ /**
2070
+ * Short poll: completes when sync slice settles, async enters cooldown, or claim is already in flight (resume/retry).
2071
+ */
2072
+ waitForWithdrawSettlement(withdrawalId: string, chainId: SupportedChainId, options?: WaitForWithdrawSettlementOptions): Promise<WithdrawLifecycleResponse>;
2073
+ /**
2074
+ * Long poll through async cooldown and claim until lifecycle is completed.
2075
+ */
2076
+ waitForWithdrawComplete(withdrawalId: string, chainId: SupportedChainId, options?: WaitForWithdrawCompleteOptions): Promise<WithdrawLifecycleResponse>;
1752
2077
  /**
1753
2078
  * Withdraw funds from Safe smart wallet
1754
2079
  * Initiates a withdrawal request to the Zyfai API
@@ -2692,6 +3017,55 @@ type BankrProvider = ReturnType<typeof createBankrProvider>;
2692
3017
  */
2693
3018
  declare function getManagedAssets(): SupportedAsset[];
2694
3019
 
3020
+ type DepositRoute = {
3021
+ kind: "direct";
3022
+ asset: string;
3023
+ } | {
3024
+ kind: "wrap";
3025
+ asset: "WETH";
3026
+ } | {
3027
+ kind: "swap";
3028
+ originChainId: number;
3029
+ originCurrency: string;
3030
+ destinationAsset: string;
3031
+ };
3032
+ type DepositRouteInput = {
3033
+ /** Chain the collateral should arrive on. */
3034
+ chainId: number;
3035
+ /** Collateral symbol that should land in the Safe. */
3036
+ asset: string;
3037
+ /**
3038
+ * Token the wallet spends. Omit to spend `asset` on `chainId`.
3039
+ * A symbol or contract equal to that collateral on `chainId` is a direct deposit.
3040
+ */
3041
+ spendToken?: string;
3042
+ /** Chain the spend token is on. Defaults to `chainId`. */
3043
+ spendChainId?: number;
3044
+ };
3045
+ /**
3046
+ * Choose a direct collateral transfer, a same-chain ETH wrap, or a Relay swap.
3047
+ *
3048
+ * A direct deposit is only when the wallet already holds the destination
3049
+ * collateral on the destination chain. Any other spend token is a swap.
3050
+ * Same-chain native ETH into WETH wraps in the wallet: Relay rejects that pair.
3051
+ */
3052
+ declare const resolveDepositRoute: (input: DepositRouteInput) => DepositRoute;
3053
+
3054
+ /** Matches the execution API and the deposit UI default. */
3055
+ declare const DEFAULT_RELAY_SLIPPAGE_BPS = 200;
3056
+ /** Hard cap accepted by `POST /users/me/funding-orders`. */
3057
+ declare const MAX_RELAY_SLIPPAGE_BPS = 500;
3058
+ /**
3059
+ * Dashboard presets (basis points). Any integer from 1 to
3060
+ * {@link MAX_RELAY_SLIPPAGE_BPS} is valid; these are the usual choices.
3061
+ */
3062
+ declare const RELAY_SLIPPAGE_PRESETS_BPS: readonly [50, 200, 500];
3063
+ /**
3064
+ * Clamp a client slippage to the range the execution API stores.
3065
+ * Omitted or non-finite values use {@link DEFAULT_RELAY_SLIPPAGE_BPS}.
3066
+ */
3067
+ declare const resolveRelaySlippageBps: (clientBps?: number | null) => number;
3068
+
2695
3069
  /**
2696
3070
  * API Endpoints Configuration
2697
3071
  *
@@ -2791,4 +3165,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
2791
3165
  */
2792
3166
  declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
2793
3167
 
2794
- 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, type UserSessionAuth, 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, getManagedAssets, getSupportedChainIds, getWsUrl, isSupportedChain, type staleBalances };
3168
+ 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_RELAY_SLIPPAGE_BPS, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositPositionOutcome, type DepositResponse, type DepositRoute, type DepositRouteInput, 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, MAX_RELAY_SLIPPAGE_BPS, 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, RELAY_SLIPPAGE_PRESETS_BPS, 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 SendDepositParams, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type SwapDepositOrder, type SwapDepositParams, type SwapDepositQuote, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, type UserSessionAuth, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, WS_ENDPOINT, WS_URLS, type WaitForDepositCreditOptions, type WaitForDepositPositionOptions, type WaitForWithdrawCompleteOptions, type WaitForWithdrawSettlementOptions, type WalletTVL, type WithdrawAsyncLeg, type WithdrawLifecycleResponse, type WithdrawLifecycleStatus, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, isSupportedChain, resolveDepositRoute, resolveRelaySlippageBps, type staleBalances };