@zyfai/sdk 0.2.10 → 0.2.12

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
@@ -462,12 +462,39 @@ The SDK provides access to various analytics and data endpoints:
462
462
 
463
463
  #### Get User Details
464
464
 
465
+ Fetch complete authenticated user profile including smart wallet, chains, protocols, and all configuration settings:
466
+
465
467
  ```typescript
466
468
  const user = await sdk.getUserDetails();
469
+
467
470
  console.log("Smart Wallet:", user.user.smartWallet);
468
471
  console.log("Active Chains:", user.user.chains);
469
472
  console.log("Active Protocols:", user.user.protocols);
470
- ```
473
+ console.log("Strategy:", user.user.strategy); // "conservative" | "aggressive"
474
+ console.log("Has Active Session:", user.user.hasActiveSessionKey);
475
+
476
+ // Feature flags
477
+ console.log("Auto-compounding:", user.user.autocompounding);
478
+ console.log("Auto-select Protocols:", user.user.autoSelectProtocols);
479
+ console.log("Omni Account:", user.user.omniAccount);
480
+ console.log("Cross-chain Strategy:", user.user.crosschainStrategy);
481
+ console.log("Executor Proxy:", user.user.executorProxy);
482
+ console.log("Splitting:", user.user.splitting);
483
+ console.log("Min Splits:", user.user.minSplits);
484
+
485
+ // Optional fields
486
+ console.log("Email:", user.user.email);
487
+ console.log("Telegram ID:", user.user.telegramId);
488
+ console.log("Agent Name:", user.user.agentName);
489
+ console.log("Wallet Type:", user.user.walletType);
490
+ ```
491
+
492
+ **Available Fields:**
493
+ - **Core Info**: `id`, `address`, `smartWallet`, `chains`, `protocols`
494
+ - **Strategy**: `strategy` (conservative or aggressive)
495
+ - **Session**: `hasActiveSessionKey` (boolean)
496
+ - **Features**: `autocompounding`, `autoSelectProtocols`, `omniAccount`, `crosschainStrategy`, `executorProxy`, `splitting`, `minSplits`
497
+ - **Optional**: `email`, `telegramId`, `agentName`, `walletType`, `customization`, `registered`
471
498
 
472
499
  #### Pause Agent
473
500
 
@@ -726,7 +753,8 @@ All examples are available in the `examples/` directory:
726
753
  8. **`get-positions.ts`** - Get active positions for a wallet
727
754
  9. **`get-user-details.ts`** - Get authenticated user details
728
755
  10. **`pause-agent.ts`** - Pause agent by clearing all protocols
729
- 11. **`get-tvl-volume.ts`** - Get TVL and trading volume
756
+ 11. **`update-profile-with-protocols.ts`** - Configure user profile with protocols, chains, and advanced features
757
+ 12. **`get-tvl-volume.ts`** - Get TVL and trading volume
730
758
  12. **`get-active-wallets.ts`** - Get active wallets by chain
731
759
  13. **`get-smart-wallets-by-eoa.ts`** - Get smart wallets by EOA
732
760
  14. **`get-first-topup.ts`** - Get first deposit information
package/dist/index.d.mts CHANGED
@@ -28,9 +28,14 @@ interface UpdateUserProfileRequest {
28
28
  chains?: number[];
29
29
  protocols?: string[];
30
30
  autoSelectProtocols?: boolean;
31
- customization?: Record<string, string[]>;
31
+ omniAccount?: boolean;
32
+ autocompounding?: boolean;
33
+ agentName?: string;
34
+ crosschainStrategy?: boolean;
35
+ executorProxy?: boolean;
32
36
  splitting?: boolean;
33
37
  minSplits?: number;
38
+ customization?: Record<string, any>;
34
39
  }
35
40
  /** @internal */
36
41
  interface UpdateUserProfileResponse {
@@ -39,6 +44,16 @@ interface UpdateUserProfileResponse {
39
44
  smartWallet?: Address;
40
45
  chains?: number[];
41
46
  strategy?: string;
47
+ protocols?: string[];
48
+ autoSelectProtocols?: boolean;
49
+ omniAccount?: boolean;
50
+ autocompounding?: boolean;
51
+ agentName?: string;
52
+ crosschainStrategy?: boolean;
53
+ executorProxy?: boolean;
54
+ splitting?: boolean;
55
+ minSplits?: number;
56
+ customization?: Record<string, any>;
42
57
  }
43
58
  /** @internal */
44
59
  interface AddSessionKeyResponse {
@@ -143,9 +158,11 @@ interface UserDetails {
143
158
  omniAccount?: boolean;
144
159
  crosschainStrategy?: boolean;
145
160
  agentName?: string;
146
- customization?: Record<string, string[]>;
161
+ customization?: Record<string, any>;
162
+ executorProxy?: boolean;
147
163
  splitting?: boolean;
148
164
  minSplits?: number;
165
+ registered?: boolean;
149
166
  }
150
167
  interface UserDetailsResponse {
151
168
  success: boolean;
@@ -996,6 +1013,51 @@ declare class ZyfaiSDK {
996
1013
  * ```
997
1014
  */
998
1015
  getAggressiveOpportunities(chainId?: number): Promise<OpportunitiesResponse>;
1016
+ /**
1017
+ * Get active conservative opportunities (status = "live") with risk and utilization data
1018
+ * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
1019
+ *
1020
+ * @param chainId - Optional chain ID filter
1021
+ * @returns Active conservative opportunities with risk data
1022
+ *
1023
+ * @example
1024
+ * ```typescript
1025
+ * const opps = await sdk.getActiveConservativeOppsRisk(8453);
1026
+ * console.log(JSON.stringify(opps, null, 2));
1027
+ * ```
1028
+ */
1029
+ getActiveConservativeOppsRisk(chainId?: number): Promise<any>;
1030
+ /**
1031
+ * Get active aggressive opportunities (status = "live") with risk and utilization data
1032
+ * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
1033
+ *
1034
+ * @param chainId - Optional chain ID filter
1035
+ * @returns Active aggressive opportunities with risk data
1036
+ *
1037
+ * @example
1038
+ * ```typescript
1039
+ * const opps = await sdk.getActiveAggressiveOppsRisk(8453);
1040
+ * console.log(JSON.stringify(opps, null, 2));
1041
+ * ```
1042
+ */
1043
+ getActiveAggressiveOppsRisk(chainId?: number): Promise<any>;
1044
+ /**
1045
+ * Get conservative pool status with derived health, risk, APY trend, and yield consistency
1046
+ * Builds on getActiveConservativeOppsRisk and computes higher-level status indicators
1047
+ *
1048
+ * @param chainId - Optional chain ID filter
1049
+ * @returns Conservative pools with status data
1050
+ */
1051
+ getConservativePoolStatus(chainId?: number): Promise<any>;
1052
+ /**
1053
+ * Get aggressive pool status with derived health, risk, APY trend, and yield consistency
1054
+ * Builds on getActiveAggressiveOppsRisk and computes higher-level status indicators
1055
+ *
1056
+ * @param chainId - Optional chain ID filter
1057
+ * @returns Aggressive pools with status data
1058
+ */
1059
+ getAggressivePoolStatus(chainId?: number): Promise<any>;
1060
+ private derivePoolStatus;
999
1061
  /**
1000
1062
  * Get daily APY history with weighted average for a wallet
1001
1063
  *
package/dist/index.d.ts CHANGED
@@ -28,9 +28,14 @@ interface UpdateUserProfileRequest {
28
28
  chains?: number[];
29
29
  protocols?: string[];
30
30
  autoSelectProtocols?: boolean;
31
- customization?: Record<string, string[]>;
31
+ omniAccount?: boolean;
32
+ autocompounding?: boolean;
33
+ agentName?: string;
34
+ crosschainStrategy?: boolean;
35
+ executorProxy?: boolean;
32
36
  splitting?: boolean;
33
37
  minSplits?: number;
38
+ customization?: Record<string, any>;
34
39
  }
35
40
  /** @internal */
36
41
  interface UpdateUserProfileResponse {
@@ -39,6 +44,16 @@ interface UpdateUserProfileResponse {
39
44
  smartWallet?: Address;
40
45
  chains?: number[];
41
46
  strategy?: string;
47
+ protocols?: string[];
48
+ autoSelectProtocols?: boolean;
49
+ omniAccount?: boolean;
50
+ autocompounding?: boolean;
51
+ agentName?: string;
52
+ crosschainStrategy?: boolean;
53
+ executorProxy?: boolean;
54
+ splitting?: boolean;
55
+ minSplits?: number;
56
+ customization?: Record<string, any>;
42
57
  }
43
58
  /** @internal */
44
59
  interface AddSessionKeyResponse {
@@ -143,9 +158,11 @@ interface UserDetails {
143
158
  omniAccount?: boolean;
144
159
  crosschainStrategy?: boolean;
145
160
  agentName?: string;
146
- customization?: Record<string, string[]>;
161
+ customization?: Record<string, any>;
162
+ executorProxy?: boolean;
147
163
  splitting?: boolean;
148
164
  minSplits?: number;
165
+ registered?: boolean;
149
166
  }
150
167
  interface UserDetailsResponse {
151
168
  success: boolean;
@@ -996,6 +1013,51 @@ declare class ZyfaiSDK {
996
1013
  * ```
997
1014
  */
998
1015
  getAggressiveOpportunities(chainId?: number): Promise<OpportunitiesResponse>;
1016
+ /**
1017
+ * Get active conservative opportunities (status = "live") with risk and utilization data
1018
+ * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
1019
+ *
1020
+ * @param chainId - Optional chain ID filter
1021
+ * @returns Active conservative opportunities with risk data
1022
+ *
1023
+ * @example
1024
+ * ```typescript
1025
+ * const opps = await sdk.getActiveConservativeOppsRisk(8453);
1026
+ * console.log(JSON.stringify(opps, null, 2));
1027
+ * ```
1028
+ */
1029
+ getActiveConservativeOppsRisk(chainId?: number): Promise<any>;
1030
+ /**
1031
+ * Get active aggressive opportunities (status = "live") with risk and utilization data
1032
+ * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
1033
+ *
1034
+ * @param chainId - Optional chain ID filter
1035
+ * @returns Active aggressive opportunities with risk data
1036
+ *
1037
+ * @example
1038
+ * ```typescript
1039
+ * const opps = await sdk.getActiveAggressiveOppsRisk(8453);
1040
+ * console.log(JSON.stringify(opps, null, 2));
1041
+ * ```
1042
+ */
1043
+ getActiveAggressiveOppsRisk(chainId?: number): Promise<any>;
1044
+ /**
1045
+ * Get conservative pool status with derived health, risk, APY trend, and yield consistency
1046
+ * Builds on getActiveConservativeOppsRisk and computes higher-level status indicators
1047
+ *
1048
+ * @param chainId - Optional chain ID filter
1049
+ * @returns Conservative pools with status data
1050
+ */
1051
+ getConservativePoolStatus(chainId?: number): Promise<any>;
1052
+ /**
1053
+ * Get aggressive pool status with derived health, risk, APY trend, and yield consistency
1054
+ * Builds on getActiveAggressiveOppsRisk and computes higher-level status indicators
1055
+ *
1056
+ * @param chainId - Optional chain ID filter
1057
+ * @returns Aggressive pools with status data
1058
+ */
1059
+ getAggressivePoolStatus(chainId?: number): Promise<any>;
1060
+ private derivePoolStatus;
999
1061
  /**
1000
1062
  * Get daily APY history with weighted average for a wallet
1001
1063
  *
package/dist/index.js CHANGED
@@ -794,7 +794,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
794
794
  userId: response.userId || response.id,
795
795
  smartWallet: response.smartWallet,
796
796
  chains: response.chains,
797
- strategy: response.strategy
797
+ strategy: response.strategy,
798
+ protocols: response.protocols,
799
+ autoSelectProtocols: response.autoSelectProtocols,
800
+ omniAccount: response.omniAccount,
801
+ autocompounding: response.autocompounding,
802
+ agentName: response.agentName,
803
+ crosschainStrategy: response.crosschainStrategy,
804
+ executorProxy: response.executorProxy,
805
+ splitting: response.splitting,
806
+ minSplits: response.minSplits,
807
+ customization: response.customization
798
808
  };
799
809
  } catch (error) {
800
810
  throw new Error(
@@ -1750,8 +1760,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1750
1760
  crosschainStrategy: convertedResponse.crosschainStrategy,
1751
1761
  agentName: convertedResponse.agentName,
1752
1762
  customization: convertedResponse.customization,
1763
+ executorProxy: convertedResponse.executorProxy,
1753
1764
  splitting: convertedResponse.splitting,
1754
- minSplits: convertedResponse.minSplits
1765
+ minSplits: convertedResponse.minSplits,
1766
+ registered: convertedResponse.registered
1755
1767
  }
1756
1768
  };
1757
1769
  } catch (error) {
@@ -2249,6 +2261,156 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2249
2261
  );
2250
2262
  }
2251
2263
  }
2264
+ /**
2265
+ * Get active conservative opportunities (status = "live") with risk and utilization data
2266
+ * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
2267
+ *
2268
+ * @param chainId - Optional chain ID filter
2269
+ * @returns Active conservative opportunities with risk data
2270
+ *
2271
+ * @example
2272
+ * ```typescript
2273
+ * const opps = await sdk.getActiveConservativeOppsRisk(8453);
2274
+ * console.log(JSON.stringify(opps, null, 2));
2275
+ * ```
2276
+ */
2277
+ async getActiveConservativeOppsRisk(chainId) {
2278
+ try {
2279
+ const response = await this.httpClient.dataGet(
2280
+ DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
2281
+ );
2282
+ const data = response.data || response || [];
2283
+ const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
2284
+ const tvl = o.tvl || 0;
2285
+ const liquidity = o.liquidity || 0;
2286
+ const utilizationRate = tvl > 0 ? (tvl - liquidity) / tvl : 0;
2287
+ return {
2288
+ poolName: o.pool_name,
2289
+ protocolName: o.protocol_name,
2290
+ chainId: o.chain_id,
2291
+ liquidityDepth: liquidity > 1e7 ? "deep" : liquidity > 1e6 ? "moderate" : "shallow",
2292
+ utilizationRate: Math.round(utilizationRate * 1e4) / 100,
2293
+ tvlStability: o.isTvlStable ?? null,
2294
+ apyStability: o.isApyStable30Days ?? null,
2295
+ tvlApyCombinedRisk: o.isApyTvlStable ?? null,
2296
+ avgCombinedApy7d: o.averageCombinedApy7Days ?? null,
2297
+ avgCombinedApy15d: o.averageCombinedApy15Days ?? null,
2298
+ avgCombinedApy30d: o.averageCombinedApy30Days ?? null,
2299
+ collateralSymbols: o.collateral_symbols || []
2300
+ };
2301
+ }) : [];
2302
+ return active;
2303
+ } catch (error) {
2304
+ throw new Error(
2305
+ `Failed to get active conservative opportunities risk: ${error.message}`
2306
+ );
2307
+ }
2308
+ }
2309
+ /**
2310
+ * Get active aggressive opportunities (status = "live") with risk and utilization data
2311
+ * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
2312
+ *
2313
+ * @param chainId - Optional chain ID filter
2314
+ * @returns Active aggressive opportunities with risk data
2315
+ *
2316
+ * @example
2317
+ * ```typescript
2318
+ * const opps = await sdk.getActiveAggressiveOppsRisk(8453);
2319
+ * console.log(JSON.stringify(opps, null, 2));
2320
+ * ```
2321
+ */
2322
+ async getActiveAggressiveOppsRisk(chainId) {
2323
+ try {
2324
+ const response = await this.httpClient.dataGet(
2325
+ DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
2326
+ );
2327
+ const data = response.data || response || [];
2328
+ const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
2329
+ const tvl = o.tvl || 0;
2330
+ const liquidity = o.liquidity || 0;
2331
+ const utilizationRate = tvl > 0 ? (tvl - liquidity) / tvl : 0;
2332
+ return {
2333
+ poolName: o.pool_name,
2334
+ protocolName: o.protocol_name,
2335
+ chainId: o.chain_id,
2336
+ liquidityDepth: liquidity > 1e7 ? "deep" : liquidity > 1e6 ? "moderate" : "shallow",
2337
+ utilizationRate: Math.round(utilizationRate * 1e4) / 100,
2338
+ tvlStability: o.isTvlStable ?? null,
2339
+ apyStability: o.isApyStable30Days ?? null,
2340
+ tvlApyCombinedRisk: o.isApyTvlStable ?? null,
2341
+ avgCombinedApy7d: o.averageCombinedApy7Days ?? null,
2342
+ avgCombinedApy15d: o.averageCombinedApy15Days ?? null,
2343
+ avgCombinedApy30d: o.averageCombinedApy30Days ?? null,
2344
+ collateralSymbols: o.collateral_symbols || []
2345
+ };
2346
+ }) : [];
2347
+ return active;
2348
+ } catch (error) {
2349
+ throw new Error(
2350
+ `Failed to get active aggressive opportunities risk: ${error.message}`
2351
+ );
2352
+ }
2353
+ }
2354
+ /**
2355
+ * Get conservative pool status with derived health, risk, APY trend, and yield consistency
2356
+ * Builds on getActiveConservativeOppsRisk and computes higher-level status indicators
2357
+ *
2358
+ * @param chainId - Optional chain ID filter
2359
+ * @returns Conservative pools with status data
2360
+ */
2361
+ async getConservativePoolStatus(chainId) {
2362
+ const pools = await this.getActiveConservativeOppsRisk(chainId);
2363
+ return pools.map((p) => this.derivePoolStatus(p));
2364
+ }
2365
+ /**
2366
+ * Get aggressive pool status with derived health, risk, APY trend, and yield consistency
2367
+ * Builds on getActiveAggressiveOppsRisk and computes higher-level status indicators
2368
+ *
2369
+ * @param chainId - Optional chain ID filter
2370
+ * @returns Aggressive pools with status data
2371
+ */
2372
+ async getAggressivePoolStatus(chainId) {
2373
+ const pools = await this.getActiveAggressiveOppsRisk(chainId);
2374
+ return pools.map((p) => this.derivePoolStatus(p));
2375
+ }
2376
+ derivePoolStatus(p) {
2377
+ let riskSignals = 0;
2378
+ if (p.tvlStability === false) riskSignals++;
2379
+ if (p.apyStability === false) riskSignals++;
2380
+ if (p.tvlApyCombinedRisk === false) riskSignals++;
2381
+ if (p.liquidityDepth === "shallow") riskSignals++;
2382
+ if (p.utilizationRate > 90) riskSignals++;
2383
+ const riskLevel = riskSignals >= 3 ? "high" : riskSignals >= 1 ? "medium" : "low";
2384
+ const stabilityScore = (p.tvlStability === true ? 1 : 0) + (p.apyStability === true ? 1 : 0) + (p.tvlApyCombinedRisk === true ? 1 : 0);
2385
+ const liquidityBonus = p.liquidityDepth === "deep" ? 1 : p.liquidityDepth === "moderate" ? 0.5 : 0;
2386
+ const healthTotal = stabilityScore + liquidityBonus;
2387
+ const healthScore = healthTotal >= 3 ? "healthy" : healthTotal >= 1.5 ? "moderate" : "risky";
2388
+ const apy7d = p.avgCombinedApy7d;
2389
+ const apy30d = p.avgCombinedApy30d;
2390
+ let apyTrend = "stable";
2391
+ if (apy7d != null && apy30d != null && apy30d !== 0) {
2392
+ const change = (apy7d - apy30d) / apy30d;
2393
+ if (change > 0.1) apyTrend = "rising";
2394
+ else if (change < -0.1) apyTrend = "falling";
2395
+ }
2396
+ let yieldConsistency = "consistent";
2397
+ if (apy7d != null && apy30d != null && apy30d !== 0) {
2398
+ const spread = Math.abs(apy7d - apy30d) / apy30d;
2399
+ if (spread > 0.3) yieldConsistency = "volatile";
2400
+ else if (spread > 0.1) yieldConsistency = "mixed";
2401
+ }
2402
+ return {
2403
+ poolName: p.poolName,
2404
+ protocolName: p.protocolName,
2405
+ chainId: p.chainId,
2406
+ healthScore,
2407
+ riskLevel,
2408
+ apyTrend,
2409
+ yieldConsistency,
2410
+ liquidityDepth: p.liquidityDepth,
2411
+ avgCombinedApy7d: p.avgCombinedApy7d
2412
+ };
2413
+ }
2252
2414
  // ============================================================================
2253
2415
  // APY History Methods (Data API v2)
2254
2416
  // ============================================================================
package/dist/index.mjs CHANGED
@@ -772,7 +772,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
772
772
  userId: response.userId || response.id,
773
773
  smartWallet: response.smartWallet,
774
774
  chains: response.chains,
775
- strategy: response.strategy
775
+ strategy: response.strategy,
776
+ protocols: response.protocols,
777
+ autoSelectProtocols: response.autoSelectProtocols,
778
+ omniAccount: response.omniAccount,
779
+ autocompounding: response.autocompounding,
780
+ agentName: response.agentName,
781
+ crosschainStrategy: response.crosschainStrategy,
782
+ executorProxy: response.executorProxy,
783
+ splitting: response.splitting,
784
+ minSplits: response.minSplits,
785
+ customization: response.customization
776
786
  };
777
787
  } catch (error) {
778
788
  throw new Error(
@@ -1728,8 +1738,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1728
1738
  crosschainStrategy: convertedResponse.crosschainStrategy,
1729
1739
  agentName: convertedResponse.agentName,
1730
1740
  customization: convertedResponse.customization,
1741
+ executorProxy: convertedResponse.executorProxy,
1731
1742
  splitting: convertedResponse.splitting,
1732
- minSplits: convertedResponse.minSplits
1743
+ minSplits: convertedResponse.minSplits,
1744
+ registered: convertedResponse.registered
1733
1745
  }
1734
1746
  };
1735
1747
  } catch (error) {
@@ -2227,6 +2239,156 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2227
2239
  );
2228
2240
  }
2229
2241
  }
2242
+ /**
2243
+ * Get active conservative opportunities (status = "live") with risk and utilization data
2244
+ * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
2245
+ *
2246
+ * @param chainId - Optional chain ID filter
2247
+ * @returns Active conservative opportunities with risk data
2248
+ *
2249
+ * @example
2250
+ * ```typescript
2251
+ * const opps = await sdk.getActiveConservativeOppsRisk(8453);
2252
+ * console.log(JSON.stringify(opps, null, 2));
2253
+ * ```
2254
+ */
2255
+ async getActiveConservativeOppsRisk(chainId) {
2256
+ try {
2257
+ const response = await this.httpClient.dataGet(
2258
+ DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
2259
+ );
2260
+ const data = response.data || response || [];
2261
+ const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
2262
+ const tvl = o.tvl || 0;
2263
+ const liquidity = o.liquidity || 0;
2264
+ const utilizationRate = tvl > 0 ? (tvl - liquidity) / tvl : 0;
2265
+ return {
2266
+ poolName: o.pool_name,
2267
+ protocolName: o.protocol_name,
2268
+ chainId: o.chain_id,
2269
+ liquidityDepth: liquidity > 1e7 ? "deep" : liquidity > 1e6 ? "moderate" : "shallow",
2270
+ utilizationRate: Math.round(utilizationRate * 1e4) / 100,
2271
+ tvlStability: o.isTvlStable ?? null,
2272
+ apyStability: o.isApyStable30Days ?? null,
2273
+ tvlApyCombinedRisk: o.isApyTvlStable ?? null,
2274
+ avgCombinedApy7d: o.averageCombinedApy7Days ?? null,
2275
+ avgCombinedApy15d: o.averageCombinedApy15Days ?? null,
2276
+ avgCombinedApy30d: o.averageCombinedApy30Days ?? null,
2277
+ collateralSymbols: o.collateral_symbols || []
2278
+ };
2279
+ }) : [];
2280
+ return active;
2281
+ } catch (error) {
2282
+ throw new Error(
2283
+ `Failed to get active conservative opportunities risk: ${error.message}`
2284
+ );
2285
+ }
2286
+ }
2287
+ /**
2288
+ * Get active aggressive opportunities (status = "live") with risk and utilization data
2289
+ * Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
2290
+ *
2291
+ * @param chainId - Optional chain ID filter
2292
+ * @returns Active aggressive opportunities with risk data
2293
+ *
2294
+ * @example
2295
+ * ```typescript
2296
+ * const opps = await sdk.getActiveAggressiveOppsRisk(8453);
2297
+ * console.log(JSON.stringify(opps, null, 2));
2298
+ * ```
2299
+ */
2300
+ async getActiveAggressiveOppsRisk(chainId) {
2301
+ try {
2302
+ const response = await this.httpClient.dataGet(
2303
+ DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
2304
+ );
2305
+ const data = response.data || response || [];
2306
+ const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
2307
+ const tvl = o.tvl || 0;
2308
+ const liquidity = o.liquidity || 0;
2309
+ const utilizationRate = tvl > 0 ? (tvl - liquidity) / tvl : 0;
2310
+ return {
2311
+ poolName: o.pool_name,
2312
+ protocolName: o.protocol_name,
2313
+ chainId: o.chain_id,
2314
+ liquidityDepth: liquidity > 1e7 ? "deep" : liquidity > 1e6 ? "moderate" : "shallow",
2315
+ utilizationRate: Math.round(utilizationRate * 1e4) / 100,
2316
+ tvlStability: o.isTvlStable ?? null,
2317
+ apyStability: o.isApyStable30Days ?? null,
2318
+ tvlApyCombinedRisk: o.isApyTvlStable ?? null,
2319
+ avgCombinedApy7d: o.averageCombinedApy7Days ?? null,
2320
+ avgCombinedApy15d: o.averageCombinedApy15Days ?? null,
2321
+ avgCombinedApy30d: o.averageCombinedApy30Days ?? null,
2322
+ collateralSymbols: o.collateral_symbols || []
2323
+ };
2324
+ }) : [];
2325
+ return active;
2326
+ } catch (error) {
2327
+ throw new Error(
2328
+ `Failed to get active aggressive opportunities risk: ${error.message}`
2329
+ );
2330
+ }
2331
+ }
2332
+ /**
2333
+ * Get conservative pool status with derived health, risk, APY trend, and yield consistency
2334
+ * Builds on getActiveConservativeOppsRisk and computes higher-level status indicators
2335
+ *
2336
+ * @param chainId - Optional chain ID filter
2337
+ * @returns Conservative pools with status data
2338
+ */
2339
+ async getConservativePoolStatus(chainId) {
2340
+ const pools = await this.getActiveConservativeOppsRisk(chainId);
2341
+ return pools.map((p) => this.derivePoolStatus(p));
2342
+ }
2343
+ /**
2344
+ * Get aggressive pool status with derived health, risk, APY trend, and yield consistency
2345
+ * Builds on getActiveAggressiveOppsRisk and computes higher-level status indicators
2346
+ *
2347
+ * @param chainId - Optional chain ID filter
2348
+ * @returns Aggressive pools with status data
2349
+ */
2350
+ async getAggressivePoolStatus(chainId) {
2351
+ const pools = await this.getActiveAggressiveOppsRisk(chainId);
2352
+ return pools.map((p) => this.derivePoolStatus(p));
2353
+ }
2354
+ derivePoolStatus(p) {
2355
+ let riskSignals = 0;
2356
+ if (p.tvlStability === false) riskSignals++;
2357
+ if (p.apyStability === false) riskSignals++;
2358
+ if (p.tvlApyCombinedRisk === false) riskSignals++;
2359
+ if (p.liquidityDepth === "shallow") riskSignals++;
2360
+ if (p.utilizationRate > 90) riskSignals++;
2361
+ const riskLevel = riskSignals >= 3 ? "high" : riskSignals >= 1 ? "medium" : "low";
2362
+ const stabilityScore = (p.tvlStability === true ? 1 : 0) + (p.apyStability === true ? 1 : 0) + (p.tvlApyCombinedRisk === true ? 1 : 0);
2363
+ const liquidityBonus = p.liquidityDepth === "deep" ? 1 : p.liquidityDepth === "moderate" ? 0.5 : 0;
2364
+ const healthTotal = stabilityScore + liquidityBonus;
2365
+ const healthScore = healthTotal >= 3 ? "healthy" : healthTotal >= 1.5 ? "moderate" : "risky";
2366
+ const apy7d = p.avgCombinedApy7d;
2367
+ const apy30d = p.avgCombinedApy30d;
2368
+ let apyTrend = "stable";
2369
+ if (apy7d != null && apy30d != null && apy30d !== 0) {
2370
+ const change = (apy7d - apy30d) / apy30d;
2371
+ if (change > 0.1) apyTrend = "rising";
2372
+ else if (change < -0.1) apyTrend = "falling";
2373
+ }
2374
+ let yieldConsistency = "consistent";
2375
+ if (apy7d != null && apy30d != null && apy30d !== 0) {
2376
+ const spread = Math.abs(apy7d - apy30d) / apy30d;
2377
+ if (spread > 0.3) yieldConsistency = "volatile";
2378
+ else if (spread > 0.1) yieldConsistency = "mixed";
2379
+ }
2380
+ return {
2381
+ poolName: p.poolName,
2382
+ protocolName: p.protocolName,
2383
+ chainId: p.chainId,
2384
+ healthScore,
2385
+ riskLevel,
2386
+ apyTrend,
2387
+ yieldConsistency,
2388
+ liquidityDepth: p.liquidityDepth,
2389
+ avgCombinedApy7d: p.avgCombinedApy7d
2390
+ };
2391
+ }
2230
2392
  // ============================================================================
2231
2393
  // APY History Methods (Data API v2)
2232
2394
  // ============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
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",