@zyfai/sdk 1.8.3 → 1.9.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
@@ -285,39 +285,12 @@ const provider = await connector.getProvider();
285
285
  await sdk.connectAccount(provider); // Uses provider's current chain
286
286
  ```
287
287
 
288
- **Nested Safe owners (multisig treasury):** connect the parent Safe, then pass the **parent Safe
289
- address** (not an owner EOA) as `userAddress` on `sendDeposit`. Use a `chainId` where that Safe
290
- is deployed (for example Ethereum `1` when the treasury only exists on mainnet). The SDK deploys
291
- a child Zyfai Safe owned by the parent, enables the agent session with EIP-712
292
- `MultiChainSession` signing, and proposes an ERC-20 `transfer` from the parent. The SDK polls
293
- Safe Transaction Service and registers the on-chain hash when execution completes.
294
-
295
- A threshold above 1 connects through WalletConnect or the Safe App, which collects the other
296
- signatures. A threshold-1 Safe can connect from a script:
297
-
298
- ```typescript
299
- import { createSafeOwnerProvider, ZyfaiSDK } from "@zyfai/sdk";
300
- import { createWalletClient, custom } from "viem";
301
- import { base } from "viem/chains";
302
-
303
- // `owner` is the wallet the user already connected. A private key is not required.
304
- const owner = createWalletClient({
305
- chain: base,
306
- transport: custom(window.ethereum),
307
- });
308
- const provider = await createSafeOwnerProvider({
309
- safeAddress: "0xParentSafe",
310
- owner,
311
- chain: base,
312
- });
313
- const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
314
- const parent = await sdk.connectAccount(provider, 8453);
315
- await sdk.sendDeposit(parent, 8453, "100000", "USDC");
316
- ```
317
-
318
- A 2-of-4 Safe does not use `createSafeOwnerProvider`. Connect that Safe with WalletConnect or
319
- the Safe App, pass the Safe address to `sendDeposit`, and the other owners confirm in the Safe
320
- UI. `sendDeposit` waits for that execution.
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.
321
294
 
322
295
  ##### `disconnectAccount(): Promise<void>`
323
296
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Chain, PublicClient, Address as Address$1, Hex as Hex$1, Account, WalletClient } from 'viem';
1
+ import { Chain, PublicClient, Address as Address$1, Hex as Hex$1 } from 'viem';
2
2
  import { hashChainSessions } from '@rhinestone/module-sdk';
3
3
 
4
4
  /**
@@ -117,6 +117,8 @@ interface DeploySafeResponse {
117
117
  sessionKeyCreated?: boolean;
118
118
  }
119
119
  interface UpdateUserProfileRequest {
120
+ smartWallet?: Address;
121
+ executorProxy?: boolean;
120
122
  strategy?: string;
121
123
  protocols?: string[];
122
124
  autoSelectProtocols?: boolean;
@@ -1248,6 +1250,10 @@ declare class ZyfaiSDK {
1248
1250
  private sessionEoa;
1249
1251
  /** When set, profile writes use agent-accessible endpoints instead of PATCH /users/me. */
1250
1252
  private sessionChannel?;
1253
+ /** Serialize concurrent connectAccount calls (e.g. React StrictMode double mount). */
1254
+ private connectAccountInFlight;
1255
+ /** One SIWE prompt at a time. Register must not send a second personal_sign. */
1256
+ private authenticateUserInFlight;
1251
1257
  /**
1252
1258
  * Create an SDK instance with an existing Zyfai user JWT (no wallet connected).
1253
1259
  *
@@ -1330,6 +1336,7 @@ declare class ZyfaiSDK {
1330
1336
  * @returns Promise that resolves when authentication is complete
1331
1337
  */
1332
1338
  private authenticateUser;
1339
+ private performAuthenticateUser;
1333
1340
  /**
1334
1341
  * Update user profile with Smart Wallet address and chain configuration
1335
1342
  * This method requires SIWE authentication and is automatically called after deploySafe
@@ -1516,6 +1523,7 @@ declare class ZyfaiSDK {
1516
1523
  * const provider = await connector.getProvider();
1517
1524
  * await sdk.connectAccount(provider);
1518
1525
  */
1526
+ private resolveConnectAddress;
1519
1527
  connectAccount(account: string | any, chainId?: SupportedChainId): Promise<Address>;
1520
1528
  /**
1521
1529
  * Clear the connected wallet, SIWE session, and cached smart-wallet state.
@@ -1541,6 +1549,13 @@ declare class ZyfaiSDK {
1541
1549
  * @private
1542
1550
  */
1543
1551
  private isConnectedUser;
1552
+ /**
1553
+ * Nested Safe owners use intent sessions: finish any pending safe-deploy typed-data
1554
+ * (install or emissary enable), then register with chainId only.
1555
+ * @private
1556
+ */
1557
+ private registerNestedIntentSessionKey;
1558
+ private registerNestedChildProfile;
1544
1559
  /**
1545
1560
  * SIWE login sets predeployed. Agent sessions (`forUser`) do not, so read it
1546
1561
  * from the user record before allowing a transfer to an undeployed pool Safe.
@@ -1633,21 +1648,10 @@ declare class ZyfaiSDK {
1633
1648
  */
1634
1649
  createSessionKey(userAddress: string, chainId: SupportedChainId): Promise<SessionKeyResponse>;
1635
1650
  /**
1636
- * Internal method to sign session key
1651
+ * Internal method to sign session key for an EOA owner.
1652
+ * Nested Safe owners register through {@link registerNestedIntentSessionKey}.
1637
1653
  * @private
1638
1654
  */
1639
- /**
1640
- * A nested Safe owner signs one MultiChainSession covering every chain in the
1641
- * session configuration, and the child validates that signature against the
1642
- * owner through ERC-1271 on each of them. A chain where the owner has no code
1643
- * would accept the signature nowhere, so refuse rather than sign it.
1644
- *
1645
- * The session list is not filtered here: the execution API rebuilds the digest
1646
- * from its own configuration, so dropping a chain client-side would change the
1647
- * hash and the signature would be rejected everywhere.
1648
- * @private
1649
- */
1650
- private assertOwnerSafeOnSessionChains;
1651
1655
  private signSessionKey;
1652
1656
  /**
1653
1657
  * Patch the user's protocol selection on USDC, WETH, and EURC across all
@@ -3335,139 +3339,6 @@ declare function createBankrProvider(config: BankrProviderConfig): {
3335
3339
  };
3336
3340
  type BankrProvider = ReturnType<typeof createBankrProvider>;
3337
3341
 
3338
- /**
3339
- * EIP-1193 provider for a threshold-1 parent Safe.
3340
- *
3341
- * The owner is the wallet already connected by the integrator (viem wallet
3342
- * client, local account, or EIP-1193 provider). A 2-of-4 Safe connects through
3343
- * WalletConnect or the Safe App instead, because one signer cannot execute it.
3344
- */
3345
-
3346
- /**
3347
- * EIP-1193 wallet, such as an injected provider or WalletConnect.
3348
- */
3349
- interface SafeOwnerEip1193 {
3350
- /**
3351
- * JSON-RPC request on the owner wallet.
3352
- *
3353
- * @param args - Method and optional params.
3354
- * @returns The wallet's RPC result.
3355
- */
3356
- request: (args: {
3357
- method: string;
3358
- params?: readonly unknown[] | undefined;
3359
- }) => Promise<unknown>;
3360
- }
3361
- /**
3362
- * Owner wallet used to sign Safe hashes and pay gas for `execTransaction`.
3363
- * Pass the wallet the integrator already connected. A raw private key is not required.
3364
- */
3365
- type SafeOwnerWallet = Account | WalletClient | SafeOwnerEip1193;
3366
- /**
3367
- * Arguments for {@link createSafeOwnerProvider}.
3368
- *
3369
- * @remarks
3370
- * The Safe must be deployed on `chain` and its threshold must be 1. `owner` is
3371
- * that owner's existing wallet. For a 2-of-4 treasury, connect the Safe itself
3372
- * with WalletConnect or the Safe App and pass that provider to
3373
- * {@link ZyfaiSDK.connectAccount}. One signer cannot execute a 2-of-4.
3374
- */
3375
- interface SafeOwnerProviderConfig {
3376
- /**
3377
- * Parent Safe that becomes the connected account and the `userAddress` on
3378
- * `sendDeposit` and `withdrawFunds`.
3379
- */
3380
- safeAddress: Address$1;
3381
- /**
3382
- * Wallet of an owner of `safeAddress`. A viem wallet client, a local account,
3383
- * or an EIP-1193 provider. This wallet pays gas when the threshold is 1.
3384
- */
3385
- owner: SafeOwnerWallet;
3386
- /** Chain where `safeAddress` has contract code. A Safe on Ethereum is not usable on Base. */
3387
- chain: Chain;
3388
- }
3389
- /**
3390
- * EIP-1193 provider whose accounts are the parent Safe, not the owner EOA.
3391
- *
3392
- * @remarks
3393
- * `eth_requestAccounts` returns the Safe. `personal_sign` and
3394
- * `eth_signTypedData_v4` produce signatures the Safe accepts via `isValidSignature`.
3395
- * `eth_sendTransaction` calls `execTransaction` and waits for the receipt.
3396
- * Pass this object to {@link ZyfaiSDK.connectAccount}.
3397
- */
3398
- interface SafeOwnerProvider {
3399
- /**
3400
- * JSON-RPC entry used by viem when the SDK signs or sends.
3401
- *
3402
- * @param args - Method name (`eth_requestAccounts`, `personal_sign`, `eth_signTypedData_v4`, `eth_sendTransaction`) and optional params.
3403
- * @returns Accounts, a signature, or the executed transaction hash.
3404
- */
3405
- request: (args: {
3406
- method: string;
3407
- params?: readonly unknown[] | undefined;
3408
- }) => Promise<unknown>;
3409
- }
3410
- /**
3411
- * Create an EIP-1193 provider that signs and executes as a threshold-1 Safe.
3412
- *
3413
- * @remarks
3414
- * Pass the provider to {@link ZyfaiSDK.connectAccount}. The address it returns
3415
- * is the Safe. Pass that same address as `userAddress` on
3416
- * {@link ZyfaiSDK.sendDeposit} and {@link ZyfaiSDK.withdrawFunds}. Withdrawals
3417
- * settle to the Safe. The owner wallet pays gas for `execTransaction`.
3418
- *
3419
- * This helper is only for threshold 1. A 2-of-4 Safe (four owners, two
3420
- * signatures required) must be connected with WalletConnect or the Safe App.
3421
- * That wallet collects the second signature. `sendDeposit` then proposes the
3422
- * transfer from the parent Safe and polls Safe Transaction Service until the
3423
- * co-signers execute it. Do not pass one signer of a 2-of-4 to this function.
3424
- *
3425
- * @param config - Safe address, the owner wallet, and the chain where the Safe is deployed.
3426
- * @returns A provider whose account is `config.safeAddress`.
3427
- *
3428
- * @throws If `safeAddress` is not an address, or `owner` is not a wallet client, account, or EIP-1193 provider.
3429
- * @throws If the Safe has no code on `config.chain`. Choose the chain where the Safe was deployed.
3430
- * @throws If the threshold is above 1. Connect a 2-of-4 through its wallet provider.
3431
- * @throws If the wallet address is not an owner of the Safe.
3432
- * @throws If `isValidSignature` rejects the owner signature.
3433
- *
3434
- * @example
3435
- * ```typescript
3436
- * import { createSafeOwnerProvider, ZyfaiSDK } from "@zyfai/sdk";
3437
- * import { createWalletClient, custom } from "viem";
3438
- * import { base } from "viem/chains";
3439
- *
3440
- * // Threshold-1 Safe. `owner` is the wallet the user already connected.
3441
- * const owner = createWalletClient({
3442
- * chain: base,
3443
- * transport: custom(window.ethereum),
3444
- * });
3445
- * const provider = await createSafeOwnerProvider({
3446
- * safeAddress: "0xParentSafe",
3447
- * owner,
3448
- * chain: base,
3449
- * });
3450
- * const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
3451
- * const parent = await sdk.connectAccount(provider, 8453);
3452
- * const sent = await sdk.sendDeposit(parent, 8453, "100000", "USDC");
3453
- * await sdk.waitForDepositCredit(sent.registration.id, 8453);
3454
- * ```
3455
- *
3456
- * @example
3457
- * ```typescript
3458
- * // 2-of-4 treasury. Do not use createSafeOwnerProvider.
3459
- * // safeWalletProvider is WalletConnect or the Safe App, connected as the Safe.
3460
- * const parent = await sdk.connectAccount(safeWalletProvider, 1);
3461
- * const sent = await sdk.sendDeposit(parent, 1, "1000000", "USDC");
3462
- * // Returns after another owner executes the Safe transaction.
3463
- * await sdk.waitForDepositCredit(sent.registration.id, 1);
3464
- * ```
3465
- *
3466
- * @see ZyfaiSDK.connectAccount
3467
- * @see ZyfaiSDK.sendDeposit
3468
- */
3469
- declare function createSafeOwnerProvider(config: SafeOwnerProviderConfig): Promise<SafeOwnerProvider>;
3470
-
3471
3342
  /**
3472
3343
  * Assets the agent manages for pause, resume, first-deposit protocol setup,
3473
3344
  * and bulk strategy changes. Derived from {@link ASSET_CONFIGS} where
@@ -3623,4 +3494,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
3623
3494
  */
3624
3495
  declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
3625
3496
 
3626
- 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 SafeOwnerEip1193, type SafeOwnerProvider, type SafeOwnerProviderConfig, type SafeOwnerWallet, 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, createSafeOwnerProvider, decodeUserOperationCalls, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, hashUserOperationV07, hashV1SessionEnable, isSupportedChain, parseUserOperationJson, parseV1ChainSessions, resolveDepositRoute, resolveRelaySlippageBps, serializeV1ChainSessions, type staleBalances };
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 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Chain, PublicClient, Address as Address$1, Hex as Hex$1, Account, WalletClient } from 'viem';
1
+ import { Chain, PublicClient, Address as Address$1, Hex as Hex$1 } from 'viem';
2
2
  import { hashChainSessions } from '@rhinestone/module-sdk';
3
3
 
4
4
  /**
@@ -117,6 +117,8 @@ interface DeploySafeResponse {
117
117
  sessionKeyCreated?: boolean;
118
118
  }
119
119
  interface UpdateUserProfileRequest {
120
+ smartWallet?: Address;
121
+ executorProxy?: boolean;
120
122
  strategy?: string;
121
123
  protocols?: string[];
122
124
  autoSelectProtocols?: boolean;
@@ -1248,6 +1250,10 @@ declare class ZyfaiSDK {
1248
1250
  private sessionEoa;
1249
1251
  /** When set, profile writes use agent-accessible endpoints instead of PATCH /users/me. */
1250
1252
  private sessionChannel?;
1253
+ /** Serialize concurrent connectAccount calls (e.g. React StrictMode double mount). */
1254
+ private connectAccountInFlight;
1255
+ /** One SIWE prompt at a time. Register must not send a second personal_sign. */
1256
+ private authenticateUserInFlight;
1251
1257
  /**
1252
1258
  * Create an SDK instance with an existing Zyfai user JWT (no wallet connected).
1253
1259
  *
@@ -1330,6 +1336,7 @@ declare class ZyfaiSDK {
1330
1336
  * @returns Promise that resolves when authentication is complete
1331
1337
  */
1332
1338
  private authenticateUser;
1339
+ private performAuthenticateUser;
1333
1340
  /**
1334
1341
  * Update user profile with Smart Wallet address and chain configuration
1335
1342
  * This method requires SIWE authentication and is automatically called after deploySafe
@@ -1516,6 +1523,7 @@ declare class ZyfaiSDK {
1516
1523
  * const provider = await connector.getProvider();
1517
1524
  * await sdk.connectAccount(provider);
1518
1525
  */
1526
+ private resolveConnectAddress;
1519
1527
  connectAccount(account: string | any, chainId?: SupportedChainId): Promise<Address>;
1520
1528
  /**
1521
1529
  * Clear the connected wallet, SIWE session, and cached smart-wallet state.
@@ -1541,6 +1549,13 @@ declare class ZyfaiSDK {
1541
1549
  * @private
1542
1550
  */
1543
1551
  private isConnectedUser;
1552
+ /**
1553
+ * Nested Safe owners use intent sessions: finish any pending safe-deploy typed-data
1554
+ * (install or emissary enable), then register with chainId only.
1555
+ * @private
1556
+ */
1557
+ private registerNestedIntentSessionKey;
1558
+ private registerNestedChildProfile;
1544
1559
  /**
1545
1560
  * SIWE login sets predeployed. Agent sessions (`forUser`) do not, so read it
1546
1561
  * from the user record before allowing a transfer to an undeployed pool Safe.
@@ -1633,21 +1648,10 @@ declare class ZyfaiSDK {
1633
1648
  */
1634
1649
  createSessionKey(userAddress: string, chainId: SupportedChainId): Promise<SessionKeyResponse>;
1635
1650
  /**
1636
- * Internal method to sign session key
1651
+ * Internal method to sign session key for an EOA owner.
1652
+ * Nested Safe owners register through {@link registerNestedIntentSessionKey}.
1637
1653
  * @private
1638
1654
  */
1639
- /**
1640
- * A nested Safe owner signs one MultiChainSession covering every chain in the
1641
- * session configuration, and the child validates that signature against the
1642
- * owner through ERC-1271 on each of them. A chain where the owner has no code
1643
- * would accept the signature nowhere, so refuse rather than sign it.
1644
- *
1645
- * The session list is not filtered here: the execution API rebuilds the digest
1646
- * from its own configuration, so dropping a chain client-side would change the
1647
- * hash and the signature would be rejected everywhere.
1648
- * @private
1649
- */
1650
- private assertOwnerSafeOnSessionChains;
1651
1655
  private signSessionKey;
1652
1656
  /**
1653
1657
  * Patch the user's protocol selection on USDC, WETH, and EURC across all
@@ -3335,139 +3339,6 @@ declare function createBankrProvider(config: BankrProviderConfig): {
3335
3339
  };
3336
3340
  type BankrProvider = ReturnType<typeof createBankrProvider>;
3337
3341
 
3338
- /**
3339
- * EIP-1193 provider for a threshold-1 parent Safe.
3340
- *
3341
- * The owner is the wallet already connected by the integrator (viem wallet
3342
- * client, local account, or EIP-1193 provider). A 2-of-4 Safe connects through
3343
- * WalletConnect or the Safe App instead, because one signer cannot execute it.
3344
- */
3345
-
3346
- /**
3347
- * EIP-1193 wallet, such as an injected provider or WalletConnect.
3348
- */
3349
- interface SafeOwnerEip1193 {
3350
- /**
3351
- * JSON-RPC request on the owner wallet.
3352
- *
3353
- * @param args - Method and optional params.
3354
- * @returns The wallet's RPC result.
3355
- */
3356
- request: (args: {
3357
- method: string;
3358
- params?: readonly unknown[] | undefined;
3359
- }) => Promise<unknown>;
3360
- }
3361
- /**
3362
- * Owner wallet used to sign Safe hashes and pay gas for `execTransaction`.
3363
- * Pass the wallet the integrator already connected. A raw private key is not required.
3364
- */
3365
- type SafeOwnerWallet = Account | WalletClient | SafeOwnerEip1193;
3366
- /**
3367
- * Arguments for {@link createSafeOwnerProvider}.
3368
- *
3369
- * @remarks
3370
- * The Safe must be deployed on `chain` and its threshold must be 1. `owner` is
3371
- * that owner's existing wallet. For a 2-of-4 treasury, connect the Safe itself
3372
- * with WalletConnect or the Safe App and pass that provider to
3373
- * {@link ZyfaiSDK.connectAccount}. One signer cannot execute a 2-of-4.
3374
- */
3375
- interface SafeOwnerProviderConfig {
3376
- /**
3377
- * Parent Safe that becomes the connected account and the `userAddress` on
3378
- * `sendDeposit` and `withdrawFunds`.
3379
- */
3380
- safeAddress: Address$1;
3381
- /**
3382
- * Wallet of an owner of `safeAddress`. A viem wallet client, a local account,
3383
- * or an EIP-1193 provider. This wallet pays gas when the threshold is 1.
3384
- */
3385
- owner: SafeOwnerWallet;
3386
- /** Chain where `safeAddress` has contract code. A Safe on Ethereum is not usable on Base. */
3387
- chain: Chain;
3388
- }
3389
- /**
3390
- * EIP-1193 provider whose accounts are the parent Safe, not the owner EOA.
3391
- *
3392
- * @remarks
3393
- * `eth_requestAccounts` returns the Safe. `personal_sign` and
3394
- * `eth_signTypedData_v4` produce signatures the Safe accepts via `isValidSignature`.
3395
- * `eth_sendTransaction` calls `execTransaction` and waits for the receipt.
3396
- * Pass this object to {@link ZyfaiSDK.connectAccount}.
3397
- */
3398
- interface SafeOwnerProvider {
3399
- /**
3400
- * JSON-RPC entry used by viem when the SDK signs or sends.
3401
- *
3402
- * @param args - Method name (`eth_requestAccounts`, `personal_sign`, `eth_signTypedData_v4`, `eth_sendTransaction`) and optional params.
3403
- * @returns Accounts, a signature, or the executed transaction hash.
3404
- */
3405
- request: (args: {
3406
- method: string;
3407
- params?: readonly unknown[] | undefined;
3408
- }) => Promise<unknown>;
3409
- }
3410
- /**
3411
- * Create an EIP-1193 provider that signs and executes as a threshold-1 Safe.
3412
- *
3413
- * @remarks
3414
- * Pass the provider to {@link ZyfaiSDK.connectAccount}. The address it returns
3415
- * is the Safe. Pass that same address as `userAddress` on
3416
- * {@link ZyfaiSDK.sendDeposit} and {@link ZyfaiSDK.withdrawFunds}. Withdrawals
3417
- * settle to the Safe. The owner wallet pays gas for `execTransaction`.
3418
- *
3419
- * This helper is only for threshold 1. A 2-of-4 Safe (four owners, two
3420
- * signatures required) must be connected with WalletConnect or the Safe App.
3421
- * That wallet collects the second signature. `sendDeposit` then proposes the
3422
- * transfer from the parent Safe and polls Safe Transaction Service until the
3423
- * co-signers execute it. Do not pass one signer of a 2-of-4 to this function.
3424
- *
3425
- * @param config - Safe address, the owner wallet, and the chain where the Safe is deployed.
3426
- * @returns A provider whose account is `config.safeAddress`.
3427
- *
3428
- * @throws If `safeAddress` is not an address, or `owner` is not a wallet client, account, or EIP-1193 provider.
3429
- * @throws If the Safe has no code on `config.chain`. Choose the chain where the Safe was deployed.
3430
- * @throws If the threshold is above 1. Connect a 2-of-4 through its wallet provider.
3431
- * @throws If the wallet address is not an owner of the Safe.
3432
- * @throws If `isValidSignature` rejects the owner signature.
3433
- *
3434
- * @example
3435
- * ```typescript
3436
- * import { createSafeOwnerProvider, ZyfaiSDK } from "@zyfai/sdk";
3437
- * import { createWalletClient, custom } from "viem";
3438
- * import { base } from "viem/chains";
3439
- *
3440
- * // Threshold-1 Safe. `owner` is the wallet the user already connected.
3441
- * const owner = createWalletClient({
3442
- * chain: base,
3443
- * transport: custom(window.ethereum),
3444
- * });
3445
- * const provider = await createSafeOwnerProvider({
3446
- * safeAddress: "0xParentSafe",
3447
- * owner,
3448
- * chain: base,
3449
- * });
3450
- * const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
3451
- * const parent = await sdk.connectAccount(provider, 8453);
3452
- * const sent = await sdk.sendDeposit(parent, 8453, "100000", "USDC");
3453
- * await sdk.waitForDepositCredit(sent.registration.id, 8453);
3454
- * ```
3455
- *
3456
- * @example
3457
- * ```typescript
3458
- * // 2-of-4 treasury. Do not use createSafeOwnerProvider.
3459
- * // safeWalletProvider is WalletConnect or the Safe App, connected as the Safe.
3460
- * const parent = await sdk.connectAccount(safeWalletProvider, 1);
3461
- * const sent = await sdk.sendDeposit(parent, 1, "1000000", "USDC");
3462
- * // Returns after another owner executes the Safe transaction.
3463
- * await sdk.waitForDepositCredit(sent.registration.id, 1);
3464
- * ```
3465
- *
3466
- * @see ZyfaiSDK.connectAccount
3467
- * @see ZyfaiSDK.sendDeposit
3468
- */
3469
- declare function createSafeOwnerProvider(config: SafeOwnerProviderConfig): Promise<SafeOwnerProvider>;
3470
-
3471
3342
  /**
3472
3343
  * Assets the agent manages for pause, resume, first-deposit protocol setup,
3473
3344
  * and bulk strategy changes. Derived from {@link ASSET_CONFIGS} where
@@ -3623,4 +3494,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
3623
3494
  */
3624
3495
  declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
3625
3496
 
3626
- 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 SafeOwnerEip1193, type SafeOwnerProvider, type SafeOwnerProviderConfig, type SafeOwnerWallet, 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, createSafeOwnerProvider, decodeUserOperationCalls, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, hashUserOperationV07, hashV1SessionEnable, isSupportedChain, parseUserOperationJson, parseV1ChainSessions, resolveDepositRoute, resolveRelaySlippageBps, serializeV1ChainSessions, type staleBalances };
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 };