@zyfai/sdk 0.2.46 → 0.2.47
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 +0 -36
- package/dist/index.d.mts +36 -33
- package/dist/index.d.ts +36 -33
- package/dist/index.js +71 -350
- package/dist/index.mjs +71 -350
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -532,32 +532,6 @@ positions.positions.forEach((bundle) => {
|
|
|
532
532
|
|
|
533
533
|
**Note**: This endpoint uses `/api/v1/data/position?walletAddress={address}` (Smart wallet address) and returns bundles with nested slot data. Use each slot's `underlyingAmount` for the canonical token balance.
|
|
534
534
|
|
|
535
|
-
#### Get Portfolio (with fee-adjusted balances)
|
|
536
|
-
|
|
537
|
-
Returns the full wallet portfolio plus net-of-pending-fee fields. Pending fee is
|
|
538
|
-
`current` onchain earnings × 10%. Gross balances are unchanged.
|
|
539
|
-
|
|
540
|
-
```typescript
|
|
541
|
-
const { portfolio } = await sdk.getPortfolio(userAddress);
|
|
542
|
-
|
|
543
|
-
// Gross vs net (after pending Zyfi fee)
|
|
544
|
-
console.log(portfolio.portfolioByAssetType?.usdc?.balance);
|
|
545
|
-
console.log(portfolio.portfolioByAssetType?.usdc?.balanceWithFee);
|
|
546
|
-
|
|
547
|
-
portfolio.positions?.forEach((slot) => {
|
|
548
|
-
console.log(slot.pool, slot.underlyingAmount, slot.underlyingAmountWithFee);
|
|
549
|
-
});
|
|
550
|
-
```
|
|
551
|
-
|
|
552
|
-
**Fee formula**
|
|
553
|
-
|
|
554
|
-
- Pending fee = `current_earnings × 0.1` (unrealised yield only)
|
|
555
|
-
- `balanceWithFee` / `underlyingAmountWithFee` = live − pending fee share
|
|
556
|
-
- If earnings cannot be fetched, `*WithFee` equals the gross value
|
|
557
|
-
|
|
558
|
-
**Note**: Portfolio balances are live; earnings used for the fee may come from a
|
|
559
|
-
snapshot, so net values can differ slightly from a fully live calculation.
|
|
560
|
-
|
|
561
535
|
### 8. Analytics & Data Endpoints
|
|
562
536
|
|
|
563
537
|
The SDK provides access to various analytics and data endpoints:
|
|
@@ -755,23 +729,13 @@ const earnings = await sdk.getOnchainEarnings(walletAddress);
|
|
|
755
729
|
console.log("Total by token:", earnings.data.totalEarningsByToken);
|
|
756
730
|
// Per-chain totals (chain → token → amount): { "8453": { "USDC": "0.01" }, "42161": {...} }
|
|
757
731
|
console.log("Total by chain:", earnings.data.totalEarningsByChain);
|
|
758
|
-
// Net totals: lifetime + unrealized + current × 0.9 (never total × 0.9)
|
|
759
|
-
console.log("Net by token:", earnings.data.totalEarningsByTokenWithFee);
|
|
760
|
-
console.log("Net by chain:", earnings.data.totalEarningsByChainWithFee);
|
|
761
732
|
```
|
|
762
733
|
|
|
763
|
-
**Fee formula for `*WithFee` earnings fields**
|
|
764
|
-
|
|
765
|
-
- `totalWithFee = lifetime + unrealized + current × 0.9`
|
|
766
|
-
- Do **not** apply `× 0.9` to lifetime or unrealized
|
|
767
|
-
- Aligns with portfolio: pending fee = `current × 0.1` only
|
|
768
|
-
|
|
769
734
|
#### Calculate Onchain Earnings (Refresh)
|
|
770
735
|
|
|
771
736
|
```typescript
|
|
772
737
|
const updated = await sdk.calculateOnchainEarnings(walletAddress);
|
|
773
738
|
console.log("Updated earnings:", updated.data.totalEarningsByToken);
|
|
774
|
-
console.log("Net earnings:", updated.data.totalEarningsByTokenWithFee);
|
|
775
739
|
```
|
|
776
740
|
|
|
777
741
|
#### Get Daily Earnings
|
package/dist/index.d.mts
CHANGED
|
@@ -142,8 +142,6 @@ interface Portfolio {
|
|
|
142
142
|
}
|
|
143
143
|
interface PortfolioAssetBalance {
|
|
144
144
|
balance: Hex;
|
|
145
|
-
/** Net balance after pending Zyfi fee (live − current × feeRate). */
|
|
146
|
-
balanceWithFee?: Hex;
|
|
147
145
|
decimals: number;
|
|
148
146
|
}
|
|
149
147
|
type PortfolioByAssetType = Record<string, PortfolioAssetBalance>;
|
|
@@ -177,12 +175,8 @@ interface PositionSlot {
|
|
|
177
175
|
token_id?: string;
|
|
178
176
|
token_symbol?: string;
|
|
179
177
|
token_icon?: string;
|
|
180
|
-
assetType?: string;
|
|
181
|
-
decimals?: number;
|
|
182
178
|
amount?: string;
|
|
183
179
|
underlyingAmount?: string;
|
|
184
|
-
/** Net underlying amount after this position's share of pending Zyfi fee. */
|
|
185
|
-
underlyingAmountWithFee?: string;
|
|
186
180
|
pool_apy?: number;
|
|
187
181
|
pool_tvl?: number;
|
|
188
182
|
liquidity?: number;
|
|
@@ -294,13 +288,6 @@ interface OnchainEarnings {
|
|
|
294
288
|
walletAddress: string;
|
|
295
289
|
totalEarningsByToken: TokenEarnings;
|
|
296
290
|
totalEarningsByChain?: ChainTokenEarnings;
|
|
297
|
-
/**
|
|
298
|
-
* Net totals: lifetime + unrealized + current × (1 - feeRate).
|
|
299
|
-
* Unrealized is treated like lifetime (no pending fee).
|
|
300
|
-
* Does not apply feeRate to lifetime (already crystallised).
|
|
301
|
-
*/
|
|
302
|
-
totalEarningsByTokenWithFee: TokenEarnings;
|
|
303
|
-
totalEarningsByChainWithFee?: ChainTokenEarnings;
|
|
304
291
|
lastCheckTimestamp?: string;
|
|
305
292
|
lastLogDate?: Record<string, string | null>;
|
|
306
293
|
}
|
|
@@ -1063,6 +1050,32 @@ declare class ZyfaiSDK {
|
|
|
1063
1050
|
* await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
|
|
1064
1051
|
* ```
|
|
1065
1052
|
*/
|
|
1053
|
+
/**
|
|
1054
|
+
* Deploy the connected predeployed (pool) wallet on one or more chains.
|
|
1055
|
+
*
|
|
1056
|
+
* A pool wallet is only deployed on the chains it has been onboarded to (see
|
|
1057
|
+
* the `chains` array from getSmartWalletByEOA); every other supported chain is
|
|
1058
|
+
* counterfactual until deployed here. The backend deploys + rotates the same
|
|
1059
|
+
* address on each chain in parallel (sponsored, no user signature) and only
|
|
1060
|
+
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
1061
|
+
* already deployed are a no-op.
|
|
1062
|
+
*
|
|
1063
|
+
* `depositFunds` calls this automatically when the target chain isn't deployed,
|
|
1064
|
+
* so most integrations never need it directly; use it to pre-provision chains.
|
|
1065
|
+
*
|
|
1066
|
+
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
1067
|
+
*/
|
|
1068
|
+
deployOnChains(chainIds: SupportedChainId[]): Promise<{
|
|
1069
|
+
success: boolean;
|
|
1070
|
+
safeAddress: string;
|
|
1071
|
+
chains: number[];
|
|
1072
|
+
status: string;
|
|
1073
|
+
}>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
1076
|
+
* responds, so this only guards against read-after-write RPC lag.
|
|
1077
|
+
*/
|
|
1078
|
+
private waitForSafeDeployed;
|
|
1066
1079
|
depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
|
|
1067
1080
|
/**
|
|
1068
1081
|
* Log a deposit that was executed client-side
|
|
@@ -1162,23 +1175,19 @@ declare class ZyfaiSDK {
|
|
|
1162
1175
|
*/
|
|
1163
1176
|
getPositions(userAddress: string, chainId?: SupportedChainId): Promise<PortfolioResponse>;
|
|
1164
1177
|
/**
|
|
1165
|
-
* Get
|
|
1166
|
-
* net-of-pending-fee fields (`balanceWithFee`, `underlyingAmountWithFee`).
|
|
1167
|
-
*
|
|
1168
|
-
* Pending fee is derived from onchain `current` earnings × fee rate.
|
|
1169
|
-
* Gross balances are unchanged. If earnings cannot be fetched, `*WithFee`
|
|
1170
|
-
* equals the gross value so the response shape stays stable.
|
|
1171
|
-
*
|
|
1172
|
-
* Note: portfolio balances are live; earnings used for the fee may be from
|
|
1173
|
-
* a snapshot, so net values can differ slightly from a fully live calc.
|
|
1178
|
+
* Get all active positions and portfolio for a user
|
|
1174
1179
|
*
|
|
1175
1180
|
* @param userAddress - User's EOA address
|
|
1176
|
-
* @
|
|
1181
|
+
* @param chainId - Optional: Filter by specific chain ID
|
|
1182
|
+
* @returns User's positions across all protocols
|
|
1177
1183
|
*
|
|
1178
1184
|
* @example
|
|
1179
1185
|
* ```typescript
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1186
|
+
* // Get all positions across all chains
|
|
1187
|
+
* const positions = await sdk.getPositions(userAddress);
|
|
1188
|
+
*
|
|
1189
|
+
* // Get positions on a specific chain
|
|
1190
|
+
* const basePositions = await sdk.getPositions(userAddress, 8453);
|
|
1182
1191
|
* ```
|
|
1183
1192
|
*/
|
|
1184
1193
|
getPortfolio(userAddress: string): Promise<PortfolioDetailedResponse>;
|
|
@@ -1301,10 +1310,6 @@ declare class ZyfaiSDK {
|
|
|
1301
1310
|
/**
|
|
1302
1311
|
* Get onchain earnings for a wallet
|
|
1303
1312
|
*
|
|
1304
|
-
* Includes gross totals plus net-of-fee totals:
|
|
1305
|
-
* `totalEarningsByTokenWithFee = lifetime + unrealized + current × (1 - feeRate)`.
|
|
1306
|
-
* Lifetime and unrealized are never multiplied by the keep-rate.
|
|
1307
|
-
*
|
|
1308
1313
|
* @param walletAddress - Smart wallet address
|
|
1309
1314
|
* @returns Onchain earnings data with per-token breakdowns
|
|
1310
1315
|
*
|
|
@@ -1312,15 +1317,13 @@ declare class ZyfaiSDK {
|
|
|
1312
1317
|
* ```typescript
|
|
1313
1318
|
* const earnings = await sdk.getOnchainEarnings("0x...");
|
|
1314
1319
|
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
1315
|
-
* console.log("Net USDC:", earnings.data.totalEarningsByTokenWithFee["USDC"]);
|
|
1316
1320
|
* console.log("Total on Arbitrum:", earnings.data.totalEarningsByChain?.["42161"]);
|
|
1317
1321
|
* ```
|
|
1318
1322
|
*/
|
|
1319
1323
|
getOnchainEarnings(walletAddress: string): Promise<OnchainEarningsResponse>;
|
|
1320
1324
|
/**
|
|
1321
1325
|
* Calculate/refresh onchain earnings for a wallet
|
|
1322
|
-
* This triggers a recalculation of earnings on the backend
|
|
1323
|
-
* Response shape matches `getOnchainEarnings` (includes `*WithFee` nets).
|
|
1326
|
+
* This triggers a recalculation of earnings on the backend
|
|
1324
1327
|
*
|
|
1325
1328
|
* @param walletAddress - Smart wallet address
|
|
1326
1329
|
* @returns Updated onchain earnings data with per-token breakdowns
|
|
@@ -1329,7 +1332,7 @@ declare class ZyfaiSDK {
|
|
|
1329
1332
|
* ```typescript
|
|
1330
1333
|
* const earnings = await sdk.calculateOnchainEarnings("0x...");
|
|
1331
1334
|
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
1332
|
-
* console.log("
|
|
1335
|
+
* console.log("Per-chain total:", earnings.data.totalEarningsByChain);
|
|
1333
1336
|
* ```
|
|
1334
1337
|
*/
|
|
1335
1338
|
calculateOnchainEarnings(walletAddress: string): Promise<OnchainEarningsResponse>;
|
package/dist/index.d.ts
CHANGED
|
@@ -142,8 +142,6 @@ interface Portfolio {
|
|
|
142
142
|
}
|
|
143
143
|
interface PortfolioAssetBalance {
|
|
144
144
|
balance: Hex;
|
|
145
|
-
/** Net balance after pending Zyfi fee (live − current × feeRate). */
|
|
146
|
-
balanceWithFee?: Hex;
|
|
147
145
|
decimals: number;
|
|
148
146
|
}
|
|
149
147
|
type PortfolioByAssetType = Record<string, PortfolioAssetBalance>;
|
|
@@ -177,12 +175,8 @@ interface PositionSlot {
|
|
|
177
175
|
token_id?: string;
|
|
178
176
|
token_symbol?: string;
|
|
179
177
|
token_icon?: string;
|
|
180
|
-
assetType?: string;
|
|
181
|
-
decimals?: number;
|
|
182
178
|
amount?: string;
|
|
183
179
|
underlyingAmount?: string;
|
|
184
|
-
/** Net underlying amount after this position's share of pending Zyfi fee. */
|
|
185
|
-
underlyingAmountWithFee?: string;
|
|
186
180
|
pool_apy?: number;
|
|
187
181
|
pool_tvl?: number;
|
|
188
182
|
liquidity?: number;
|
|
@@ -294,13 +288,6 @@ interface OnchainEarnings {
|
|
|
294
288
|
walletAddress: string;
|
|
295
289
|
totalEarningsByToken: TokenEarnings;
|
|
296
290
|
totalEarningsByChain?: ChainTokenEarnings;
|
|
297
|
-
/**
|
|
298
|
-
* Net totals: lifetime + unrealized + current × (1 - feeRate).
|
|
299
|
-
* Unrealized is treated like lifetime (no pending fee).
|
|
300
|
-
* Does not apply feeRate to lifetime (already crystallised).
|
|
301
|
-
*/
|
|
302
|
-
totalEarningsByTokenWithFee: TokenEarnings;
|
|
303
|
-
totalEarningsByChainWithFee?: ChainTokenEarnings;
|
|
304
291
|
lastCheckTimestamp?: string;
|
|
305
292
|
lastLogDate?: Record<string, string | null>;
|
|
306
293
|
}
|
|
@@ -1063,6 +1050,32 @@ declare class ZyfaiSDK {
|
|
|
1063
1050
|
* await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
|
|
1064
1051
|
* ```
|
|
1065
1052
|
*/
|
|
1053
|
+
/**
|
|
1054
|
+
* Deploy the connected predeployed (pool) wallet on one or more chains.
|
|
1055
|
+
*
|
|
1056
|
+
* A pool wallet is only deployed on the chains it has been onboarded to (see
|
|
1057
|
+
* the `chains` array from getSmartWalletByEOA); every other supported chain is
|
|
1058
|
+
* counterfactual until deployed here. The backend deploys + rotates the same
|
|
1059
|
+
* address on each chain in parallel (sponsored, no user signature) and only
|
|
1060
|
+
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
1061
|
+
* already deployed are a no-op.
|
|
1062
|
+
*
|
|
1063
|
+
* `depositFunds` calls this automatically when the target chain isn't deployed,
|
|
1064
|
+
* so most integrations never need it directly; use it to pre-provision chains.
|
|
1065
|
+
*
|
|
1066
|
+
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
1067
|
+
*/
|
|
1068
|
+
deployOnChains(chainIds: SupportedChainId[]): Promise<{
|
|
1069
|
+
success: boolean;
|
|
1070
|
+
safeAddress: string;
|
|
1071
|
+
chains: number[];
|
|
1072
|
+
status: string;
|
|
1073
|
+
}>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
1076
|
+
* responds, so this only guards against read-after-write RPC lag.
|
|
1077
|
+
*/
|
|
1078
|
+
private waitForSafeDeployed;
|
|
1066
1079
|
depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
|
|
1067
1080
|
/**
|
|
1068
1081
|
* Log a deposit that was executed client-side
|
|
@@ -1162,23 +1175,19 @@ declare class ZyfaiSDK {
|
|
|
1162
1175
|
*/
|
|
1163
1176
|
getPositions(userAddress: string, chainId?: SupportedChainId): Promise<PortfolioResponse>;
|
|
1164
1177
|
/**
|
|
1165
|
-
* Get
|
|
1166
|
-
* net-of-pending-fee fields (`balanceWithFee`, `underlyingAmountWithFee`).
|
|
1167
|
-
*
|
|
1168
|
-
* Pending fee is derived from onchain `current` earnings × fee rate.
|
|
1169
|
-
* Gross balances are unchanged. If earnings cannot be fetched, `*WithFee`
|
|
1170
|
-
* equals the gross value so the response shape stays stable.
|
|
1171
|
-
*
|
|
1172
|
-
* Note: portfolio balances are live; earnings used for the fee may be from
|
|
1173
|
-
* a snapshot, so net values can differ slightly from a fully live calc.
|
|
1178
|
+
* Get all active positions and portfolio for a user
|
|
1174
1179
|
*
|
|
1175
1180
|
* @param userAddress - User's EOA address
|
|
1176
|
-
* @
|
|
1181
|
+
* @param chainId - Optional: Filter by specific chain ID
|
|
1182
|
+
* @returns User's positions across all protocols
|
|
1177
1183
|
*
|
|
1178
1184
|
* @example
|
|
1179
1185
|
* ```typescript
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1186
|
+
* // Get all positions across all chains
|
|
1187
|
+
* const positions = await sdk.getPositions(userAddress);
|
|
1188
|
+
*
|
|
1189
|
+
* // Get positions on a specific chain
|
|
1190
|
+
* const basePositions = await sdk.getPositions(userAddress, 8453);
|
|
1182
1191
|
* ```
|
|
1183
1192
|
*/
|
|
1184
1193
|
getPortfolio(userAddress: string): Promise<PortfolioDetailedResponse>;
|
|
@@ -1301,10 +1310,6 @@ declare class ZyfaiSDK {
|
|
|
1301
1310
|
/**
|
|
1302
1311
|
* Get onchain earnings for a wallet
|
|
1303
1312
|
*
|
|
1304
|
-
* Includes gross totals plus net-of-fee totals:
|
|
1305
|
-
* `totalEarningsByTokenWithFee = lifetime + unrealized + current × (1 - feeRate)`.
|
|
1306
|
-
* Lifetime and unrealized are never multiplied by the keep-rate.
|
|
1307
|
-
*
|
|
1308
1313
|
* @param walletAddress - Smart wallet address
|
|
1309
1314
|
* @returns Onchain earnings data with per-token breakdowns
|
|
1310
1315
|
*
|
|
@@ -1312,15 +1317,13 @@ declare class ZyfaiSDK {
|
|
|
1312
1317
|
* ```typescript
|
|
1313
1318
|
* const earnings = await sdk.getOnchainEarnings("0x...");
|
|
1314
1319
|
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
1315
|
-
* console.log("Net USDC:", earnings.data.totalEarningsByTokenWithFee["USDC"]);
|
|
1316
1320
|
* console.log("Total on Arbitrum:", earnings.data.totalEarningsByChain?.["42161"]);
|
|
1317
1321
|
* ```
|
|
1318
1322
|
*/
|
|
1319
1323
|
getOnchainEarnings(walletAddress: string): Promise<OnchainEarningsResponse>;
|
|
1320
1324
|
/**
|
|
1321
1325
|
* Calculate/refresh onchain earnings for a wallet
|
|
1322
|
-
* This triggers a recalculation of earnings on the backend
|
|
1323
|
-
* Response shape matches `getOnchainEarnings` (includes `*WithFee` nets).
|
|
1326
|
+
* This triggers a recalculation of earnings on the backend
|
|
1324
1327
|
*
|
|
1325
1328
|
* @param walletAddress - Smart wallet address
|
|
1326
1329
|
* @returns Updated onchain earnings data with per-token breakdowns
|
|
@@ -1329,7 +1332,7 @@ declare class ZyfaiSDK {
|
|
|
1329
1332
|
* ```typescript
|
|
1330
1333
|
* const earnings = await sdk.calculateOnchainEarnings("0x...");
|
|
1331
1334
|
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
1332
|
-
* console.log("
|
|
1335
|
+
* console.log("Per-chain total:", earnings.data.totalEarningsByChain);
|
|
1333
1336
|
* ```
|
|
1334
1337
|
*/
|
|
1335
1338
|
calculateOnchainEarnings(walletAddress: string): Promise<OnchainEarningsResponse>;
|