@zyfai/sdk 0.2.53 → 0.2.55

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
@@ -427,7 +427,7 @@ if (result.success) {
427
427
 
428
428
  #### Log External Deposit (For Sponsored Transactions)
429
429
 
430
- 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:
430
+ `depositFunds()` already calls `logDeposit` after the transfer. If you **do not** use `depositFunds()` and send the ERC20 yourself (front, Privy, Biconomy, custom wallet), you **must** call `logDeposit` — otherwise the backend never sees the deposit: a reserved pool wallet stays reserved (no ownership rotation), and yield/agent tracking does not start.
431
431
 
432
432
  ```typescript
433
433
  // 1. Execute deposit with your own wallet implementation (e.g., Privy)
@@ -450,8 +450,9 @@ if (result.success) {
450
450
 
451
451
  **When to use `logDeposit`:**
452
452
 
453
+ - You did **not** call `depositFunds()` (it already logs the deposit for you)
453
454
  - You use sponsored/gasless transactions (Privy, Biconomy, Gelato, etc.)
454
- - You have a custom wallet implementation
455
+ - You have a custom wallet / frontend transfer
455
456
  - You need more control over transaction execution
456
457
  - You want to pay gas fees for your users
457
458
 
@@ -750,6 +751,10 @@ history.data.forEach((tx) => {
750
751
  console.log(tx.rebalanceLog.oldApy, tx.rebalanceLog.oldApy_withFee);
751
752
  console.log(tx.rebalanceLog.newApy, tx.rebalanceLog.newApy_withFee);
752
753
  }
754
+ tx.positions?.forEach((pos) => {
755
+ console.log(pos.amount); // resulting position balance after the action
756
+ console.log(pos.deltaAmount); // amount actually moved by the action (optional, not on older entries)
757
+ });
753
758
  });
754
759
  ```
755
760
 
@@ -796,6 +801,8 @@ const daily = await sdk.getDailyEarnings(
796
801
  );
797
802
  daily.data.forEach((d) => {
798
803
  console.log(d.snapshot_date, d.total_earnings_by_token);
804
+ // daily_total_delta_by_token_withoutFee = daily_total_delta_by_token x (1 - feeRate), computed by the SDK
805
+ console.log("Delta without fee:", d.daily_total_delta_by_token_withoutFee);
799
806
  });
800
807
  ```
801
808
 
package/dist/index.d.mts CHANGED
@@ -266,6 +266,12 @@ interface HistoryPosition {
266
266
  token_symbol?: string;
267
267
  protocol_icon?: string;
268
268
  protocol_name?: string;
269
+ /**
270
+ * The amount actually moved by this action (deposit/withdraw/rebalance delta),
271
+ * as opposed to `amount`, which is the resulting position balance after the action.
272
+ * Optional: not present on older history entries or actions that predate this field.
273
+ */
274
+ deltaAmount?: string;
269
275
  }
270
276
  interface HistoryFeeData {
271
277
  gasCostInToken?: string;
@@ -333,6 +339,8 @@ interface DailyEarning {
333
339
  unrealized_earnings_by_token: ChainTokenEarnings;
334
340
  total_earnings_by_token: ChainTokenEarnings;
335
341
  daily_total_delta_by_token: ChainTokenEarnings;
342
+ /** Fee-exclusive: daily_total_delta_by_token × (1 - feeRate). */
343
+ daily_total_delta_by_token_withoutFee: ChainTokenEarnings;
336
344
  created_at?: string;
337
345
  }
338
346
  interface DailyEarningsResponse {
@@ -1110,15 +1118,20 @@ declare class ZyfaiSDK {
1110
1118
  }>;
1111
1119
  depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1112
1120
  /**
1113
- * Log a deposit that was executed client-side
1121
+ * Log a deposit that was executed client-side.
1114
1122
  *
1115
- * Use this method when you execute the deposit transaction yourself (e.g., with Privy,
1116
- * sponsored transactions, or any custom wallet implementation) and need to register
1117
- * the deposit with the Zyfai backend for tracking and yield optimization.
1123
+ * `depositFunds()` already calls this after the ERC20 transfer. If you send the
1124
+ * transfer yourself (front, Privy, Biconomy, custom wallet) you **must** call
1125
+ * `logDeposit` — otherwise the backend never sees the deposit: a reserved pool
1126
+ * wallet stays reserved (no ownership rotation), and yield/agent tracking does
1127
+ * not start.
1118
1128
  *
1119
- * This is useful for partners who:
1129
+ * Use this method when you execute the deposit transaction yourself and need to
1130
+ * register it with the Zyfai backend.
1131
+ *
1132
+ * This is required for partners who:
1120
1133
  * - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
1121
- * - Have custom wallet implementations
1134
+ * - Have a custom wallet / frontend transfer
1122
1135
  * - Need more control over transaction execution
1123
1136
  *
1124
1137
  * Token is automatically selected based on chain if not provided:
@@ -1388,7 +1401,10 @@ declare class ZyfaiSDK {
1388
1401
  *
1389
1402
  * Reads from `user_onchain_daily_earnings_v2`. Each entry exposes
1390
1403
  * per-chain per-token maps for current / lifetime / unrealized / total
1391
- * earnings plus a daily total delta.
1404
+ * earnings plus a daily total delta (gross and fee-exclusive).
1405
+ *
1406
+ * `daily_total_delta_by_token_withoutFee` is computed by the SDK, not the
1407
+ * API: it is `daily_total_delta_by_token × (1 - feeRate)`.
1392
1408
  *
1393
1409
  * @param walletAddress - Smart wallet address
1394
1410
  * @param startDate - Start date (YYYY-MM-DD format)
@@ -1401,6 +1417,7 @@ declare class ZyfaiSDK {
1401
1417
  * daily.data.forEach(d => {
1402
1418
  * // d.total_earnings_by_token = { "8453": { "USDC": "143.10" } }
1403
1419
  * console.log(d.snapshot_date, d.total_earnings_by_token);
1420
+ * console.log("Delta without fee:", d.daily_total_delta_by_token_withoutFee);
1404
1421
  * });
1405
1422
  * ```
1406
1423
  */
package/dist/index.d.ts CHANGED
@@ -266,6 +266,12 @@ interface HistoryPosition {
266
266
  token_symbol?: string;
267
267
  protocol_icon?: string;
268
268
  protocol_name?: string;
269
+ /**
270
+ * The amount actually moved by this action (deposit/withdraw/rebalance delta),
271
+ * as opposed to `amount`, which is the resulting position balance after the action.
272
+ * Optional: not present on older history entries or actions that predate this field.
273
+ */
274
+ deltaAmount?: string;
269
275
  }
270
276
  interface HistoryFeeData {
271
277
  gasCostInToken?: string;
@@ -333,6 +339,8 @@ interface DailyEarning {
333
339
  unrealized_earnings_by_token: ChainTokenEarnings;
334
340
  total_earnings_by_token: ChainTokenEarnings;
335
341
  daily_total_delta_by_token: ChainTokenEarnings;
342
+ /** Fee-exclusive: daily_total_delta_by_token × (1 - feeRate). */
343
+ daily_total_delta_by_token_withoutFee: ChainTokenEarnings;
336
344
  created_at?: string;
337
345
  }
338
346
  interface DailyEarningsResponse {
@@ -1110,15 +1118,20 @@ declare class ZyfaiSDK {
1110
1118
  }>;
1111
1119
  depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1112
1120
  /**
1113
- * Log a deposit that was executed client-side
1121
+ * Log a deposit that was executed client-side.
1114
1122
  *
1115
- * Use this method when you execute the deposit transaction yourself (e.g., with Privy,
1116
- * sponsored transactions, or any custom wallet implementation) and need to register
1117
- * the deposit with the Zyfai backend for tracking and yield optimization.
1123
+ * `depositFunds()` already calls this after the ERC20 transfer. If you send the
1124
+ * transfer yourself (front, Privy, Biconomy, custom wallet) you **must** call
1125
+ * `logDeposit` — otherwise the backend never sees the deposit: a reserved pool
1126
+ * wallet stays reserved (no ownership rotation), and yield/agent tracking does
1127
+ * not start.
1118
1128
  *
1119
- * This is useful for partners who:
1129
+ * Use this method when you execute the deposit transaction yourself and need to
1130
+ * register it with the Zyfai backend.
1131
+ *
1132
+ * This is required for partners who:
1120
1133
  * - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
1121
- * - Have custom wallet implementations
1134
+ * - Have a custom wallet / frontend transfer
1122
1135
  * - Need more control over transaction execution
1123
1136
  *
1124
1137
  * Token is automatically selected based on chain if not provided:
@@ -1388,7 +1401,10 @@ declare class ZyfaiSDK {
1388
1401
  *
1389
1402
  * Reads from `user_onchain_daily_earnings_v2`. Each entry exposes
1390
1403
  * per-chain per-token maps for current / lifetime / unrealized / total
1391
- * earnings plus a daily total delta.
1404
+ * earnings plus a daily total delta (gross and fee-exclusive).
1405
+ *
1406
+ * `daily_total_delta_by_token_withoutFee` is computed by the SDK, not the
1407
+ * API: it is `daily_total_delta_by_token × (1 - feeRate)`.
1392
1408
  *
1393
1409
  * @param walletAddress - Smart wallet address
1394
1410
  * @param startDate - Start date (YYYY-MM-DD format)
@@ -1401,6 +1417,7 @@ declare class ZyfaiSDK {
1401
1417
  * daily.data.forEach(d => {
1402
1418
  * // d.total_earnings_by_token = { "8453": { "USDC": "143.10" } }
1403
1419
  * console.log(d.snapshot_date, d.total_earnings_by_token);
1420
+ * console.log("Delta without fee:", d.daily_total_delta_by_token_withoutFee);
1404
1421
  * });
1405
1422
  * ```
1406
1423
  */
package/dist/index.js CHANGED
@@ -1309,6 +1309,26 @@ function enrichRebalanceLog(log) {
1309
1309
  ...log.newApy !== void 0 ? { newApy_withFee: applyApyFeeToString(log.newApy) } : {}
1310
1310
  };
1311
1311
  }
1312
+ function excludeFeeFromChainTokenEarnings(earnings) {
1313
+ const keepRate = 1 - ZYFI_FEE_RATE;
1314
+ const result = {};
1315
+ Object.entries(earnings).forEach(([chainId, tokens]) => {
1316
+ const tokenMap = {};
1317
+ Object.entries(tokens || {}).forEach(([symbol, amount]) => {
1318
+ tokenMap[symbol] = formatHumanAmount(parseHumanAmount(amount) * keepRate);
1319
+ });
1320
+ result[chainId] = tokenMap;
1321
+ });
1322
+ return result;
1323
+ }
1324
+ function enrichDailyEarningWithoutFee(entry) {
1325
+ return {
1326
+ ...entry,
1327
+ daily_total_delta_by_token_withoutFee: excludeFeeFromChainTokenEarnings(
1328
+ entry.daily_total_delta_by_token
1329
+ )
1330
+ };
1331
+ }
1312
1332
  function enrichPortfolioWithFees(portfolio, currentEarningsByChain) {
1313
1333
  const { byToken, byChainByToken } = computePendingFees(currentEarningsByChain);
1314
1334
  const portfolioByAssetType = portfolio.portfolioByAssetType ? Object.fromEntries(
@@ -2665,15 +2685,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2665
2685
  }
2666
2686
  }
2667
2687
  /**
2668
- * Log a deposit that was executed client-side
2688
+ * Log a deposit that was executed client-side.
2669
2689
  *
2670
- * Use this method when you execute the deposit transaction yourself (e.g., with Privy,
2671
- * sponsored transactions, or any custom wallet implementation) and need to register
2672
- * the deposit with the Zyfai backend for tracking and yield optimization.
2690
+ * `depositFunds()` already calls this after the ERC20 transfer. If you send the
2691
+ * transfer yourself (front, Privy, Biconomy, custom wallet) you **must** call
2692
+ * `logDeposit` — otherwise the backend never sees the deposit: a reserved pool
2693
+ * wallet stays reserved (no ownership rotation), and yield/agent tracking does
2694
+ * not start.
2673
2695
  *
2674
- * This is useful for partners who:
2696
+ * Use this method when you execute the deposit transaction yourself and need to
2697
+ * register it with the Zyfai backend.
2698
+ *
2699
+ * This is required for partners who:
2675
2700
  * - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
2676
- * - Have custom wallet implementations
2701
+ * - Have a custom wallet / frontend transfer
2677
2702
  * - Need more control over transaction execution
2678
2703
  *
2679
2704
  * Token is automatically selected based on chain if not provided:
@@ -3348,7 +3373,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3348
3373
  *
3349
3374
  * Reads from `user_onchain_daily_earnings_v2`. Each entry exposes
3350
3375
  * per-chain per-token maps for current / lifetime / unrealized / total
3351
- * earnings plus a daily total delta.
3376
+ * earnings plus a daily total delta (gross and fee-exclusive).
3377
+ *
3378
+ * `daily_total_delta_by_token_withoutFee` is computed by the SDK, not the
3379
+ * API: it is `daily_total_delta_by_token × (1 - feeRate)`.
3352
3380
  *
3353
3381
  * @param walletAddress - Smart wallet address
3354
3382
  * @param startDate - Start date (YYYY-MM-DD format)
@@ -3361,6 +3389,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3361
3389
  * daily.data.forEach(d => {
3362
3390
  * // d.total_earnings_by_token = { "8453": { "USDC": "143.10" } }
3363
3391
  * console.log(d.snapshot_date, d.total_earnings_by_token);
3392
+ * console.log("Delta without fee:", d.daily_total_delta_by_token_withoutFee);
3364
3393
  * });
3365
3394
  * ```
3366
3395
  */
@@ -3372,15 +3401,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3372
3401
  const response = await this.httpClient.dataGet(
3373
3402
  DATA_ENDPOINTS.DAILY_EARNINGS(walletAddress, startDate, endDate)
3374
3403
  );
3375
- const data = (response.data || []).map((entry) => ({
3376
- snapshot_date: entry.snapshot_date,
3377
- current_earnings_by_token: entry.current_earnings_by_token || {},
3378
- lifetime_earnings_by_token: entry.lifetime_earnings_by_token || {},
3379
- unrealized_earnings_by_token: entry.unrealized_earnings_by_token || {},
3380
- total_earnings_by_token: entry.total_earnings_by_token || {},
3381
- daily_total_delta_by_token: entry.daily_total_delta_by_token || {},
3382
- created_at: entry.created_at
3383
- }));
3404
+ const data = (response.data || []).map(
3405
+ (entry) => enrichDailyEarningWithoutFee({
3406
+ snapshot_date: entry.snapshot_date,
3407
+ current_earnings_by_token: entry.current_earnings_by_token || {},
3408
+ lifetime_earnings_by_token: entry.lifetime_earnings_by_token || {},
3409
+ unrealized_earnings_by_token: entry.unrealized_earnings_by_token || {},
3410
+ total_earnings_by_token: entry.total_earnings_by_token || {},
3411
+ daily_total_delta_by_token: entry.daily_total_delta_by_token || {},
3412
+ created_at: entry.created_at
3413
+ })
3414
+ );
3384
3415
  return {
3385
3416
  success: true,
3386
3417
  walletAddress,
package/dist/index.mjs CHANGED
@@ -1276,6 +1276,26 @@ function enrichRebalanceLog(log) {
1276
1276
  ...log.newApy !== void 0 ? { newApy_withFee: applyApyFeeToString(log.newApy) } : {}
1277
1277
  };
1278
1278
  }
1279
+ function excludeFeeFromChainTokenEarnings(earnings) {
1280
+ const keepRate = 1 - ZYFI_FEE_RATE;
1281
+ const result = {};
1282
+ Object.entries(earnings).forEach(([chainId, tokens]) => {
1283
+ const tokenMap = {};
1284
+ Object.entries(tokens || {}).forEach(([symbol, amount]) => {
1285
+ tokenMap[symbol] = formatHumanAmount(parseHumanAmount(amount) * keepRate);
1286
+ });
1287
+ result[chainId] = tokenMap;
1288
+ });
1289
+ return result;
1290
+ }
1291
+ function enrichDailyEarningWithoutFee(entry) {
1292
+ return {
1293
+ ...entry,
1294
+ daily_total_delta_by_token_withoutFee: excludeFeeFromChainTokenEarnings(
1295
+ entry.daily_total_delta_by_token
1296
+ )
1297
+ };
1298
+ }
1279
1299
  function enrichPortfolioWithFees(portfolio, currentEarningsByChain) {
1280
1300
  const { byToken, byChainByToken } = computePendingFees(currentEarningsByChain);
1281
1301
  const portfolioByAssetType = portfolio.portfolioByAssetType ? Object.fromEntries(
@@ -2632,15 +2652,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2632
2652
  }
2633
2653
  }
2634
2654
  /**
2635
- * Log a deposit that was executed client-side
2655
+ * Log a deposit that was executed client-side.
2636
2656
  *
2637
- * Use this method when you execute the deposit transaction yourself (e.g., with Privy,
2638
- * sponsored transactions, or any custom wallet implementation) and need to register
2639
- * the deposit with the Zyfai backend for tracking and yield optimization.
2657
+ * `depositFunds()` already calls this after the ERC20 transfer. If you send the
2658
+ * transfer yourself (front, Privy, Biconomy, custom wallet) you **must** call
2659
+ * `logDeposit` — otherwise the backend never sees the deposit: a reserved pool
2660
+ * wallet stays reserved (no ownership rotation), and yield/agent tracking does
2661
+ * not start.
2640
2662
  *
2641
- * This is useful for partners who:
2663
+ * Use this method when you execute the deposit transaction yourself and need to
2664
+ * register it with the Zyfai backend.
2665
+ *
2666
+ * This is required for partners who:
2642
2667
  * - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
2643
- * - Have custom wallet implementations
2668
+ * - Have a custom wallet / frontend transfer
2644
2669
  * - Need more control over transaction execution
2645
2670
  *
2646
2671
  * Token is automatically selected based on chain if not provided:
@@ -3315,7 +3340,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3315
3340
  *
3316
3341
  * Reads from `user_onchain_daily_earnings_v2`. Each entry exposes
3317
3342
  * per-chain per-token maps for current / lifetime / unrealized / total
3318
- * earnings plus a daily total delta.
3343
+ * earnings plus a daily total delta (gross and fee-exclusive).
3344
+ *
3345
+ * `daily_total_delta_by_token_withoutFee` is computed by the SDK, not the
3346
+ * API: it is `daily_total_delta_by_token × (1 - feeRate)`.
3319
3347
  *
3320
3348
  * @param walletAddress - Smart wallet address
3321
3349
  * @param startDate - Start date (YYYY-MM-DD format)
@@ -3328,6 +3356,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3328
3356
  * daily.data.forEach(d => {
3329
3357
  * // d.total_earnings_by_token = { "8453": { "USDC": "143.10" } }
3330
3358
  * console.log(d.snapshot_date, d.total_earnings_by_token);
3359
+ * console.log("Delta without fee:", d.daily_total_delta_by_token_withoutFee);
3331
3360
  * });
3332
3361
  * ```
3333
3362
  */
@@ -3339,15 +3368,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
3339
3368
  const response = await this.httpClient.dataGet(
3340
3369
  DATA_ENDPOINTS.DAILY_EARNINGS(walletAddress, startDate, endDate)
3341
3370
  );
3342
- const data = (response.data || []).map((entry) => ({
3343
- snapshot_date: entry.snapshot_date,
3344
- current_earnings_by_token: entry.current_earnings_by_token || {},
3345
- lifetime_earnings_by_token: entry.lifetime_earnings_by_token || {},
3346
- unrealized_earnings_by_token: entry.unrealized_earnings_by_token || {},
3347
- total_earnings_by_token: entry.total_earnings_by_token || {},
3348
- daily_total_delta_by_token: entry.daily_total_delta_by_token || {},
3349
- created_at: entry.created_at
3350
- }));
3371
+ const data = (response.data || []).map(
3372
+ (entry) => enrichDailyEarningWithoutFee({
3373
+ snapshot_date: entry.snapshot_date,
3374
+ current_earnings_by_token: entry.current_earnings_by_token || {},
3375
+ lifetime_earnings_by_token: entry.lifetime_earnings_by_token || {},
3376
+ unrealized_earnings_by_token: entry.unrealized_earnings_by_token || {},
3377
+ total_earnings_by_token: entry.total_earnings_by_token || {},
3378
+ daily_total_delta_by_token: entry.daily_total_delta_by_token || {},
3379
+ created_at: entry.created_at
3380
+ })
3381
+ );
3351
3382
  return {
3352
3383
  success: true,
3353
3384
  walletAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.53",
3
+ "version": "0.2.55",
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",