@zyfai/sdk 1.9.2 → 1.10.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/README.md CHANGED
@@ -79,29 +79,19 @@ const sdk = new ZyfaiSDK("your-api-key");
79
79
 
80
80
  ### Connect Account
81
81
 
82
- The SDK accepts either a private key or a modern wallet provider. **The SDK automatically authenticates the user via SIWE (Sign-In with Ethereum) when connecting.**
82
+ Connect the customer's existing wallet provider. The SDK performs SIWE authentication automatically.
83
83
 
84
84
  ```typescript
85
- // Option 1: With private key (chainId required)
86
- await sdk.connectAccount("0x...", 8453);
87
-
88
- // Option 2: With wallet provider (chainId optional - uses provider's chain)
89
85
  const provider = await connector.getProvider();
90
- await sdk.connectAccount(provider); // SDK detects chain from provider
91
-
92
- // Option 3: With EIP-1193 provider
93
- const provider = window.ethereum; // Client passes this from their frontend
94
- await sdk.connectAccount(provider); // Automatically uses provider's current chain
95
-
96
- // Now call methods with explicit user addresses
97
- const userAddress = "0xUser...";
98
- await sdk.deploySafe(userAddress, 8453);
86
+ const chainId = 8453; // match the connected wallet
87
+ const userAddress = await sdk.connectAccount(provider, chainId);
99
88
  ```
100
89
 
101
- **Note:**
102
-
103
- - When using a wallet provider, the SDK automatically detects the chain from the provider. You can optionally specify `chainId` to override.
104
- - The SDK automatically performs SIWE authentication when connecting, so you don't need to call any additional authentication methods.
90
+ Wait for authentication before enabling deposit or withdrawal actions. For an existing
91
+ Safe treasury, the returned address must be the parent Safe, not an individual owner
92
+ or the Zyfai child. See the [nested Safe integration guide](https://docs.zyf.ai/docs/sdk/nested-safe-deposit).
93
+ Backend-owned EOA agents can use a private-key input; see the
94
+ [agent quickstart](https://docs.zyf.ai/docs/sdk/agent-quickstart).
105
95
 
106
96
  ### Disconnect Account
107
97
 
@@ -262,8 +252,7 @@ Connect account for signing transactions and authenticate via SIWE. Accepts eith
262
252
 
263
253
  - `account`: Private key string or wallet provider object (EIP-1193 provider, viem WalletClient, etc.)
264
254
  - `chainId`: Target chain ID
265
- - **Required** for private key
266
- - **Optional** for wallet providers (auto-detects from provider)
255
+ - Pass explicitly to match the connected wallet network.
267
256
  - Default: 8453 (Base)
268
257
 
269
258
  **Returns:** Connected wallet address
@@ -277,20 +266,43 @@ Connect account for signing transactions and authenticate via SIWE. Accepts eith
277
266
  **Examples:**
278
267
 
279
268
  ```typescript
280
- // With private key (chainId required)
281
- await sdk.connectAccount("0x...", 8453);
282
-
283
- // With wallet provider (chainId optional)
284
269
  const provider = await connector.getProvider();
285
- await sdk.connectAccount(provider); // Uses provider's current chain
270
+ const userAddress = await sdk.connectAccount(provider, chainId);
286
271
  ```
287
272
 
288
- **Nested Safe owners:** connect the parent Safe with WalletConnect or the Safe App, then pass
289
- that parent address (not an owner EOA) as `userAddress` on `sendDeposit`. Use a `chainId` where
290
- the Safe is deployed. The SDK asks the parent to sign the execution API EIP-712 deploy payload,
291
- registers the session with `{ chainId }` only, and proposes an ERC-20 `transfer` from the parent.
292
- The SDK polls Safe Transaction Service and registers the on-chain hash when execution completes.
293
- Other owners confirm in the Safe UI when the threshold is above 1.
273
+ **Nested Safe owners:** use the parent Safe's WalletConnect or Safe App provider.
274
+ Pass the authenticated parent address and its deployed chain to the SDK.
275
+ `sendDeposit` handles child account setup and authorisation; owners confirm in Safe{Wallet}.
276
+ Use the object form for direct deposits to capture an exact proposal reference:
277
+
278
+ ```typescript
279
+ const sent = await sdk.sendDeposit({
280
+ userAddress,
281
+ chainId,
282
+ amount: "100000000",
283
+ asset: "USDC",
284
+ onSafeProposal: async (reference) => {
285
+ await savePendingProposal(reference); // your app's durable, operation-scoped storage
286
+ },
287
+ });
288
+ await saveDepositId(sent.registration.id); // your app's storage
289
+ await sdk.waitForDepositCredit(sent.registration.id, chainId);
290
+ await sdk.waitForDepositPosition(sent.registration.id, chainId);
291
+ ```
292
+
293
+ If interrupted after submission, reconnect the same parent and call
294
+ `sdk.resumeNestedSafeDeposit(reference)` with the stored reference. A new
295
+ `sendDeposit` starts a new proposal; equal amounts do not identify a retry.
296
+ If no reference was captured, reconcile the Safe transaction queue before retrying.
297
+
298
+ Withdraw with `withdrawFunds(userAddress, chainId, amount, asset)` and persist its
299
+ lifecycle ID. Use `getWithdrawStatus`, `waitForWithdrawSettlement` and
300
+ `waitForWithdrawComplete` rather than submitting again. The standard payout
301
+ returns to the authenticated parent Safe.
302
+
303
+ See the [nested Safe integration guide](https://docs.zyf.ai/docs/sdk/nested-safe-deposit)
304
+ for the recommended frontend flow. Do not manage child deployment, session signing,
305
+ or individual owner keys in your application.
294
306
 
295
307
  ##### `disconnectAccount(): Promise<void>`
296
308
 
@@ -334,7 +346,7 @@ Get the Smart Wallet (Safe) address for a user.
334
346
 
335
347
  ##### `deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>`
336
348
 
337
- > Not needed for a predeployed (pool) wallet: `sendDeposit()` deploys the Safe and enables the agent session on first deposit, and this method warns when called for one. Required for an owner that is not predeployed — a contract owner such as a nested Safe, or a legacy self-deployed wallet — where `sendDeposit()` calls it internally.
349
+ > Advanced/legacy method. New partner integrations should call `sendDeposit()`, which orchestrates account setup. Do not call this method as a separate step for a parent Safe.
338
350
 
339
351
  Deploy a Safe smart wallet for a user. **Deployment is handled by the backend API**, which manages all RPC calls and bundler interactions. This avoids rate limiting issues.
340
352
 
@@ -467,7 +479,7 @@ Session keys enable delegated transaction execution without exposing the main pr
467
479
 
468
480
  #### Simple Usage
469
481
 
470
- > Not needed for a predeployed (pool) wallet: its agent session is already enabled on-chain, `sendDeposit()` records it after the first deposit, and this method warns when called for one. Required for an owner that is not predeployed — a contract owner such as a nested Safe, or a legacy self-deployed wallet — where `sendDeposit()` calls it internally.
482
+ > Advanced/legacy method. New partner integrations should let `sendDeposit()` establish session readiness. The explicit example below is for legacy EOA integrations, not Safe treasury frontends.
471
483
 
472
484
  The SDK automatically fetches optimal session configuration from Zyfai API:
473
485
 
@@ -697,14 +709,14 @@ if (result.success) {
697
709
  - The SDK authenticates via SIWE before calling the withdrawal endpoints
698
710
  - Withdrawals are processed asynchronously - the `txHash` may not be immediately available
699
711
  - Check the `message` field for the withdrawal status
700
- - Use `getHistory()` to track the withdrawal transaction once it's processed
712
+ - Persist the withdrawal lifecycle ID and poll `getWithdrawStatus()` or `waitForWithdrawComplete()`. Do not submit a second withdrawal to check status.
701
713
 
702
714
  **Delayed withdrawals (`yieldmaxxing` strategy)**
703
715
 
704
716
  Positions held in protocols with asynchronous withdrawals (Ipor, Superform)
705
717
  cannot be exited on demand. For those the backend sends the immediately
706
718
  available portion straight away, then queues a redemption for the rest and
707
- forwards the funds to the EOA once the protocol releases them — roughly a day
719
+ forwards the funds to the authenticated owner (EOA or parent Safe) once the protocol releases them — roughly a day
708
720
  on Ipor, three on Superform.
709
721
 
710
722
  The user has nothing else to call, but `withdrawFunds` returns as soon as the
@@ -869,7 +881,7 @@ is the most common mistake:
869
881
  An in-flight amount is **no longer withdrawable**. A `withdrawFunds` call only
870
882
  reaches positions in the current snapshot and idle Safe balances, and the
871
883
  in-flight amount is in neither — calling it again will not pull those funds out
872
- any faster, nor will it fail with an error. They land on the user's EOA on
884
+ any faster, nor will it fail with an error. They land on the authenticated owner's address on
873
885
  their own once the protocol releases them, so the right UI is to show them as
874
886
  pending with their `estimatedClaimAt`, never to offer them for withdrawal.
875
887
 
package/dist/index.d.mts CHANGED
@@ -202,6 +202,23 @@ interface SmartWalletResponse {
202
202
  */
203
203
  isOwner: boolean;
204
204
  }
205
+ /** Next nested-parent action after wallet connect (integrator-owned). */
206
+ type NestedSafeOnboardingStep = "deploy" | "register" | "deposit" | "withdraw" | "ready";
207
+ interface NestedSafeOnboardingStatus$1 {
208
+ isNestedOwner: boolean;
209
+ childRegistered: boolean;
210
+ childDeployed: boolean;
211
+ sessionActive: boolean;
212
+ hasPortfolioBalance: boolean;
213
+ suggestedStep: NestedSafeOnboardingStep;
214
+ child: SmartWalletResponse | null;
215
+ }
216
+ interface NestedSafeOnboardingStatusResponse {
217
+ success: boolean;
218
+ userAddress: string;
219
+ chainId: number;
220
+ status: NestedSafeOnboardingStatus$1;
221
+ }
205
222
  interface Protocol {
206
223
  id: string;
207
224
  name: string;
@@ -733,7 +750,19 @@ interface SwapDepositOrder {
733
750
  * `sendDeposit` input. Omit `spendToken` to deposit `asset` directly on `chainId`.
734
751
  * Set `spendToken` when the wallet holds a different token or chain.
735
752
  */
753
+ /** Serializable identity of a submitted nested Safe deposit. Persist before waiting. */
754
+ interface NestedSafeDepositReference {
755
+ userAddress: Address;
756
+ chainId: SupportedChainId;
757
+ childSafe: Address;
758
+ asset: string;
759
+ amount: string;
760
+ /** Safe proposal hash or actual transaction hash returned by the connector. */
761
+ proposalHash: Hex;
762
+ }
736
763
  interface SendDepositParams {
764
+ /** Called after a direct Safe proposal is submitted, before polling its execution. */
765
+ onSafeProposal?: (reference: NestedSafeDepositReference) => void | Promise<void>;
737
766
  userAddress: string;
738
767
  /** Chain the collateral should arrive on. */
739
768
  chainId: SupportedChainId;
@@ -1548,12 +1577,19 @@ declare class ZyfaiSDK {
1548
1577
  * True when userAddress is the signer, wallet client, or agent session EOA.
1549
1578
  * @private
1550
1579
  */
1580
+ private assertConnectedUser;
1551
1581
  private isConnectedUser;
1552
1582
  /**
1553
1583
  * Nested Safe owners use intent sessions: finish any pending safe-deploy typed-data
1554
1584
  * (install or emissary enable), then register with chainId only.
1555
1585
  * @private
1556
1586
  */
1587
+ /**
1588
+ * Read-only probe for nested owners: on-chain session permissions on `chainId`.
1589
+ * Mirrors the early-return branch in {@link deploySafeAccount} without signing.
1590
+ * @private
1591
+ */
1592
+ private isNestedChainSessionPermissionsReady;
1557
1593
  private registerNestedIntentSessionKey;
1558
1594
  private registerNestedChildProfile;
1559
1595
  /**
@@ -1590,6 +1626,20 @@ declare class ZyfaiSDK {
1590
1626
  * @throws If `userAddress` is missing or `chainId` is unsupported
1591
1627
  */
1592
1628
  getSmartWalletAddress(userAddress: string, chainId: SupportedChainId): Promise<SmartWalletResponse>;
1629
+ /**
1630
+ * Nested-parent onboarding snapshot for a connected parent Safe address.
1631
+ *
1632
+ * @group Deposits and withdrawals
1633
+ *
1634
+ * @remarks Combines child resolution ({@link ZyfaiSDK.getSmartWalletAddress}),
1635
+ * session state (account registration plus per-chain safe-deploy readiness),
1636
+ * and portfolio balances
1637
+ * ({@link ZyfaiSDK.getPortfolio}). Wallet connect remains integrator-side.
1638
+ *
1639
+ * @param userAddress - Parent Safe address from {@link ZyfaiSDK.connectAccount}
1640
+ * @param chainId - Target chain (deployment and session are per chain)
1641
+ */
1642
+ getNestedSafeOnboardingStatus(userAddress: string, chainId: SupportedChainId): Promise<NestedSafeOnboardingStatusResponse>;
1593
1643
  /**
1594
1644
  * Deploy Safe Smart Wallet for a user
1595
1645
  *
@@ -1818,7 +1868,7 @@ declare class ZyfaiSDK {
1818
1868
  * await sdk.waitForDepositPosition(sent.registration.id, 8453);
1819
1869
  * ```
1820
1870
  */
1821
- sendDirectDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1871
+ sendDirectDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy, onSafeProposal?: (reference: NestedSafeDepositReference) => void | Promise<void>): Promise<DepositResponse>;
1822
1872
  private sendCollateralDeposit;
1823
1873
  /**
1824
1874
  * Read the current first-deposit permit intent after a pending or interrupted deposit.
@@ -1892,6 +1942,13 @@ declare class ZyfaiSDK {
1892
1942
  */
1893
1943
  sendDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1894
1944
  sendDeposit(params: SendDepositParams): Promise<DepositResponse>;
1945
+ /**
1946
+ * Resume one specific parent Safe deposit without proposing another transfer.
1947
+ * Persist the reference supplied by sendDeposit's onSafeProposal callback.
1948
+ *
1949
+ * @group Deposits and withdrawals
1950
+ */
1951
+ resumeNestedSafeDeposit(reference: NestedSafeDepositReference): Promise<DepositResponse>;
1895
1952
  /**
1896
1953
  * Resolve a deposit without signing.
1897
1954
  *
@@ -3346,6 +3403,26 @@ type BankrProvider = ReturnType<typeof createBankrProvider>;
3346
3403
  */
3347
3404
  declare function getManagedAssets(): SupportedAsset[];
3348
3405
 
3406
+ type NestedSafeOnboardingFlags = {
3407
+ isNestedOwner: boolean;
3408
+ childRegistered: boolean;
3409
+ childDeployed: boolean;
3410
+ sessionActive: boolean;
3411
+ hasPortfolioBalance: boolean;
3412
+ };
3413
+ type NestedSafeOnboardingStatus = NestedSafeOnboardingFlags & {
3414
+ suggestedStep: NestedSafeOnboardingStep;
3415
+ child: SmartWalletResponse | null;
3416
+ };
3417
+ /** True when the child Safe has positions or idle balances the agent can withdraw. */
3418
+ declare function portfolioHasWithdrawableBalance(portfolio: PortfolioDetailed | undefined): boolean;
3419
+ /**
3420
+ * Pure onboarding step from flags already fetched from chain and the execution API.
3421
+ * Wallet connect stays integrator-side (Reown, Safe App, etc.).
3422
+ */
3423
+ declare function deriveNestedSafeOnboardingStep(flags: NestedSafeOnboardingFlags): NestedSafeOnboardingStep;
3424
+ declare function buildNestedSafeOnboardingStatus(flags: NestedSafeOnboardingFlags, child: SmartWalletResponse | null): NestedSafeOnboardingStatus;
3425
+
3349
3426
  type DepositRoute = {
3350
3427
  kind: "direct";
3351
3428
  asset: string;
@@ -3494,4 +3571,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
3494
3571
  */
3495
3572
  declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
3496
3573
 
3497
- 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 BaseMerklCampaignId, 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 DecodedUserOperationCall, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositPositionOutcome, type DepositResponse, type DepositRoute, type DepositRouteInput, ENTRY_POINT_V07_ADDRESS, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, type ExcludedPool, type FirstPermitDepositStatus, type FirstTopupResponse, type GetAvailablePoolsOptions, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryAssetType, 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 MerklCampaign, 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, type RzfiClaimResponse, type RzfiClaimTransaction, 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, type V1ChainSessions, type V1SessionEnableInput, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VerifiableUserOperation, type VolumeAssetType, 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, buildV1ChainSessions, createBankrProvider, decodeUserOperationCalls, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, hashUserOperationV07, hashV1SessionEnable, isSupportedChain, parseUserOperationJson, parseV1ChainSessions, resolveDepositRoute, resolveRelaySlippageBps, serializeV1ChainSessions, type staleBalances };
3574
+ 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 BaseMerklCampaignId, 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 DecodedUserOperationCall, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositPositionOutcome, type DepositResponse, type DepositRoute, type DepositRouteInput, ENTRY_POINT_V07_ADDRESS, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, type ExcludedPool, type FirstPermitDepositStatus, type FirstTopupResponse, type GetAvailablePoolsOptions, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryAssetType, 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 MerklCampaign, type NestedSafeDepositReference, type NestedSafeOnboardingFlags, type NestedSafeOnboardingStatus$1 as NestedSafeOnboardingStatus, type NestedSafeOnboardingStatusResponse, type NestedSafeOnboardingStep, 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, type RzfiClaimResponse, type RzfiClaimTransaction, 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, type V1ChainSessions, type V1SessionEnableInput, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VerifiableUserOperation, type VolumeAssetType, 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, buildNestedSafeOnboardingStatus, buildV1ChainSessions, createBankrProvider, decodeUserOperationCalls, deriveNestedSafeOnboardingStep, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, hashUserOperationV07, hashV1SessionEnable, isSupportedChain, parseUserOperationJson, parseV1ChainSessions, portfolioHasWithdrawableBalance, resolveDepositRoute, resolveRelaySlippageBps, serializeV1ChainSessions, type staleBalances };
package/dist/index.d.ts CHANGED
@@ -202,6 +202,23 @@ interface SmartWalletResponse {
202
202
  */
203
203
  isOwner: boolean;
204
204
  }
205
+ /** Next nested-parent action after wallet connect (integrator-owned). */
206
+ type NestedSafeOnboardingStep = "deploy" | "register" | "deposit" | "withdraw" | "ready";
207
+ interface NestedSafeOnboardingStatus$1 {
208
+ isNestedOwner: boolean;
209
+ childRegistered: boolean;
210
+ childDeployed: boolean;
211
+ sessionActive: boolean;
212
+ hasPortfolioBalance: boolean;
213
+ suggestedStep: NestedSafeOnboardingStep;
214
+ child: SmartWalletResponse | null;
215
+ }
216
+ interface NestedSafeOnboardingStatusResponse {
217
+ success: boolean;
218
+ userAddress: string;
219
+ chainId: number;
220
+ status: NestedSafeOnboardingStatus$1;
221
+ }
205
222
  interface Protocol {
206
223
  id: string;
207
224
  name: string;
@@ -733,7 +750,19 @@ interface SwapDepositOrder {
733
750
  * `sendDeposit` input. Omit `spendToken` to deposit `asset` directly on `chainId`.
734
751
  * Set `spendToken` when the wallet holds a different token or chain.
735
752
  */
753
+ /** Serializable identity of a submitted nested Safe deposit. Persist before waiting. */
754
+ interface NestedSafeDepositReference {
755
+ userAddress: Address;
756
+ chainId: SupportedChainId;
757
+ childSafe: Address;
758
+ asset: string;
759
+ amount: string;
760
+ /** Safe proposal hash or actual transaction hash returned by the connector. */
761
+ proposalHash: Hex;
762
+ }
736
763
  interface SendDepositParams {
764
+ /** Called after a direct Safe proposal is submitted, before polling its execution. */
765
+ onSafeProposal?: (reference: NestedSafeDepositReference) => void | Promise<void>;
737
766
  userAddress: string;
738
767
  /** Chain the collateral should arrive on. */
739
768
  chainId: SupportedChainId;
@@ -1548,12 +1577,19 @@ declare class ZyfaiSDK {
1548
1577
  * True when userAddress is the signer, wallet client, or agent session EOA.
1549
1578
  * @private
1550
1579
  */
1580
+ private assertConnectedUser;
1551
1581
  private isConnectedUser;
1552
1582
  /**
1553
1583
  * Nested Safe owners use intent sessions: finish any pending safe-deploy typed-data
1554
1584
  * (install or emissary enable), then register with chainId only.
1555
1585
  * @private
1556
1586
  */
1587
+ /**
1588
+ * Read-only probe for nested owners: on-chain session permissions on `chainId`.
1589
+ * Mirrors the early-return branch in {@link deploySafeAccount} without signing.
1590
+ * @private
1591
+ */
1592
+ private isNestedChainSessionPermissionsReady;
1557
1593
  private registerNestedIntentSessionKey;
1558
1594
  private registerNestedChildProfile;
1559
1595
  /**
@@ -1590,6 +1626,20 @@ declare class ZyfaiSDK {
1590
1626
  * @throws If `userAddress` is missing or `chainId` is unsupported
1591
1627
  */
1592
1628
  getSmartWalletAddress(userAddress: string, chainId: SupportedChainId): Promise<SmartWalletResponse>;
1629
+ /**
1630
+ * Nested-parent onboarding snapshot for a connected parent Safe address.
1631
+ *
1632
+ * @group Deposits and withdrawals
1633
+ *
1634
+ * @remarks Combines child resolution ({@link ZyfaiSDK.getSmartWalletAddress}),
1635
+ * session state (account registration plus per-chain safe-deploy readiness),
1636
+ * and portfolio balances
1637
+ * ({@link ZyfaiSDK.getPortfolio}). Wallet connect remains integrator-side.
1638
+ *
1639
+ * @param userAddress - Parent Safe address from {@link ZyfaiSDK.connectAccount}
1640
+ * @param chainId - Target chain (deployment and session are per chain)
1641
+ */
1642
+ getNestedSafeOnboardingStatus(userAddress: string, chainId: SupportedChainId): Promise<NestedSafeOnboardingStatusResponse>;
1593
1643
  /**
1594
1644
  * Deploy Safe Smart Wallet for a user
1595
1645
  *
@@ -1818,7 +1868,7 @@ declare class ZyfaiSDK {
1818
1868
  * await sdk.waitForDepositPosition(sent.registration.id, 8453);
1819
1869
  * ```
1820
1870
  */
1821
- sendDirectDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1871
+ sendDirectDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy, onSafeProposal?: (reference: NestedSafeDepositReference) => void | Promise<void>): Promise<DepositResponse>;
1822
1872
  private sendCollateralDeposit;
1823
1873
  /**
1824
1874
  * Read the current first-deposit permit intent after a pending or interrupted deposit.
@@ -1892,6 +1942,13 @@ declare class ZyfaiSDK {
1892
1942
  */
1893
1943
  sendDeposit(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1894
1944
  sendDeposit(params: SendDepositParams): Promise<DepositResponse>;
1945
+ /**
1946
+ * Resume one specific parent Safe deposit without proposing another transfer.
1947
+ * Persist the reference supplied by sendDeposit's onSafeProposal callback.
1948
+ *
1949
+ * @group Deposits and withdrawals
1950
+ */
1951
+ resumeNestedSafeDeposit(reference: NestedSafeDepositReference): Promise<DepositResponse>;
1895
1952
  /**
1896
1953
  * Resolve a deposit without signing.
1897
1954
  *
@@ -3346,6 +3403,26 @@ type BankrProvider = ReturnType<typeof createBankrProvider>;
3346
3403
  */
3347
3404
  declare function getManagedAssets(): SupportedAsset[];
3348
3405
 
3406
+ type NestedSafeOnboardingFlags = {
3407
+ isNestedOwner: boolean;
3408
+ childRegistered: boolean;
3409
+ childDeployed: boolean;
3410
+ sessionActive: boolean;
3411
+ hasPortfolioBalance: boolean;
3412
+ };
3413
+ type NestedSafeOnboardingStatus = NestedSafeOnboardingFlags & {
3414
+ suggestedStep: NestedSafeOnboardingStep;
3415
+ child: SmartWalletResponse | null;
3416
+ };
3417
+ /** True when the child Safe has positions or idle balances the agent can withdraw. */
3418
+ declare function portfolioHasWithdrawableBalance(portfolio: PortfolioDetailed | undefined): boolean;
3419
+ /**
3420
+ * Pure onboarding step from flags already fetched from chain and the execution API.
3421
+ * Wallet connect stays integrator-side (Reown, Safe App, etc.).
3422
+ */
3423
+ declare function deriveNestedSafeOnboardingStep(flags: NestedSafeOnboardingFlags): NestedSafeOnboardingStep;
3424
+ declare function buildNestedSafeOnboardingStatus(flags: NestedSafeOnboardingFlags, child: SmartWalletResponse | null): NestedSafeOnboardingStatus;
3425
+
3349
3426
  type DepositRoute = {
3350
3427
  kind: "direct";
3351
3428
  asset: string;
@@ -3494,4 +3571,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
3494
3571
  */
3495
3572
  declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
3496
3573
 
3497
- 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 BaseMerklCampaignId, 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 DecodedUserOperationCall, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositPositionOutcome, type DepositResponse, type DepositRoute, type DepositRouteInput, ENTRY_POINT_V07_ADDRESS, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, type ExcludedPool, type FirstPermitDepositStatus, type FirstTopupResponse, type GetAvailablePoolsOptions, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryAssetType, 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 MerklCampaign, 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, type RzfiClaimResponse, type RzfiClaimTransaction, 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, type V1ChainSessions, type V1SessionEnableInput, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VerifiableUserOperation, type VolumeAssetType, 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, buildV1ChainSessions, createBankrProvider, decodeUserOperationCalls, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, hashUserOperationV07, hashV1SessionEnable, isSupportedChain, parseUserOperationJson, parseV1ChainSessions, resolveDepositRoute, resolveRelaySlippageBps, serializeV1ChainSessions, type staleBalances };
3574
+ 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 BaseMerklCampaignId, 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 DecodedUserOperationCall, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositPositionOutcome, type DepositResponse, type DepositRoute, type DepositRouteInput, ENTRY_POINT_V07_ADDRESS, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, type ExcludedPool, type FirstPermitDepositStatus, type FirstTopupResponse, type GetAvailablePoolsOptions, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryAssetType, 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 MerklCampaign, type NestedSafeDepositReference, type NestedSafeOnboardingFlags, type NestedSafeOnboardingStatus$1 as NestedSafeOnboardingStatus, type NestedSafeOnboardingStatusResponse, type NestedSafeOnboardingStep, 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, type RzfiClaimResponse, type RzfiClaimTransaction, 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, type V1ChainSessions, type V1SessionEnableInput, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VerifiableUserOperation, type VolumeAssetType, 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, buildNestedSafeOnboardingStatus, buildV1ChainSessions, createBankrProvider, decodeUserOperationCalls, deriveNestedSafeOnboardingStep, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, hashUserOperationV07, hashV1SessionEnable, isSupportedChain, parseUserOperationJson, parseV1ChainSessions, portfolioHasWithdrawableBalance, resolveDepositRoute, resolveRelaySlippageBps, serializeV1ChainSessions, type staleBalances };