@zyfai/sdk 0.2.54 → 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 +5 -2
- package/dist/index.d.mts +18 -7
- package/dist/index.d.ts +18 -7
- package/dist/index.js +47 -16
- package/dist/index.mjs +47 -16
- package/package.json +1 -1
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
|
|
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
|
|
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
|
|
|
@@ -800,6 +801,8 @@ const daily = await sdk.getDailyEarnings(
|
|
|
800
801
|
);
|
|
801
802
|
daily.data.forEach((d) => {
|
|
802
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);
|
|
803
806
|
});
|
|
804
807
|
```
|
|
805
808
|
|
package/dist/index.d.mts
CHANGED
|
@@ -339,6 +339,8 @@ interface DailyEarning {
|
|
|
339
339
|
unrealized_earnings_by_token: ChainTokenEarnings;
|
|
340
340
|
total_earnings_by_token: ChainTokenEarnings;
|
|
341
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;
|
|
342
344
|
created_at?: string;
|
|
343
345
|
}
|
|
344
346
|
interface DailyEarningsResponse {
|
|
@@ -1116,15 +1118,20 @@ declare class ZyfaiSDK {
|
|
|
1116
1118
|
}>;
|
|
1117
1119
|
depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
|
|
1118
1120
|
/**
|
|
1119
|
-
* Log a deposit that was executed client-side
|
|
1121
|
+
* Log a deposit that was executed client-side.
|
|
1120
1122
|
*
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
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.
|
|
1124
1128
|
*
|
|
1125
|
-
*
|
|
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:
|
|
1126
1133
|
* - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
|
|
1127
|
-
* - Have custom wallet
|
|
1134
|
+
* - Have a custom wallet / frontend transfer
|
|
1128
1135
|
* - Need more control over transaction execution
|
|
1129
1136
|
*
|
|
1130
1137
|
* Token is automatically selected based on chain if not provided:
|
|
@@ -1394,7 +1401,10 @@ declare class ZyfaiSDK {
|
|
|
1394
1401
|
*
|
|
1395
1402
|
* Reads from `user_onchain_daily_earnings_v2`. Each entry exposes
|
|
1396
1403
|
* per-chain per-token maps for current / lifetime / unrealized / total
|
|
1397
|
-
* 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)`.
|
|
1398
1408
|
*
|
|
1399
1409
|
* @param walletAddress - Smart wallet address
|
|
1400
1410
|
* @param startDate - Start date (YYYY-MM-DD format)
|
|
@@ -1407,6 +1417,7 @@ declare class ZyfaiSDK {
|
|
|
1407
1417
|
* daily.data.forEach(d => {
|
|
1408
1418
|
* // d.total_earnings_by_token = { "8453": { "USDC": "143.10" } }
|
|
1409
1419
|
* console.log(d.snapshot_date, d.total_earnings_by_token);
|
|
1420
|
+
* console.log("Delta without fee:", d.daily_total_delta_by_token_withoutFee);
|
|
1410
1421
|
* });
|
|
1411
1422
|
* ```
|
|
1412
1423
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -339,6 +339,8 @@ interface DailyEarning {
|
|
|
339
339
|
unrealized_earnings_by_token: ChainTokenEarnings;
|
|
340
340
|
total_earnings_by_token: ChainTokenEarnings;
|
|
341
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;
|
|
342
344
|
created_at?: string;
|
|
343
345
|
}
|
|
344
346
|
interface DailyEarningsResponse {
|
|
@@ -1116,15 +1118,20 @@ declare class ZyfaiSDK {
|
|
|
1116
1118
|
}>;
|
|
1117
1119
|
depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
|
|
1118
1120
|
/**
|
|
1119
|
-
* Log a deposit that was executed client-side
|
|
1121
|
+
* Log a deposit that was executed client-side.
|
|
1120
1122
|
*
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
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.
|
|
1124
1128
|
*
|
|
1125
|
-
*
|
|
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:
|
|
1126
1133
|
* - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
|
|
1127
|
-
* - Have custom wallet
|
|
1134
|
+
* - Have a custom wallet / frontend transfer
|
|
1128
1135
|
* - Need more control over transaction execution
|
|
1129
1136
|
*
|
|
1130
1137
|
* Token is automatically selected based on chain if not provided:
|
|
@@ -1394,7 +1401,10 @@ declare class ZyfaiSDK {
|
|
|
1394
1401
|
*
|
|
1395
1402
|
* Reads from `user_onchain_daily_earnings_v2`. Each entry exposes
|
|
1396
1403
|
* per-chain per-token maps for current / lifetime / unrealized / total
|
|
1397
|
-
* 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)`.
|
|
1398
1408
|
*
|
|
1399
1409
|
* @param walletAddress - Smart wallet address
|
|
1400
1410
|
* @param startDate - Start date (YYYY-MM-DD format)
|
|
@@ -1407,6 +1417,7 @@ declare class ZyfaiSDK {
|
|
|
1407
1417
|
* daily.data.forEach(d => {
|
|
1408
1418
|
* // d.total_earnings_by_token = { "8453": { "USDC": "143.10" } }
|
|
1409
1419
|
* console.log(d.snapshot_date, d.total_earnings_by_token);
|
|
1420
|
+
* console.log("Delta without fee:", d.daily_total_delta_by_token_withoutFee);
|
|
1410
1421
|
* });
|
|
1411
1422
|
* ```
|
|
1412
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
|
-
*
|
|
2671
|
-
*
|
|
2672
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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(
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
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
|
-
*
|
|
2638
|
-
*
|
|
2639
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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(
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
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.
|
|
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",
|