@zyfai/sdk 0.2.21 → 0.2.23

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
@@ -385,6 +385,43 @@ if (result.success) {
385
385
  - Token address is automatically selected based on chain (USDC for Base/Arbitrum, USDT for Plasma)
386
386
  - The SDK automatically authenticates via SIWE before logging the deposit with Zyfai's API, so no extra steps are required on your end once the transfer confirms
387
387
 
388
+ #### Log External Deposit (For Sponsored Transactions)
389
+
390
+ If you execute deposits client-side (e.g., with Privy, Biconomy, or other sponsored/gasless transaction providers), use `logDeposit` to register the deposit with Zyfai's backend:
391
+
392
+ ```typescript
393
+ // 1. Execute deposit with your own wallet implementation (e.g., Privy)
394
+ const txHash = await privyWallet.sendTransaction({
395
+ to: safeAddress,
396
+ data: transferData, // ERC20 transfer encoded data
397
+ });
398
+
399
+ // 2. Log the deposit to Zyfai backend for tracking and yield optimization
400
+ const result = await sdk.logDeposit(
401
+ 8453, // chainId
402
+ txHash, // transaction hash from your wallet
403
+ "100000000" // 100 USDC (6 decimals)
404
+ );
405
+
406
+ if (result.success) {
407
+ console.log("Deposit logged successfully");
408
+ }
409
+ ```
410
+
411
+ **When to use `logDeposit`:**
412
+
413
+ - You use sponsored/gasless transactions (Privy, Biconomy, Gelato, etc.)
414
+ - You have a custom wallet implementation
415
+ - You need more control over transaction execution
416
+ - You want to pay gas fees for your users
417
+
418
+ **Parameters:**
419
+
420
+ - `chainId`: Chain ID where the deposit was made
421
+ - `txHash`: Transaction hash of the deposit (must start with "0x")
422
+ - `amount`: Amount in least decimal units
423
+ - `tokenAddress` (optional): Token address (auto-selected based on chain if not provided)
424
+
388
425
  ### 5. Withdraw Funds
389
426
 
390
427
  Initiate a withdrawal from your Safe. **Note: Withdrawals are processed asynchronously by the backend.**
package/dist/index.d.mts CHANGED
@@ -112,7 +112,7 @@ interface staleBalances {
112
112
  balance: string;
113
113
  isPending: boolean;
114
114
  }
115
- interface Position {
115
+ interface Portfolio {
116
116
  user?: string;
117
117
  eoa?: Address;
118
118
  chains?: number[];
@@ -147,7 +147,7 @@ interface PositionSlot {
147
147
  interface PortfolioResponse {
148
148
  success: boolean;
149
149
  userAddress: string;
150
- portfolio: Position;
150
+ portfolio: Portfolio;
151
151
  }
152
152
  interface UserDetails {
153
153
  id: string;
@@ -375,6 +375,10 @@ interface DepositResponse {
375
375
  smartWallet: string;
376
376
  amount: string;
377
377
  }
378
+ interface LogDepositResponse {
379
+ success: boolean;
380
+ message: string;
381
+ }
378
382
  interface WithdrawResponse {
379
383
  success: boolean;
380
384
  message: string;
@@ -808,6 +812,46 @@ declare class ZyfaiSDK {
808
812
  * ```
809
813
  */
810
814
  depositFunds(userAddress: string, chainId: SupportedChainId, amount: string): Promise<DepositResponse>;
815
+ /**
816
+ * Log a deposit that was executed client-side
817
+ *
818
+ * Use this method when you execute the deposit transaction yourself (e.g., with Privy,
819
+ * sponsored transactions, or any custom wallet implementation) and need to register
820
+ * the deposit with the Zyfai backend for tracking and yield optimization.
821
+ *
822
+ * This is useful for partners who:
823
+ * - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
824
+ * - Have custom wallet implementations
825
+ * - Need more control over transaction execution
826
+ *
827
+ * Token is automatically selected based on chain if not provided:
828
+ * - Base (8453) and Arbitrum (42161): USDC
829
+ * - Plasma (9745): USDT
830
+ *
831
+ * @param chainId - Chain ID where the deposit was made
832
+ * @param txHash - Transaction hash of the deposit
833
+ * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
834
+ * @param tokenAddress - Optional: Token address (auto-selected based on chain if not provided)
835
+ * @returns Log deposit response with success status
836
+ *
837
+ * @example
838
+ * ```typescript
839
+ * // Execute deposit with Privy (sponsored transaction)
840
+ * const txHash = await privyWallet.sendTransaction({
841
+ * to: safeAddress,
842
+ * data: transferData,
843
+ * });
844
+ *
845
+ * // Log the deposit to Zyfai backend
846
+ * const result = await sdk.logDeposit(
847
+ * 8453, // chainId
848
+ * txHash, // transaction hash from Privy
849
+ * "100000000" // 100 USDC
850
+ * );
851
+ * console.log(result.success); // true
852
+ * ```
853
+ */
854
+ logDeposit(chainId: SupportedChainId, txHash: string, amount: string, tokenAddress?: string): Promise<LogDepositResponse>;
811
855
  /**
812
856
  * Withdraw funds from Safe smart wallet
813
857
  * Initiates a withdrawal request to the Zyfai API
@@ -1283,4 +1327,4 @@ declare class ZyfaiSDK {
1283
1327
  registerAgentOnIdentityRegistry(smartWallet: string, chainId: SupportedChainId): Promise<RegisterAgentResponse>;
1284
1328
  }
1285
1329
 
1286
- export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type PortfolioResponse, type PortfolioToken, type Position, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
1330
+ export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type LogDepositResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type Portfolio, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
package/dist/index.d.ts CHANGED
@@ -112,7 +112,7 @@ interface staleBalances {
112
112
  balance: string;
113
113
  isPending: boolean;
114
114
  }
115
- interface Position {
115
+ interface Portfolio {
116
116
  user?: string;
117
117
  eoa?: Address;
118
118
  chains?: number[];
@@ -147,7 +147,7 @@ interface PositionSlot {
147
147
  interface PortfolioResponse {
148
148
  success: boolean;
149
149
  userAddress: string;
150
- portfolio: Position;
150
+ portfolio: Portfolio;
151
151
  }
152
152
  interface UserDetails {
153
153
  id: string;
@@ -375,6 +375,10 @@ interface DepositResponse {
375
375
  smartWallet: string;
376
376
  amount: string;
377
377
  }
378
+ interface LogDepositResponse {
379
+ success: boolean;
380
+ message: string;
381
+ }
378
382
  interface WithdrawResponse {
379
383
  success: boolean;
380
384
  message: string;
@@ -808,6 +812,46 @@ declare class ZyfaiSDK {
808
812
  * ```
809
813
  */
810
814
  depositFunds(userAddress: string, chainId: SupportedChainId, amount: string): Promise<DepositResponse>;
815
+ /**
816
+ * Log a deposit that was executed client-side
817
+ *
818
+ * Use this method when you execute the deposit transaction yourself (e.g., with Privy,
819
+ * sponsored transactions, or any custom wallet implementation) and need to register
820
+ * the deposit with the Zyfai backend for tracking and yield optimization.
821
+ *
822
+ * This is useful for partners who:
823
+ * - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
824
+ * - Have custom wallet implementations
825
+ * - Need more control over transaction execution
826
+ *
827
+ * Token is automatically selected based on chain if not provided:
828
+ * - Base (8453) and Arbitrum (42161): USDC
829
+ * - Plasma (9745): USDT
830
+ *
831
+ * @param chainId - Chain ID where the deposit was made
832
+ * @param txHash - Transaction hash of the deposit
833
+ * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
834
+ * @param tokenAddress - Optional: Token address (auto-selected based on chain if not provided)
835
+ * @returns Log deposit response with success status
836
+ *
837
+ * @example
838
+ * ```typescript
839
+ * // Execute deposit with Privy (sponsored transaction)
840
+ * const txHash = await privyWallet.sendTransaction({
841
+ * to: safeAddress,
842
+ * data: transferData,
843
+ * });
844
+ *
845
+ * // Log the deposit to Zyfai backend
846
+ * const result = await sdk.logDeposit(
847
+ * 8453, // chainId
848
+ * txHash, // transaction hash from Privy
849
+ * "100000000" // 100 USDC
850
+ * );
851
+ * console.log(result.success); // true
852
+ * ```
853
+ */
854
+ logDeposit(chainId: SupportedChainId, txHash: string, amount: string, tokenAddress?: string): Promise<LogDepositResponse>;
811
855
  /**
812
856
  * Withdraw funds from Safe smart wallet
813
857
  * Initiates a withdrawal request to the Zyfai API
@@ -1283,4 +1327,4 @@ declare class ZyfaiSDK {
1283
1327
  registerAgentOnIdentityRegistry(smartWallet: string, chainId: SupportedChainId): Promise<RegisterAgentResponse>;
1284
1328
  }
1285
1329
 
1286
- export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type PortfolioResponse, type PortfolioToken, type Position, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
1330
+ export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type LogDepositResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type Portfolio, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
package/dist/index.js CHANGED
@@ -1650,6 +1650,71 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1650
1650
  throw new Error(`Deposit failed: ${error.message}`);
1651
1651
  }
1652
1652
  }
1653
+ /**
1654
+ * Log a deposit that was executed client-side
1655
+ *
1656
+ * Use this method when you execute the deposit transaction yourself (e.g., with Privy,
1657
+ * sponsored transactions, or any custom wallet implementation) and need to register
1658
+ * the deposit with the Zyfai backend for tracking and yield optimization.
1659
+ *
1660
+ * This is useful for partners who:
1661
+ * - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
1662
+ * - Have custom wallet implementations
1663
+ * - Need more control over transaction execution
1664
+ *
1665
+ * Token is automatically selected based on chain if not provided:
1666
+ * - Base (8453) and Arbitrum (42161): USDC
1667
+ * - Plasma (9745): USDT
1668
+ *
1669
+ * @param chainId - Chain ID where the deposit was made
1670
+ * @param txHash - Transaction hash of the deposit
1671
+ * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1672
+ * @param tokenAddress - Optional: Token address (auto-selected based on chain if not provided)
1673
+ * @returns Log deposit response with success status
1674
+ *
1675
+ * @example
1676
+ * ```typescript
1677
+ * // Execute deposit with Privy (sponsored transaction)
1678
+ * const txHash = await privyWallet.sendTransaction({
1679
+ * to: safeAddress,
1680
+ * data: transferData,
1681
+ * });
1682
+ *
1683
+ * // Log the deposit to Zyfai backend
1684
+ * const result = await sdk.logDeposit(
1685
+ * 8453, // chainId
1686
+ * txHash, // transaction hash from Privy
1687
+ * "100000000" // 100 USDC
1688
+ * );
1689
+ * console.log(result.success); // true
1690
+ * ```
1691
+ */
1692
+ async logDeposit(chainId, txHash, amount, tokenAddress) {
1693
+ try {
1694
+ if (!isSupportedChain(chainId)) {
1695
+ throw new Error(`Unsupported chain ID: ${chainId}`);
1696
+ }
1697
+ if (!txHash || !txHash.startsWith("0x")) {
1698
+ throw new Error("Valid transaction hash is required");
1699
+ }
1700
+ if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
1701
+ throw new Error("Valid amount is required");
1702
+ }
1703
+ const token = tokenAddress || getDefaultTokenAddress(chainId);
1704
+ await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
1705
+ chainId,
1706
+ transaction: txHash,
1707
+ token,
1708
+ amount
1709
+ });
1710
+ return {
1711
+ success: true,
1712
+ message: "Deposit logged successfully"
1713
+ };
1714
+ } catch (error) {
1715
+ throw new Error(`Log deposit failed: ${error.message}`);
1716
+ }
1717
+ }
1653
1718
  /**
1654
1719
  * Withdraw funds from Safe smart wallet
1655
1720
  * Initiates a withdrawal request to the Zyfai API
package/dist/index.mjs CHANGED
@@ -1628,6 +1628,71 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1628
1628
  throw new Error(`Deposit failed: ${error.message}`);
1629
1629
  }
1630
1630
  }
1631
+ /**
1632
+ * Log a deposit that was executed client-side
1633
+ *
1634
+ * Use this method when you execute the deposit transaction yourself (e.g., with Privy,
1635
+ * sponsored transactions, or any custom wallet implementation) and need to register
1636
+ * the deposit with the Zyfai backend for tracking and yield optimization.
1637
+ *
1638
+ * This is useful for partners who:
1639
+ * - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
1640
+ * - Have custom wallet implementations
1641
+ * - Need more control over transaction execution
1642
+ *
1643
+ * Token is automatically selected based on chain if not provided:
1644
+ * - Base (8453) and Arbitrum (42161): USDC
1645
+ * - Plasma (9745): USDT
1646
+ *
1647
+ * @param chainId - Chain ID where the deposit was made
1648
+ * @param txHash - Transaction hash of the deposit
1649
+ * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1650
+ * @param tokenAddress - Optional: Token address (auto-selected based on chain if not provided)
1651
+ * @returns Log deposit response with success status
1652
+ *
1653
+ * @example
1654
+ * ```typescript
1655
+ * // Execute deposit with Privy (sponsored transaction)
1656
+ * const txHash = await privyWallet.sendTransaction({
1657
+ * to: safeAddress,
1658
+ * data: transferData,
1659
+ * });
1660
+ *
1661
+ * // Log the deposit to Zyfai backend
1662
+ * const result = await sdk.logDeposit(
1663
+ * 8453, // chainId
1664
+ * txHash, // transaction hash from Privy
1665
+ * "100000000" // 100 USDC
1666
+ * );
1667
+ * console.log(result.success); // true
1668
+ * ```
1669
+ */
1670
+ async logDeposit(chainId, txHash, amount, tokenAddress) {
1671
+ try {
1672
+ if (!isSupportedChain(chainId)) {
1673
+ throw new Error(`Unsupported chain ID: ${chainId}`);
1674
+ }
1675
+ if (!txHash || !txHash.startsWith("0x")) {
1676
+ throw new Error("Valid transaction hash is required");
1677
+ }
1678
+ if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
1679
+ throw new Error("Valid amount is required");
1680
+ }
1681
+ const token = tokenAddress || getDefaultTokenAddress(chainId);
1682
+ await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
1683
+ chainId,
1684
+ transaction: txHash,
1685
+ token,
1686
+ amount
1687
+ });
1688
+ return {
1689
+ success: true,
1690
+ message: "Deposit logged successfully"
1691
+ };
1692
+ } catch (error) {
1693
+ throw new Error(`Log deposit failed: ${error.message}`);
1694
+ }
1695
+ }
1631
1696
  /**
1632
1697
  * Withdraw funds from Safe smart wallet
1633
1698
  * Initiates a withdrawal request to the Zyfai API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
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",