@zyfai/sdk 0.2.45 → 0.2.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1050,6 +1050,32 @@ declare class ZyfaiSDK {
1050
1050
  * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
1051
1051
  * ```
1052
1052
  */
1053
+ /**
1054
+ * Deploy the connected predeployed (pool) wallet on one or more chains.
1055
+ *
1056
+ * A pool wallet is only deployed on the chains it has been onboarded to (see
1057
+ * the `chains` array from getSmartWalletByEOA); every other supported chain is
1058
+ * counterfactual until deployed here. The backend deploys + rotates the same
1059
+ * address on each chain in parallel (sponsored, no user signature) and only
1060
+ * resolves once all requested chains have landed on-chain. Idempotent — chains
1061
+ * already deployed are a no-op.
1062
+ *
1063
+ * `depositFunds` calls this automatically when the target chain isn't deployed,
1064
+ * so most integrations never need it directly; use it to pre-provision chains.
1065
+ *
1066
+ * @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
1067
+ */
1068
+ deployOnChains(chainIds: SupportedChainId[]): Promise<{
1069
+ success: boolean;
1070
+ safeAddress: string;
1071
+ chains: number[];
1072
+ status: string;
1073
+ }>;
1074
+ /**
1075
+ * Poll until the Safe has code on-chain. The backend awaits landing before it
1076
+ * responds, so this only guards against read-after-write RPC lag.
1077
+ */
1078
+ private waitForSafeDeployed;
1053
1079
  depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1054
1080
  /**
1055
1081
  * Log a deposit that was executed client-side
package/dist/index.d.ts CHANGED
@@ -1050,6 +1050,32 @@ declare class ZyfaiSDK {
1050
1050
  * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
1051
1051
  * ```
1052
1052
  */
1053
+ /**
1054
+ * Deploy the connected predeployed (pool) wallet on one or more chains.
1055
+ *
1056
+ * A pool wallet is only deployed on the chains it has been onboarded to (see
1057
+ * the `chains` array from getSmartWalletByEOA); every other supported chain is
1058
+ * counterfactual until deployed here. The backend deploys + rotates the same
1059
+ * address on each chain in parallel (sponsored, no user signature) and only
1060
+ * resolves once all requested chains have landed on-chain. Idempotent — chains
1061
+ * already deployed are a no-op.
1062
+ *
1063
+ * `depositFunds` calls this automatically when the target chain isn't deployed,
1064
+ * so most integrations never need it directly; use it to pre-provision chains.
1065
+ *
1066
+ * @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
1067
+ */
1068
+ deployOnChains(chainIds: SupportedChainId[]): Promise<{
1069
+ success: boolean;
1070
+ safeAddress: string;
1071
+ chains: number[];
1072
+ status: string;
1073
+ }>;
1074
+ /**
1075
+ * Poll until the Safe has code on-chain. The backend awaits landing before it
1076
+ * responds, so this only guards against read-after-write RPC lag.
1077
+ */
1078
+ private waitForSafeDeployed;
1053
1079
  depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1054
1080
  /**
1055
1081
  * Log a deposit that was executed client-side
package/dist/index.js CHANGED
@@ -70,6 +70,9 @@ var ENDPOINTS = {
70
70
  LOG_DEPOSIT: "/users/log_deposit",
71
71
  // Safe Deployment (single endpoint)
72
72
  SAFE_DEPLOY: "/users/safe-deploy",
73
+ // Multichain deploy for predeployed (pool) wallets — deploys + rotates the
74
+ // same address on the requested chains (sponsored, no user signature).
75
+ DEPLOY_CHAINS: "/users/deploy-chains",
73
76
  // Session Keys
74
77
  SESSION_KEYS_CONFIG: "/session-keys/config",
75
78
  SESSION_KEYS_ADD: "/session-keys/add",
@@ -2134,6 +2137,42 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2134
2137
  * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
2135
2138
  * ```
2136
2139
  */
2140
+ /**
2141
+ * Deploy the connected predeployed (pool) wallet on one or more chains.
2142
+ *
2143
+ * A pool wallet is only deployed on the chains it has been onboarded to (see
2144
+ * the `chains` array from getSmartWalletByEOA); every other supported chain is
2145
+ * counterfactual until deployed here. The backend deploys + rotates the same
2146
+ * address on each chain in parallel (sponsored, no user signature) and only
2147
+ * resolves once all requested chains have landed on-chain. Idempotent — chains
2148
+ * already deployed are a no-op.
2149
+ *
2150
+ * `depositFunds` calls this automatically when the target chain isn't deployed,
2151
+ * so most integrations never need it directly; use it to pre-provision chains.
2152
+ *
2153
+ * @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
2154
+ */
2155
+ async deployOnChains(chainIds) {
2156
+ if (!chainIds?.length) {
2157
+ throw new Error("At least one chainId is required");
2158
+ }
2159
+ for (const c of chainIds) {
2160
+ if (!isSupportedChain(c)) throw new Error(`Unsupported chain ID: ${c}`);
2161
+ }
2162
+ await this.authenticateUser();
2163
+ return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
2164
+ }
2165
+ /**
2166
+ * Poll until the Safe has code on-chain. The backend awaits landing before it
2167
+ * responds, so this only guards against read-after-write RPC lag.
2168
+ */
2169
+ async waitForSafeDeployed(safeAddress, publicClient, tries = 5, delayMs = 2e3) {
2170
+ for (let i = 0; i < tries; i++) {
2171
+ if (await isSafeDeployed(safeAddress, publicClient)) return true;
2172
+ await new Promise((r) => setTimeout(r, delayMs));
2173
+ }
2174
+ return isSafeDeployed(safeAddress, publicClient);
2175
+ }
2137
2176
  async depositFunds(userAddress, chainId, amount, asset, strategy) {
2138
2177
  try {
2139
2178
  if (!userAddress) {
@@ -2170,9 +2209,22 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2170
2209
  chainConfig.publicClient
2171
2210
  );
2172
2211
  if (!isDeployed) {
2173
- throw new Error(
2174
- `Safe not available for ${userAddress} on chain ${chainId}.`
2175
- );
2212
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
2213
+ await this.deployOnChains([chainId]);
2214
+ const landed = await this.waitForSafeDeployed(
2215
+ safeAddress,
2216
+ chainConfig.publicClient
2217
+ );
2218
+ if (!landed) {
2219
+ throw new Error(
2220
+ `Safe deploy on chain ${chainId} for ${userAddress} did not land \u2014 retry the deposit.`
2221
+ );
2222
+ }
2223
+ } else {
2224
+ throw new Error(
2225
+ `Safe not available for ${userAddress} on chain ${chainId}.`
2226
+ );
2227
+ }
2176
2228
  }
2177
2229
  try {
2178
2230
  const usdcDetails = await this.getUserDetails("USDC");
package/dist/index.mjs CHANGED
@@ -18,6 +18,9 @@ var ENDPOINTS = {
18
18
  LOG_DEPOSIT: "/users/log_deposit",
19
19
  // Safe Deployment (single endpoint)
20
20
  SAFE_DEPLOY: "/users/safe-deploy",
21
+ // Multichain deploy for predeployed (pool) wallets — deploys + rotates the
22
+ // same address on the requested chains (sponsored, no user signature).
23
+ DEPLOY_CHAINS: "/users/deploy-chains",
21
24
  // Session Keys
22
25
  SESSION_KEYS_CONFIG: "/session-keys/config",
23
26
  SESSION_KEYS_ADD: "/session-keys/add",
@@ -2102,6 +2105,42 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2102
2105
  * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
2103
2106
  * ```
2104
2107
  */
2108
+ /**
2109
+ * Deploy the connected predeployed (pool) wallet on one or more chains.
2110
+ *
2111
+ * A pool wallet is only deployed on the chains it has been onboarded to (see
2112
+ * the `chains` array from getSmartWalletByEOA); every other supported chain is
2113
+ * counterfactual until deployed here. The backend deploys + rotates the same
2114
+ * address on each chain in parallel (sponsored, no user signature) and only
2115
+ * resolves once all requested chains have landed on-chain. Idempotent — chains
2116
+ * already deployed are a no-op.
2117
+ *
2118
+ * `depositFunds` calls this automatically when the target chain isn't deployed,
2119
+ * so most integrations never need it directly; use it to pre-provision chains.
2120
+ *
2121
+ * @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
2122
+ */
2123
+ async deployOnChains(chainIds) {
2124
+ if (!chainIds?.length) {
2125
+ throw new Error("At least one chainId is required");
2126
+ }
2127
+ for (const c of chainIds) {
2128
+ if (!isSupportedChain(c)) throw new Error(`Unsupported chain ID: ${c}`);
2129
+ }
2130
+ await this.authenticateUser();
2131
+ return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
2132
+ }
2133
+ /**
2134
+ * Poll until the Safe has code on-chain. The backend awaits landing before it
2135
+ * responds, so this only guards against read-after-write RPC lag.
2136
+ */
2137
+ async waitForSafeDeployed(safeAddress, publicClient, tries = 5, delayMs = 2e3) {
2138
+ for (let i = 0; i < tries; i++) {
2139
+ if (await isSafeDeployed(safeAddress, publicClient)) return true;
2140
+ await new Promise((r) => setTimeout(r, delayMs));
2141
+ }
2142
+ return isSafeDeployed(safeAddress, publicClient);
2143
+ }
2105
2144
  async depositFunds(userAddress, chainId, amount, asset, strategy) {
2106
2145
  try {
2107
2146
  if (!userAddress) {
@@ -2138,9 +2177,22 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2138
2177
  chainConfig.publicClient
2139
2178
  );
2140
2179
  if (!isDeployed) {
2141
- throw new Error(
2142
- `Safe not available for ${userAddress} on chain ${chainId}.`
2143
- );
2180
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
2181
+ await this.deployOnChains([chainId]);
2182
+ const landed = await this.waitForSafeDeployed(
2183
+ safeAddress,
2184
+ chainConfig.publicClient
2185
+ );
2186
+ if (!landed) {
2187
+ throw new Error(
2188
+ `Safe deploy on chain ${chainId} for ${userAddress} did not land \u2014 retry the deposit.`
2189
+ );
2190
+ }
2191
+ } else {
2192
+ throw new Error(
2193
+ `Safe not available for ${userAddress} on chain ${chainId}.`
2194
+ );
2195
+ }
2144
2196
  }
2145
2197
  try {
2146
2198
  const usdcDetails = await this.getUserDetails("USDC");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.45",
3
+ "version": "0.2.47",
4
4
  "description": "TypeScript SDK for Zyfai Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",