@zyfai/sdk 0.2.48 → 0.2.50

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
@@ -322,7 +322,7 @@ Deploy a Safe smart wallet for a user. **Deployment is handled by the backend AP
322
322
 
323
323
  - User must be authenticated (automatically done via `connectAccount()`)
324
324
  - Backend handles all RPC calls, avoiding rate limiting
325
- - Protocol / asset patching is **not** done in `deploySafe` — it runs once on the account's **first** `depositFunds` call (see Deposit Funds below)
325
+ - Protocol / asset patching runs in `deploySafe` (all paths). `depositFunds` still patches on the account's **first** deposit if USDC `chains` are empty (see Deposit Funds below)
326
326
 
327
327
  ##### `addWalletToSdk(walletAddress: string): Promise<AddWalletToSdkResponse>`
328
328
 
@@ -380,7 +380,7 @@ console.log("User ID:", result.userId);
380
380
  - User must be authenticated (automatically done via `connectAccount()`)
381
381
  - The SDK proactively checks if the user already has an active session key and returns early without requiring any signature if one exists
382
382
  - The user record must have `smartWallet` and `chainId` set (predeployed assignment / first deposit)
383
- - Protocol selection is **not** touched by `createSessionKey` — it's set on the first `depositFunds` call
383
+ - Protocol selection is **not** touched by `createSessionKey` — it's set by `deploySafe` and on the first `depositFunds` call if USDC `chains` are still empty
384
384
  - **Deprecated**: prefer `depositFunds()` for partner onboarding; `createSessionKey` remains for legacy flows
385
385
  - When `alreadyActive` is `true`, `sessionKeyAddress` and `signature` are not available in the response
386
386
 
@@ -739,6 +739,7 @@ console.log("Chain ID:", firstTopup.chainId);
739
739
  const history = await sdk.getHistory(walletAddress, 8453, {
740
740
  limit: 50,
741
741
  fromDate: "2024-01-01",
742
+ assetType: "eth",
742
743
  });
743
744
  history.data.forEach((tx) => console.log(tx.type, tx.amount));
744
745
  ```
package/dist/index.d.mts CHANGED
@@ -849,8 +849,8 @@ declare class ZyfaiSDK {
849
849
  */
850
850
  updateMinSplits(minSplits: number): Promise<UpdateUserProfileResponse>;
851
851
  /**
852
- * Initialize user after Safe deployment
853
- * This method is automatically called after deploySafe to initialize user state
852
+ * Initialize earnings tracking for a smart wallet on the Data API.
853
+ * Called from `deploySafe` after a fresh deploy and for predeployed wallets.
854
854
  *
855
855
  * @param smartWallet - Safe smart wallet address
856
856
  * @param chainId - Target chain ID
@@ -992,7 +992,8 @@ declare class ZyfaiSDK {
992
992
  * asset/chain/strategy combo.
993
993
  * 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
994
994
  *
995
- * Called once from `depositFunds` on the account's first deposit.
995
+ * Called from `deploySafe` after every path, and from `depositFunds` on
996
+ * the account's first deposit (when USDC chains are still empty).
996
997
  *
997
998
  * @internal
998
999
  */
@@ -1309,12 +1310,15 @@ declare class ZyfaiSDK {
1309
1310
  *
1310
1311
  * @param walletAddress - Smart wallet address
1311
1312
  * @param chainId - Chain ID
1312
- * @param options - Optional pagination and date filters
1313
+ * @param options - Optional pagination, date, and assetType filters
1313
1314
  * @returns Transaction history
1314
1315
  *
1315
1316
  * @example
1316
1317
  * ```typescript
1317
- * const history = await sdk.getHistory("0x...", 8453, { limit: 50 });
1318
+ * const history = await sdk.getHistory("0x...", 8453, {
1319
+ * limit: 50,
1320
+ * assetType: "eth",
1321
+ * });
1318
1322
  * history.data.forEach(tx => console.log(tx.type, tx.amount));
1319
1323
  * ```
1320
1324
  */
@@ -1323,6 +1327,7 @@ declare class ZyfaiSDK {
1323
1327
  offset?: number;
1324
1328
  fromDate?: string;
1325
1329
  toDate?: string;
1330
+ assetType?: "usdc" | "eth" | "eurc";
1326
1331
  }): Promise<HistoryResponse>;
1327
1332
  /**
1328
1333
  * Get onchain earnings for a wallet
package/dist/index.d.ts CHANGED
@@ -849,8 +849,8 @@ declare class ZyfaiSDK {
849
849
  */
850
850
  updateMinSplits(minSplits: number): Promise<UpdateUserProfileResponse>;
851
851
  /**
852
- * Initialize user after Safe deployment
853
- * This method is automatically called after deploySafe to initialize user state
852
+ * Initialize earnings tracking for a smart wallet on the Data API.
853
+ * Called from `deploySafe` after a fresh deploy and for predeployed wallets.
854
854
  *
855
855
  * @param smartWallet - Safe smart wallet address
856
856
  * @param chainId - Target chain ID
@@ -992,7 +992,8 @@ declare class ZyfaiSDK {
992
992
  * asset/chain/strategy combo.
993
993
  * 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
994
994
  *
995
- * Called once from `depositFunds` on the account's first deposit.
995
+ * Called from `deploySafe` after every path, and from `depositFunds` on
996
+ * the account's first deposit (when USDC chains are still empty).
996
997
  *
997
998
  * @internal
998
999
  */
@@ -1309,12 +1310,15 @@ declare class ZyfaiSDK {
1309
1310
  *
1310
1311
  * @param walletAddress - Smart wallet address
1311
1312
  * @param chainId - Chain ID
1312
- * @param options - Optional pagination and date filters
1313
+ * @param options - Optional pagination, date, and assetType filters
1313
1314
  * @returns Transaction history
1314
1315
  *
1315
1316
  * @example
1316
1317
  * ```typescript
1317
- * const history = await sdk.getHistory("0x...", 8453, { limit: 50 });
1318
+ * const history = await sdk.getHistory("0x...", 8453, {
1319
+ * limit: 50,
1320
+ * assetType: "eth",
1321
+ * });
1318
1322
  * history.data.forEach(tx => console.log(tx.type, tx.amount));
1319
1323
  * ```
1320
1324
  */
@@ -1323,6 +1327,7 @@ declare class ZyfaiSDK {
1323
1327
  offset?: number;
1324
1328
  fromDate?: string;
1325
1329
  toDate?: string;
1330
+ assetType?: "usdc" | "eth" | "eurc";
1326
1331
  }): Promise<HistoryResponse>;
1327
1332
  /**
1328
1333
  * Get onchain earnings for a wallet
package/dist/index.js CHANGED
@@ -81,7 +81,7 @@ var ENDPOINTS = {
81
81
  // Data (v1)
82
82
  DATA_POSITION: (walletAddress) => `/data/position?walletAddress=${walletAddress}`,
83
83
  DATA_PORTFOLIO: (walletAddress) => `/data/wallet-portfolio?walletAddress=${walletAddress}`,
84
- DATA_HISTORY: (walletAddress, chainId) => `/data/history?walletAddress=${walletAddress}&chainId=${chainId}`,
84
+ DATA_HISTORY: (walletAddress, chainId, assetType) => `/data/history?walletAddress=${walletAddress}&chainId=${chainId}${assetType ? `&assetType=${assetType}` : ""}`,
85
85
  DATA_TVL: "/data/usd-tvl",
86
86
  DATA_VOLUME: (assetType) => `/data/volume?assetType=${assetType}`,
87
87
  DATA_FIRST_TOPUP: (walletAddress, chainId) => `/data/first-topup?walletAddress=${walletAddress}&chainId=${chainId}`,
@@ -1706,8 +1706,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1706
1706
  }
1707
1707
  }
1708
1708
  /**
1709
- * Initialize user after Safe deployment
1710
- * This method is automatically called after deploySafe to initialize user state
1709
+ * Initialize earnings tracking for a smart wallet on the Data API.
1710
+ * Called from `deploySafe` after a fresh deploy and for predeployed wallets.
1711
1711
  *
1712
1712
  * @param smartWallet - Safe smart wallet address
1713
1713
  * @param chainId - Target chain ID
@@ -2033,6 +2033,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2033
2033
  userAddress,
2034
2034
  chainId
2035
2035
  );
2036
+ try {
2037
+ await this.initializeUser(predeployedAddress, chainId);
2038
+ } catch (initError) {
2039
+ console.warn(
2040
+ "Failed to initialize user after Safe deployment:",
2041
+ initError.message
2042
+ );
2043
+ }
2036
2044
  await this.updateUserProtocols(strategy);
2037
2045
  return {
2038
2046
  success: true,
@@ -2094,6 +2102,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2094
2102
  initError.message
2095
2103
  );
2096
2104
  }
2105
+ await this.updateUserProtocols(strategy);
2097
2106
  let sessionKeyCreated = false;
2098
2107
  if (createSessionKey) {
2099
2108
  try {
@@ -2283,7 +2292,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2283
2292
  * asset/chain/strategy combo.
2284
2293
  * 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
2285
2294
  *
2286
- * Called once from `depositFunds` on the account's first deposit.
2295
+ * Called from `deploySafe` after every path, and from `depositFunds` on
2296
+ * the account's first deposit (when USDC chains are still empty).
2287
2297
  *
2288
2298
  * @internal
2289
2299
  */
@@ -3122,12 +3132,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3122
3132
  *
3123
3133
  * @param walletAddress - Smart wallet address
3124
3134
  * @param chainId - Chain ID
3125
- * @param options - Optional pagination and date filters
3135
+ * @param options - Optional pagination, date, and assetType filters
3126
3136
  * @returns Transaction history
3127
3137
  *
3128
3138
  * @example
3129
3139
  * ```typescript
3130
- * const history = await sdk.getHistory("0x...", 8453, { limit: 50 });
3140
+ * const history = await sdk.getHistory("0x...", 8453, {
3141
+ * limit: 50,
3142
+ * assetType: "eth",
3143
+ * });
3131
3144
  * history.data.forEach(tx => console.log(tx.type, tx.amount));
3132
3145
  * ```
3133
3146
  */
@@ -3139,7 +3152,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3139
3152
  if (!chainId) {
3140
3153
  throw new Error("Chain ID is required");
3141
3154
  }
3142
- let endpoint = ENDPOINTS.DATA_HISTORY(walletAddress, chainId);
3155
+ let endpoint = ENDPOINTS.DATA_HISTORY(
3156
+ walletAddress,
3157
+ chainId,
3158
+ options?.assetType
3159
+ );
3143
3160
  if (options?.limit) endpoint += `&limit=${options.limit}`;
3144
3161
  if (options?.offset) endpoint += `&offset=${options.offset}`;
3145
3162
  if (options?.fromDate) endpoint += `&fromDate=${options.fromDate}`;
package/dist/index.mjs CHANGED
@@ -29,7 +29,7 @@ var ENDPOINTS = {
29
29
  // Data (v1)
30
30
  DATA_POSITION: (walletAddress) => `/data/position?walletAddress=${walletAddress}`,
31
31
  DATA_PORTFOLIO: (walletAddress) => `/data/wallet-portfolio?walletAddress=${walletAddress}`,
32
- DATA_HISTORY: (walletAddress, chainId) => `/data/history?walletAddress=${walletAddress}&chainId=${chainId}`,
32
+ DATA_HISTORY: (walletAddress, chainId, assetType) => `/data/history?walletAddress=${walletAddress}&chainId=${chainId}${assetType ? `&assetType=${assetType}` : ""}`,
33
33
  DATA_TVL: "/data/usd-tvl",
34
34
  DATA_VOLUME: (assetType) => `/data/volume?assetType=${assetType}`,
35
35
  DATA_FIRST_TOPUP: (walletAddress, chainId) => `/data/first-topup?walletAddress=${walletAddress}&chainId=${chainId}`,
@@ -1674,8 +1674,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1674
1674
  }
1675
1675
  }
1676
1676
  /**
1677
- * Initialize user after Safe deployment
1678
- * This method is automatically called after deploySafe to initialize user state
1677
+ * Initialize earnings tracking for a smart wallet on the Data API.
1678
+ * Called from `deploySafe` after a fresh deploy and for predeployed wallets.
1679
1679
  *
1680
1680
  * @param smartWallet - Safe smart wallet address
1681
1681
  * @param chainId - Target chain ID
@@ -2001,6 +2001,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2001
2001
  userAddress,
2002
2002
  chainId
2003
2003
  );
2004
+ try {
2005
+ await this.initializeUser(predeployedAddress, chainId);
2006
+ } catch (initError) {
2007
+ console.warn(
2008
+ "Failed to initialize user after Safe deployment:",
2009
+ initError.message
2010
+ );
2011
+ }
2004
2012
  await this.updateUserProtocols(strategy);
2005
2013
  return {
2006
2014
  success: true,
@@ -2062,6 +2070,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2062
2070
  initError.message
2063
2071
  );
2064
2072
  }
2073
+ await this.updateUserProtocols(strategy);
2065
2074
  let sessionKeyCreated = false;
2066
2075
  if (createSessionKey) {
2067
2076
  try {
@@ -2251,7 +2260,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2251
2260
  * asset/chain/strategy combo.
2252
2261
  * 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
2253
2262
  *
2254
- * Called once from `depositFunds` on the account's first deposit.
2263
+ * Called from `deploySafe` after every path, and from `depositFunds` on
2264
+ * the account's first deposit (when USDC chains are still empty).
2255
2265
  *
2256
2266
  * @internal
2257
2267
  */
@@ -3090,12 +3100,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3090
3100
  *
3091
3101
  * @param walletAddress - Smart wallet address
3092
3102
  * @param chainId - Chain ID
3093
- * @param options - Optional pagination and date filters
3103
+ * @param options - Optional pagination, date, and assetType filters
3094
3104
  * @returns Transaction history
3095
3105
  *
3096
3106
  * @example
3097
3107
  * ```typescript
3098
- * const history = await sdk.getHistory("0x...", 8453, { limit: 50 });
3108
+ * const history = await sdk.getHistory("0x...", 8453, {
3109
+ * limit: 50,
3110
+ * assetType: "eth",
3111
+ * });
3099
3112
  * history.data.forEach(tx => console.log(tx.type, tx.amount));
3100
3113
  * ```
3101
3114
  */
@@ -3107,7 +3120,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3107
3120
  if (!chainId) {
3108
3121
  throw new Error("Chain ID is required");
3109
3122
  }
3110
- let endpoint = ENDPOINTS.DATA_HISTORY(walletAddress, chainId);
3123
+ let endpoint = ENDPOINTS.DATA_HISTORY(
3124
+ walletAddress,
3125
+ chainId,
3126
+ options?.assetType
3127
+ );
3111
3128
  if (options?.limit) endpoint += `&limit=${options.limit}`;
3112
3129
  if (options?.offset) endpoint += `&offset=${options.offset}`;
3113
3130
  if (options?.fromDate) endpoint += `&fromDate=${options.fromDate}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.48",
3
+ "version": "0.2.50",
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",