@zyfai/sdk 0.2.15 → 0.2.17

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
@@ -14,6 +14,7 @@ interface RpcUrlsConfig {
14
14
  interface SDKConfig {
15
15
  apiKey: string;
16
16
  rpcUrls?: RpcUrlsConfig;
17
+ referralSource?: string;
17
18
  }
18
19
  interface DeploySafeResponse {
19
20
  success: boolean;
@@ -349,7 +350,8 @@ interface DailyApyHistoryResponse {
349
350
  history: Record<string, DailyApyEntry>;
350
351
  totalDays: number;
351
352
  requestedDays?: number;
352
- averageWeightedApy?: number;
353
+ weightedApyWithRzfiAfterFee?: number;
354
+ weightedApyAfterFee?: number;
353
355
  }
354
356
  interface RebalanceFrequencyResponse {
355
357
  success: boolean;
@@ -531,6 +533,7 @@ declare class ZyfaiSDK {
531
533
  private currentProvider;
532
534
  private currentChainId;
533
535
  private rpcUrls?;
536
+ private referralSource?;
534
537
  constructor(config: SDKConfig | string);
535
538
  /**
536
539
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
@@ -575,6 +578,25 @@ declare class ZyfaiSDK {
575
578
  * ```
576
579
  */
577
580
  pauseAgent(): Promise<UpdateUserProfileResponse>;
581
+ /**
582
+ * Pause the agent by clearing all protocols
583
+ * Sets the user's protocols to an empty array, effectively pausing automated operations
584
+ *
585
+ * @returns Response indicating success and updated user details
586
+ *
587
+ * @example
588
+ * ```typescript
589
+ * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
590
+ *
591
+ * // Connect account first
592
+ * await sdk.connectAccount();
593
+ *
594
+ * // Pause the agent
595
+ * const result = await sdk.pauseAgent();
596
+ * console.log('Agent paused:', result.success);
597
+ * ```
598
+ */
599
+ resumeAgent(): Promise<UpdateUserProfileResponse>;
578
600
  /**
579
601
  * Enable splitting for the user's account
580
602
  * When enabled, deposits are split across multiple protocols based on minSplits setting
@@ -1142,32 +1164,6 @@ declare class ZyfaiSDK {
1142
1164
  * ```
1143
1165
  */
1144
1166
  getSdkKeyTVL(): Promise<SdkKeyTVLResponse>;
1145
- /**
1146
- * Get the best yield opportunity for a registered wallet.
1147
- *
1148
- * Returns the highest-APY opportunity available based on the wallet's strategy
1149
- * and enabled protocols. This reflects what the rebalance engine would select.
1150
- *
1151
- * @param walletAddress - The smart wallet address (must be registered)
1152
- * @param chainId - The chain ID to check opportunities on
1153
- * @returns Best opportunity details with comparison to current position
1154
- *
1155
- * @example
1156
- * ```typescript
1157
- * const result = await sdk.getBestOpportunity(walletAddress, 8453);
1158
- *
1159
- * console.log("Current position:", result.currentPosition);
1160
- * console.log("Best opportunity:", result.bestOpportunity);
1161
- * console.log("Should rebalance:", result.shouldRebalance);
1162
- * console.log("APY improvement:", result.apyImprovement);
1163
- *
1164
- * // List all available opportunities
1165
- * result.allOpportunities?.forEach(opp => {
1166
- * console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}%`);
1167
- * });
1168
- * ```
1169
- */
1170
- getBestOpportunity(walletAddress: Address, chainId: SupportedChainId): Promise<BestOpportunityResponse>;
1171
1167
  /**
1172
1168
  * Configure protocol and pool customizations in batch.
1173
1169
  *
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ interface RpcUrlsConfig {
14
14
  interface SDKConfig {
15
15
  apiKey: string;
16
16
  rpcUrls?: RpcUrlsConfig;
17
+ referralSource?: string;
17
18
  }
18
19
  interface DeploySafeResponse {
19
20
  success: boolean;
@@ -349,7 +350,8 @@ interface DailyApyHistoryResponse {
349
350
  history: Record<string, DailyApyEntry>;
350
351
  totalDays: number;
351
352
  requestedDays?: number;
352
- averageWeightedApy?: number;
353
+ weightedApyWithRzfiAfterFee?: number;
354
+ weightedApyAfterFee?: number;
353
355
  }
354
356
  interface RebalanceFrequencyResponse {
355
357
  success: boolean;
@@ -531,6 +533,7 @@ declare class ZyfaiSDK {
531
533
  private currentProvider;
532
534
  private currentChainId;
533
535
  private rpcUrls?;
536
+ private referralSource?;
534
537
  constructor(config: SDKConfig | string);
535
538
  /**
536
539
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
@@ -575,6 +578,25 @@ declare class ZyfaiSDK {
575
578
  * ```
576
579
  */
577
580
  pauseAgent(): Promise<UpdateUserProfileResponse>;
581
+ /**
582
+ * Pause the agent by clearing all protocols
583
+ * Sets the user's protocols to an empty array, effectively pausing automated operations
584
+ *
585
+ * @returns Response indicating success and updated user details
586
+ *
587
+ * @example
588
+ * ```typescript
589
+ * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
590
+ *
591
+ * // Connect account first
592
+ * await sdk.connectAccount();
593
+ *
594
+ * // Pause the agent
595
+ * const result = await sdk.pauseAgent();
596
+ * console.log('Agent paused:', result.success);
597
+ * ```
598
+ */
599
+ resumeAgent(): Promise<UpdateUserProfileResponse>;
578
600
  /**
579
601
  * Enable splitting for the user's account
580
602
  * When enabled, deposits are split across multiple protocols based on minSplits setting
@@ -1142,32 +1164,6 @@ declare class ZyfaiSDK {
1142
1164
  * ```
1143
1165
  */
1144
1166
  getSdkKeyTVL(): Promise<SdkKeyTVLResponse>;
1145
- /**
1146
- * Get the best yield opportunity for a registered wallet.
1147
- *
1148
- * Returns the highest-APY opportunity available based on the wallet's strategy
1149
- * and enabled protocols. This reflects what the rebalance engine would select.
1150
- *
1151
- * @param walletAddress - The smart wallet address (must be registered)
1152
- * @param chainId - The chain ID to check opportunities on
1153
- * @returns Best opportunity details with comparison to current position
1154
- *
1155
- * @example
1156
- * ```typescript
1157
- * const result = await sdk.getBestOpportunity(walletAddress, 8453);
1158
- *
1159
- * console.log("Current position:", result.currentPosition);
1160
- * console.log("Best opportunity:", result.bestOpportunity);
1161
- * console.log("Should rebalance:", result.shouldRebalance);
1162
- * console.log("APY improvement:", result.apyImprovement);
1163
- *
1164
- * // List all available opportunities
1165
- * result.allOpportunities?.forEach(opp => {
1166
- * console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}%`);
1167
- * });
1168
- * ```
1169
- */
1170
- getBestOpportunity(walletAddress: Address, chainId: SupportedChainId): Promise<BestOpportunityResponse>;
1171
1167
  /**
1172
1168
  * Configure protocol and pool customizations in batch.
1173
1169
  *
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ var ENDPOINTS = {
62
62
  SESSION_KEYS_CONFIG: "/session-keys/config",
63
63
  SESSION_KEYS_ADD: "/session-keys/add",
64
64
  // Protocols
65
- PROTOCOLS: (chainId) => `/protocols?chainId=${chainId}`,
65
+ PROTOCOLS: (chainId) => chainId ? `/protocols?chainId=${chainId}` : "/protocols",
66
66
  // Data (v1)
67
67
  DATA_POSITION: (walletAddress) => `/data/position?walletAddress=${walletAddress}`,
68
68
  DATA_HISTORY: (walletAddress, chainId) => `/data/history?walletAddress=${walletAddress}&chainId=${chainId}`,
@@ -75,8 +75,6 @@ var ENDPOINTS = {
75
75
  // SDK Keys
76
76
  SDK_ALLOWED_WALLETS: "/data/sdk-allowed-wallets",
77
77
  SDK_TVL: "/data/sdk-tvl",
78
- // Best Opportunity
79
- BEST_OPPORTUNITY: (walletAddress, chainId) => `/data/best-opportunity?walletAddress=${walletAddress}&chainId=${chainId}`,
80
78
  // Agent Identity Registry
81
79
  AGENT_TOKEN_URI: "/users/me/agent-token-uri",
82
80
  // Customization
@@ -685,12 +683,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
685
683
  this.currentProvider = null;
686
684
  this.currentChainId = null;
687
685
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
688
- const { apiKey, rpcUrls } = sdkConfig;
686
+ const { apiKey, rpcUrls, referralSource } = sdkConfig;
689
687
  if (!apiKey) {
690
688
  throw new Error("API key is required");
691
689
  }
692
690
  this.httpClient = new HttpClient(apiKey);
693
691
  this.rpcUrls = rpcUrls;
692
+ this.referralSource = referralSource;
694
693
  }
695
694
  /**
696
695
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
@@ -738,7 +737,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
738
737
  ENDPOINTS.AUTH_LOGIN,
739
738
  {
740
739
  message: messageObj,
741
- signature
740
+ signature,
741
+ referralSource: this.referralSource
742
742
  },
743
743
  // Set Origin header in Node.js to match message.uri (required by backend validation)
744
744
  isNodeJs ? {
@@ -844,6 +844,49 @@ var _ZyfaiSDK = class _ZyfaiSDK {
844
844
  throw new Error(`Failed to pause agent: ${error.message}`);
845
845
  }
846
846
  }
847
+ /**
848
+ * Pause the agent by clearing all protocols
849
+ * Sets the user's protocols to an empty array, effectively pausing automated operations
850
+ *
851
+ * @returns Response indicating success and updated user details
852
+ *
853
+ * @example
854
+ * ```typescript
855
+ * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
856
+ *
857
+ * // Connect account first
858
+ * await sdk.connectAccount();
859
+ *
860
+ * // Pause the agent
861
+ * const result = await sdk.pauseAgent();
862
+ * console.log('Agent paused:', result.success);
863
+ * ```
864
+ */
865
+ async resumeAgent() {
866
+ try {
867
+ const userDetails = await this.getUserDetails();
868
+ const userChains = userDetails.user.chains;
869
+ const strategy = userDetails.user.strategy || "safe_strategy";
870
+ const convertedStrategy = toInternalStrategy(strategy);
871
+ const chains = userChains && userChains.length > 0 ? userChains : [8453, 42161];
872
+ const allProtocols = await this.httpClient.get(
873
+ ENDPOINTS.PROTOCOLS()
874
+ );
875
+ const filteredProtocolIds = allProtocols.filter((protocol) => {
876
+ const hasMatchingChain = protocol.chains.some(
877
+ (chain) => chains.includes(chain)
878
+ );
879
+ const hasMatchingStrategy = protocol.strategies?.includes(convertedStrategy);
880
+ return hasMatchingChain && hasMatchingStrategy;
881
+ }).map((protocol) => protocol.id);
882
+ const response = await this.updateUserProfile({
883
+ protocols: filteredProtocolIds
884
+ });
885
+ return response;
886
+ } catch (error) {
887
+ throw new Error(`Failed to resume agent: ${error.message}`);
888
+ }
889
+ }
847
890
  /**
848
891
  * Enable splitting for the user's account
849
892
  * When enabled, deposits are split across multiple protocols based on minSplits setting
@@ -2447,7 +2490,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2447
2490
  history: data.history || {},
2448
2491
  totalDays: data.total_days || data.totalDays || 0,
2449
2492
  requestedDays: data.requested_days || data.requestedDays,
2450
- averageWeightedApy: data.average_final_weighted_apy_after_fee || data.averageWeightedApy || 0
2493
+ weightedApyWithRzfiAfterFee: data.average_final_weighted_apy_after_fee_with_rzfi,
2494
+ weightedApyAfterFee: data.average_final_weighted_apy_after_fee
2451
2495
  };
2452
2496
  } catch (error) {
2453
2497
  throw new Error(
@@ -2563,43 +2607,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2563
2607
  );
2564
2608
  }
2565
2609
  }
2566
- /**
2567
- * Get the best yield opportunity for a registered wallet.
2568
- *
2569
- * Returns the highest-APY opportunity available based on the wallet's strategy
2570
- * and enabled protocols. This reflects what the rebalance engine would select.
2571
- *
2572
- * @param walletAddress - The smart wallet address (must be registered)
2573
- * @param chainId - The chain ID to check opportunities on
2574
- * @returns Best opportunity details with comparison to current position
2575
- *
2576
- * @example
2577
- * ```typescript
2578
- * const result = await sdk.getBestOpportunity(walletAddress, 8453);
2579
- *
2580
- * console.log("Current position:", result.currentPosition);
2581
- * console.log("Best opportunity:", result.bestOpportunity);
2582
- * console.log("Should rebalance:", result.shouldRebalance);
2583
- * console.log("APY improvement:", result.apyImprovement);
2584
- *
2585
- * // List all available opportunities
2586
- * result.allOpportunities?.forEach(opp => {
2587
- * console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}%`);
2588
- * });
2589
- * ```
2590
- */
2591
- async getBestOpportunity(walletAddress, chainId) {
2592
- try {
2593
- const response = await this.httpClient.get(
2594
- ENDPOINTS.BEST_OPPORTUNITY(walletAddress, chainId)
2595
- );
2596
- return response;
2597
- } catch (error) {
2598
- throw new Error(
2599
- `Failed to get best opportunity: ${error.message}`
2600
- );
2601
- }
2602
- }
2603
2610
  // ============================================================================
2604
2611
  // Protocol/Pool Customization
2605
2612
  // ============================================================================
package/dist/index.mjs CHANGED
@@ -21,7 +21,7 @@ var ENDPOINTS = {
21
21
  SESSION_KEYS_CONFIG: "/session-keys/config",
22
22
  SESSION_KEYS_ADD: "/session-keys/add",
23
23
  // Protocols
24
- PROTOCOLS: (chainId) => `/protocols?chainId=${chainId}`,
24
+ PROTOCOLS: (chainId) => chainId ? `/protocols?chainId=${chainId}` : "/protocols",
25
25
  // Data (v1)
26
26
  DATA_POSITION: (walletAddress) => `/data/position?walletAddress=${walletAddress}`,
27
27
  DATA_HISTORY: (walletAddress, chainId) => `/data/history?walletAddress=${walletAddress}&chainId=${chainId}`,
@@ -34,8 +34,6 @@ var ENDPOINTS = {
34
34
  // SDK Keys
35
35
  SDK_ALLOWED_WALLETS: "/data/sdk-allowed-wallets",
36
36
  SDK_TVL: "/data/sdk-tvl",
37
- // Best Opportunity
38
- BEST_OPPORTUNITY: (walletAddress, chainId) => `/data/best-opportunity?walletAddress=${walletAddress}&chainId=${chainId}`,
39
37
  // Agent Identity Registry
40
38
  AGENT_TOKEN_URI: "/users/me/agent-token-uri",
41
39
  // Customization
@@ -663,12 +661,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
663
661
  this.currentProvider = null;
664
662
  this.currentChainId = null;
665
663
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
666
- const { apiKey, rpcUrls } = sdkConfig;
664
+ const { apiKey, rpcUrls, referralSource } = sdkConfig;
667
665
  if (!apiKey) {
668
666
  throw new Error("API key is required");
669
667
  }
670
668
  this.httpClient = new HttpClient(apiKey);
671
669
  this.rpcUrls = rpcUrls;
670
+ this.referralSource = referralSource;
672
671
  }
673
672
  /**
674
673
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
@@ -716,7 +715,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
716
715
  ENDPOINTS.AUTH_LOGIN,
717
716
  {
718
717
  message: messageObj,
719
- signature
718
+ signature,
719
+ referralSource: this.referralSource
720
720
  },
721
721
  // Set Origin header in Node.js to match message.uri (required by backend validation)
722
722
  isNodeJs ? {
@@ -822,6 +822,49 @@ var _ZyfaiSDK = class _ZyfaiSDK {
822
822
  throw new Error(`Failed to pause agent: ${error.message}`);
823
823
  }
824
824
  }
825
+ /**
826
+ * Pause the agent by clearing all protocols
827
+ * Sets the user's protocols to an empty array, effectively pausing automated operations
828
+ *
829
+ * @returns Response indicating success and updated user details
830
+ *
831
+ * @example
832
+ * ```typescript
833
+ * const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
834
+ *
835
+ * // Connect account first
836
+ * await sdk.connectAccount();
837
+ *
838
+ * // Pause the agent
839
+ * const result = await sdk.pauseAgent();
840
+ * console.log('Agent paused:', result.success);
841
+ * ```
842
+ */
843
+ async resumeAgent() {
844
+ try {
845
+ const userDetails = await this.getUserDetails();
846
+ const userChains = userDetails.user.chains;
847
+ const strategy = userDetails.user.strategy || "safe_strategy";
848
+ const convertedStrategy = toInternalStrategy(strategy);
849
+ const chains = userChains && userChains.length > 0 ? userChains : [8453, 42161];
850
+ const allProtocols = await this.httpClient.get(
851
+ ENDPOINTS.PROTOCOLS()
852
+ );
853
+ const filteredProtocolIds = allProtocols.filter((protocol) => {
854
+ const hasMatchingChain = protocol.chains.some(
855
+ (chain) => chains.includes(chain)
856
+ );
857
+ const hasMatchingStrategy = protocol.strategies?.includes(convertedStrategy);
858
+ return hasMatchingChain && hasMatchingStrategy;
859
+ }).map((protocol) => protocol.id);
860
+ const response = await this.updateUserProfile({
861
+ protocols: filteredProtocolIds
862
+ });
863
+ return response;
864
+ } catch (error) {
865
+ throw new Error(`Failed to resume agent: ${error.message}`);
866
+ }
867
+ }
825
868
  /**
826
869
  * Enable splitting for the user's account
827
870
  * When enabled, deposits are split across multiple protocols based on minSplits setting
@@ -2425,7 +2468,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2425
2468
  history: data.history || {},
2426
2469
  totalDays: data.total_days || data.totalDays || 0,
2427
2470
  requestedDays: data.requested_days || data.requestedDays,
2428
- averageWeightedApy: data.average_final_weighted_apy_after_fee || data.averageWeightedApy || 0
2471
+ weightedApyWithRzfiAfterFee: data.average_final_weighted_apy_after_fee_with_rzfi,
2472
+ weightedApyAfterFee: data.average_final_weighted_apy_after_fee
2429
2473
  };
2430
2474
  } catch (error) {
2431
2475
  throw new Error(
@@ -2541,43 +2585,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2541
2585
  );
2542
2586
  }
2543
2587
  }
2544
- /**
2545
- * Get the best yield opportunity for a registered wallet.
2546
- *
2547
- * Returns the highest-APY opportunity available based on the wallet's strategy
2548
- * and enabled protocols. This reflects what the rebalance engine would select.
2549
- *
2550
- * @param walletAddress - The smart wallet address (must be registered)
2551
- * @param chainId - The chain ID to check opportunities on
2552
- * @returns Best opportunity details with comparison to current position
2553
- *
2554
- * @example
2555
- * ```typescript
2556
- * const result = await sdk.getBestOpportunity(walletAddress, 8453);
2557
- *
2558
- * console.log("Current position:", result.currentPosition);
2559
- * console.log("Best opportunity:", result.bestOpportunity);
2560
- * console.log("Should rebalance:", result.shouldRebalance);
2561
- * console.log("APY improvement:", result.apyImprovement);
2562
- *
2563
- * // List all available opportunities
2564
- * result.allOpportunities?.forEach(opp => {
2565
- * console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}%`);
2566
- * });
2567
- * ```
2568
- */
2569
- async getBestOpportunity(walletAddress, chainId) {
2570
- try {
2571
- const response = await this.httpClient.get(
2572
- ENDPOINTS.BEST_OPPORTUNITY(walletAddress, chainId)
2573
- );
2574
- return response;
2575
- } catch (error) {
2576
- throw new Error(
2577
- `Failed to get best opportunity: ${error.message}`
2578
- );
2579
- }
2580
- }
2581
2588
  // ============================================================================
2582
2589
  // Protocol/Pool Customization
2583
2590
  // ============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
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",