@zyfai/sdk 0.2.22 → 0.2.24
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 +60 -10
- package/dist/index.d.mts +145 -114
- package/dist/index.d.ts +145 -114
- package/dist/index.js +327 -192
- package/dist/index.mjs +327 -192
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -66,8 +66,8 @@ var ENDPOINTS = {
|
|
|
66
66
|
// Data (v1)
|
|
67
67
|
DATA_POSITION: (walletAddress) => `/data/position?walletAddress=${walletAddress}`,
|
|
68
68
|
DATA_HISTORY: (walletAddress, chainId) => `/data/history?walletAddress=${walletAddress}&chainId=${chainId}`,
|
|
69
|
-
DATA_TVL: "/data/tvl",
|
|
70
|
-
DATA_VOLUME:
|
|
69
|
+
DATA_TVL: "/data/usd-tvl",
|
|
70
|
+
DATA_VOLUME: (assetType) => `/data/volume?assetType=${assetType}`,
|
|
71
71
|
DATA_FIRST_TOPUP: (walletAddress, chainId) => `/data/first-topup?walletAddress=${walletAddress}&chainId=${chainId}`,
|
|
72
72
|
DATA_ACTIVE_WALLETS: (chainId) => `/data/active-wallets?chainId=${chainId}`,
|
|
73
73
|
DATA_BY_EOA: (address) => `/data/by-eoa?address=${address}`,
|
|
@@ -86,25 +86,48 @@ var DATA_ENDPOINTS = {
|
|
|
86
86
|
// User Initialization
|
|
87
87
|
USER_INITIALIZE: "/api/earnings/initialize",
|
|
88
88
|
// Earnings
|
|
89
|
-
ONCHAIN_EARNINGS: (walletAddress) => `/
|
|
90
|
-
CALCULATE_ONCHAIN_EARNINGS: "/
|
|
89
|
+
ONCHAIN_EARNINGS: (walletAddress) => `/onchain-earnings/onchain-earnings?walletAddress=${walletAddress}`,
|
|
90
|
+
CALCULATE_ONCHAIN_EARNINGS: "/onchain-earnings/calculate-onchain-earnings",
|
|
91
91
|
DAILY_EARNINGS: (walletAddress, startDate, endDate) => {
|
|
92
|
-
let url = `/
|
|
92
|
+
let url = `/onchain-earnings/daily-earnings?walletAddress=${walletAddress}`;
|
|
93
93
|
if (startDate) url += `&startDate=${startDate}`;
|
|
94
94
|
if (endDate) url += `&endDate=${endDate}`;
|
|
95
95
|
return url;
|
|
96
96
|
},
|
|
97
|
-
// Portfolio
|
|
98
|
-
DEBANK_PORTFOLIO_MULTICHAIN: (address) => `/debank/portfolio/multichain/${address}`,
|
|
99
97
|
// Opportunities
|
|
100
|
-
OPPORTUNITIES_SAFE: (chainId) =>
|
|
101
|
-
|
|
98
|
+
OPPORTUNITIES_SAFE: (chainId, asset, status) => {
|
|
99
|
+
const params = [];
|
|
100
|
+
if (chainId !== void 0) params.push(`chainId=${chainId}`);
|
|
101
|
+
if (asset) params.push(`asset=${asset}`);
|
|
102
|
+
if (status) params.push(`status=${status}`);
|
|
103
|
+
return params.length > 0 ? `/opportunities/safe?${params.join("&")}` : "/opportunities/safe";
|
|
104
|
+
},
|
|
105
|
+
OPPORTUNITIES_DEGEN: (chainId, asset, status) => {
|
|
106
|
+
const params = [];
|
|
107
|
+
if (chainId !== void 0) params.push(`chainId=${chainId}`);
|
|
108
|
+
if (asset) params.push(`asset=${asset}`);
|
|
109
|
+
if (status) params.push(`status=${status}`);
|
|
110
|
+
return params.length > 0 ? `/opportunities/degen-strategies?${params.join("&")}` : "/opportunities/degen-strategies";
|
|
111
|
+
},
|
|
102
112
|
// APY History
|
|
103
|
-
DAILY_APY_HISTORY_WEIGHTED: (walletAddress, days) => `/daily-apy-history/weighted/${walletAddress}${days ? `?days=${days}` : ""}`,
|
|
113
|
+
DAILY_APY_HISTORY_WEIGHTED: (walletAddress, days) => `/daily-apy-history/weighted-multi-asset/${walletAddress}${days ? `?days=${days}` : ""}`,
|
|
104
114
|
// Rebalance
|
|
105
|
-
REBALANCE_INFO: (
|
|
115
|
+
REBALANCE_INFO: (options) => {
|
|
116
|
+
const params = [];
|
|
117
|
+
if (options?.isCrossChain !== void 0) params.push(`isCrossChain=${options.isCrossChain}`);
|
|
118
|
+
if (options?.tokenSymbol) params.push(`tokenSymbol=${options.tokenSymbol}`);
|
|
119
|
+
return params.length > 0 ? `/rebalance/rebalance-info?${params.join("&")}` : "/rebalance/rebalance-info";
|
|
120
|
+
},
|
|
106
121
|
// APY Per Strategy
|
|
107
|
-
APY_PER_STRATEGY: (
|
|
122
|
+
APY_PER_STRATEGY: (options = {}) => {
|
|
123
|
+
const params = [];
|
|
124
|
+
if (options.isCrossChain !== void 0) params.push(`isCrossChain=${options.isCrossChain}`);
|
|
125
|
+
if (options.days !== void 0) params.push(`days=${options.days}`);
|
|
126
|
+
if (options.strategy) params.push(`strategy=${options.strategy}`);
|
|
127
|
+
if (options.chainId !== void 0) params.push(`chainId=${options.chainId}`);
|
|
128
|
+
if (options.tokenSymbol) params.push(`tokenSymbol=${options.tokenSymbol}`);
|
|
129
|
+
return params.length > 0 ? `/rebalance/rebalance-info?${params.join("&")}` : "/rebalance/rebalance-info";
|
|
130
|
+
}
|
|
108
131
|
};
|
|
109
132
|
|
|
110
133
|
// src/utils/http-client.ts
|
|
@@ -403,8 +426,71 @@ var DEFAULT_TOKEN_ADDRESSES = {
|
|
|
403
426
|
9745: "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb"
|
|
404
427
|
// USDT on Plasma
|
|
405
428
|
};
|
|
406
|
-
var
|
|
407
|
-
|
|
429
|
+
var ASSET_CONFIGS = {
|
|
430
|
+
USDC: {
|
|
431
|
+
symbol: "USDC",
|
|
432
|
+
assetType: "usdc",
|
|
433
|
+
displayName: "USDC",
|
|
434
|
+
icon: "/ai-dashboard/usdc-token.png",
|
|
435
|
+
decimals: 6,
|
|
436
|
+
tokenSymbols: ["USDC", "USDC.e", "USDT", "USDT0"],
|
|
437
|
+
tokenSymbolsByChainId: {
|
|
438
|
+
8453: "USDC",
|
|
439
|
+
42161: "USDC",
|
|
440
|
+
9745: "USDT0",
|
|
441
|
+
146: "USDC.e",
|
|
442
|
+
1: "USDC"
|
|
443
|
+
},
|
|
444
|
+
addresses: {
|
|
445
|
+
8453: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
446
|
+
// Base
|
|
447
|
+
42161: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
448
|
+
// Arbitrum
|
|
449
|
+
9745: "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
|
|
450
|
+
// Plasma
|
|
451
|
+
146: "0x29219dd400f2bf60e5a23d13be72b486d4038894",
|
|
452
|
+
// Sonic
|
|
453
|
+
59144: "0x176211869ca2b568f2a7d4ee941e073a821ee1ff",
|
|
454
|
+
// Linea
|
|
455
|
+
1: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
456
|
+
// Ethereum
|
|
457
|
+
},
|
|
458
|
+
enabled: true
|
|
459
|
+
},
|
|
460
|
+
WETH: {
|
|
461
|
+
symbol: "WETH",
|
|
462
|
+
assetType: "eth",
|
|
463
|
+
displayName: "WETH",
|
|
464
|
+
icon: "/ai-dashboard/eth-token.png",
|
|
465
|
+
decimals: 18,
|
|
466
|
+
tokenSymbols: ["WETH", "ETH"],
|
|
467
|
+
tokenSymbolsByChainId: {
|
|
468
|
+
8453: "WETH",
|
|
469
|
+
42161: "WETH",
|
|
470
|
+
9745: "WETH",
|
|
471
|
+
146: "WETH",
|
|
472
|
+
59144: "WETH",
|
|
473
|
+
1: "WETH"
|
|
474
|
+
},
|
|
475
|
+
addresses: {
|
|
476
|
+
8453: "0x4200000000000000000000000000000000000006",
|
|
477
|
+
// Base
|
|
478
|
+
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
479
|
+
// Arbitrum
|
|
480
|
+
9745: "0x4200000000000000000000000000000000000006",
|
|
481
|
+
// Plasma
|
|
482
|
+
146: "0x039e64f90d4199560e7533692f69448878db85c7",
|
|
483
|
+
// Sonic
|
|
484
|
+
59144: "0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f",
|
|
485
|
+
// Linea
|
|
486
|
+
1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
487
|
+
// Ethereum
|
|
488
|
+
},
|
|
489
|
+
enabled: true
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
var getDefaultTokenAddress = (chainId, asset) => {
|
|
493
|
+
const address = ASSET_CONFIGS[asset || "USDC"]?.addresses[chainId];
|
|
408
494
|
if (!address || address === "0x0000000000000000000000000000000000000000") {
|
|
409
495
|
throw new Error(
|
|
410
496
|
`Default token address not configured for chain ${chainId}. Please provide tokenAddress explicitly.`
|
|
@@ -822,38 +908,39 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
822
908
|
async updateUserProfile(request) {
|
|
823
909
|
try {
|
|
824
910
|
await this.authenticateUser();
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
|
|
911
|
+
const asset = request.asset || "usdc";
|
|
912
|
+
let rebalanceStrategy;
|
|
913
|
+
if (request.strategy) {
|
|
914
|
+
if (!isValidPublicStrategy(request.strategy)) {
|
|
828
915
|
throw new Error(
|
|
829
|
-
`Invalid strategy: ${
|
|
916
|
+
`Invalid strategy: ${request.strategy}. Must be "conservative" or "aggressive".`
|
|
830
917
|
);
|
|
831
918
|
}
|
|
832
|
-
|
|
833
|
-
|
|
919
|
+
rebalanceStrategy = toInternalStrategy(
|
|
920
|
+
request.strategy
|
|
834
921
|
);
|
|
835
922
|
}
|
|
836
|
-
const
|
|
923
|
+
const assetSettings = {};
|
|
924
|
+
if (rebalanceStrategy !== void 0) assetSettings.rebalanceStrategy = rebalanceStrategy;
|
|
925
|
+
if (request.autocompounding !== void 0) assetSettings.autocompounding = request.autocompounding;
|
|
926
|
+
if (request.crosschainStrategy !== void 0) assetSettings.crosschainStrategy = request.crosschainStrategy;
|
|
927
|
+
if (request.splitting !== void 0) assetSettings.splitting = request.splitting;
|
|
928
|
+
if (request.minSplits !== void 0) assetSettings.minSplits = request.minSplits;
|
|
929
|
+
if (request.chains !== void 0) assetSettings.chains = request.chains;
|
|
930
|
+
if (request.autoSelectProtocols !== void 0) assetSettings.autoSelectProtocols = request.autoSelectProtocols;
|
|
931
|
+
if (request.protocols !== void 0) assetSettings.protocols = request.protocols;
|
|
932
|
+
const payload = {
|
|
933
|
+
assetTypeSettings: {
|
|
934
|
+
[asset]: assetSettings
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
if (request.omniAccount !== void 0) payload.omniAccount = request.omniAccount;
|
|
938
|
+
if (request.agentName !== void 0) payload.agentName = request.agentName;
|
|
939
|
+
await this.httpClient.patch(
|
|
837
940
|
ENDPOINTS.USER_ME,
|
|
838
941
|
payload
|
|
839
942
|
);
|
|
840
|
-
return
|
|
841
|
-
success: true,
|
|
842
|
-
userId: response.userId || response.id,
|
|
843
|
-
smartWallet: response.smartWallet,
|
|
844
|
-
chains: response.chains,
|
|
845
|
-
strategy: response.strategy,
|
|
846
|
-
protocols: response.protocols,
|
|
847
|
-
autoSelectProtocols: response.autoSelectProtocols,
|
|
848
|
-
omniAccount: response.omniAccount,
|
|
849
|
-
autocompounding: response.autocompounding,
|
|
850
|
-
agentName: response.agentName,
|
|
851
|
-
crosschainStrategy: response.crosschainStrategy,
|
|
852
|
-
executorProxy: response.executorProxy,
|
|
853
|
-
splitting: response.splitting,
|
|
854
|
-
minSplits: response.minSplits,
|
|
855
|
-
customization: response.customization
|
|
856
|
-
};
|
|
943
|
+
return await this.getUserDetails(asset);
|
|
857
944
|
} catch (error) {
|
|
858
945
|
throw new Error(
|
|
859
946
|
`Failed to update user profile: ${error.message}`
|
|
@@ -880,7 +967,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
880
967
|
*/
|
|
881
968
|
async pauseAgent() {
|
|
882
969
|
try {
|
|
970
|
+
await this.updateUserProfile({
|
|
971
|
+
asset: "usdc",
|
|
972
|
+
protocols: []
|
|
973
|
+
});
|
|
883
974
|
const response = await this.updateUserProfile({
|
|
975
|
+
asset: "eth",
|
|
884
976
|
protocols: []
|
|
885
977
|
});
|
|
886
978
|
return response;
|
|
@@ -889,49 +981,58 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
889
981
|
}
|
|
890
982
|
}
|
|
891
983
|
/**
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
984
|
+
* Resume the agent by restoring protocols based on user's strategy for each asset
|
|
985
|
+
* Fetches available protocols and assigns them based on each asset's strategy
|
|
986
|
+
*
|
|
987
|
+
* @returns Response indicating success and updated user details
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* ```typescript
|
|
991
|
+
* const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
|
|
992
|
+
*
|
|
993
|
+
* // Connect account first
|
|
994
|
+
* await sdk.connectAccount();
|
|
995
|
+
*
|
|
996
|
+
* // Resume the agent
|
|
997
|
+
* const result = await sdk.resumeAgent();
|
|
998
|
+
* console.log('Agent resumed:', result.success);
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
909
1001
|
async resumeAgent() {
|
|
910
1002
|
try {
|
|
911
|
-
const
|
|
912
|
-
const
|
|
913
|
-
const
|
|
914
|
-
const convertedStrategy = toInternalStrategy(strategy);
|
|
915
|
-
const chains = userChains && userChains.length > 0 ? userChains : [8453, 42161];
|
|
1003
|
+
const userDetailsUSDC = await this.getUserDetails("usdc");
|
|
1004
|
+
const userDetailsETH = await this.getUserDetails("eth");
|
|
1005
|
+
const chains = userDetailsUSDC.chains && userDetailsUSDC.chains.length > 0 ? userDetailsUSDC.chains : [8453, 42161];
|
|
916
1006
|
const allProtocols = await this.httpClient.get(
|
|
917
1007
|
ENDPOINTS.PROTOCOLS()
|
|
918
1008
|
);
|
|
919
|
-
const
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
)
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
1009
|
+
const usdcStrategy = userDetailsUSDC.strategy || "safe_strategy";
|
|
1010
|
+
const ethStrategy = userDetailsETH.strategy || "safe_strategy";
|
|
1011
|
+
const filterProtocolsByStrategy = (strategy) => {
|
|
1012
|
+
return allProtocols.filter((protocol) => {
|
|
1013
|
+
const hasMatchingChain = protocol.chains.some(
|
|
1014
|
+
(chain) => chains.includes(chain)
|
|
1015
|
+
);
|
|
1016
|
+
if (!hasMatchingChain) {
|
|
1017
|
+
return false;
|
|
1018
|
+
}
|
|
1019
|
+
if (strategy === "degen_strategy") {
|
|
1020
|
+
return protocol.strategies?.includes("safe_strategy") || protocol.strategies?.includes("degen_strategy");
|
|
1021
|
+
}
|
|
1022
|
+
return protocol.strategies?.includes("safe_strategy");
|
|
1023
|
+
}).map((protocol) => protocol.id);
|
|
1024
|
+
};
|
|
1025
|
+
const usdcProtocols = filterProtocolsByStrategy(usdcStrategy);
|
|
1026
|
+
const ethProtocols = filterProtocolsByStrategy(ethStrategy);
|
|
1027
|
+
await this.updateUserProfile({
|
|
1028
|
+
asset: "usdc",
|
|
1029
|
+
protocols: usdcProtocols
|
|
933
1030
|
});
|
|
934
|
-
|
|
1031
|
+
const updatedUserDetailsETH = await this.updateUserProfile({
|
|
1032
|
+
asset: "eth",
|
|
1033
|
+
protocols: ethProtocols
|
|
1034
|
+
});
|
|
1035
|
+
return updatedUserDetailsETH;
|
|
935
1036
|
} catch (error) {
|
|
936
1037
|
throw new Error(`Failed to resume agent: ${error.message}`);
|
|
937
1038
|
}
|
|
@@ -1518,14 +1619,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1518
1619
|
async updateUserProtocols(chainId) {
|
|
1519
1620
|
try {
|
|
1520
1621
|
const protocolsResponse = await this.getAvailableProtocols(chainId);
|
|
1521
|
-
|
|
1622
|
+
const userDetails = await this.getUserDetails();
|
|
1623
|
+
const filteredProtocols = userDetails.strategy ? protocolsResponse.protocols.filter((p) => p.strategies?.includes(userDetails.strategy)) : protocolsResponse.protocols;
|
|
1624
|
+
if (!filteredProtocols || filteredProtocols.length === 0) {
|
|
1522
1625
|
console.warn(`No protocols available for chain ${chainId}`);
|
|
1523
1626
|
return;
|
|
1524
1627
|
}
|
|
1525
|
-
const protocolIds =
|
|
1628
|
+
const protocolIds = filteredProtocols.map((p) => p.id);
|
|
1526
1629
|
await this.updateUserProfile({
|
|
1527
1630
|
protocols: protocolIds
|
|
1528
1631
|
});
|
|
1632
|
+
await this.updateUserProfile({
|
|
1633
|
+
protocols: protocolIds,
|
|
1634
|
+
asset: "eth"
|
|
1635
|
+
});
|
|
1529
1636
|
} catch (error) {
|
|
1530
1637
|
console.warn(
|
|
1531
1638
|
`Failed to update user protocols: ${error.message}`
|
|
@@ -1587,7 +1694,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1587
1694
|
* );
|
|
1588
1695
|
* ```
|
|
1589
1696
|
*/
|
|
1590
|
-
async depositFunds(userAddress, chainId, amount) {
|
|
1697
|
+
async depositFunds(userAddress, chainId, amount, asset) {
|
|
1591
1698
|
try {
|
|
1592
1699
|
if (!userAddress) {
|
|
1593
1700
|
throw new Error("User address is required");
|
|
@@ -1598,7 +1705,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1598
1705
|
if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
|
|
1599
1706
|
throw new Error("Valid amount is required");
|
|
1600
1707
|
}
|
|
1601
|
-
const token = getDefaultTokenAddress(chainId);
|
|
1708
|
+
const token = getDefaultTokenAddress(chainId, asset);
|
|
1602
1709
|
const walletClient = this.getWalletClient();
|
|
1603
1710
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1604
1711
|
const safeAddress = await getDeterministicSafeAddress({
|
|
@@ -1650,6 +1757,71 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1650
1757
|
throw new Error(`Deposit failed: ${error.message}`);
|
|
1651
1758
|
}
|
|
1652
1759
|
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Log a deposit that was executed client-side
|
|
1762
|
+
*
|
|
1763
|
+
* Use this method when you execute the deposit transaction yourself (e.g., with Privy,
|
|
1764
|
+
* sponsored transactions, or any custom wallet implementation) and need to register
|
|
1765
|
+
* the deposit with the Zyfai backend for tracking and yield optimization.
|
|
1766
|
+
*
|
|
1767
|
+
* This is useful for partners who:
|
|
1768
|
+
* - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
|
|
1769
|
+
* - Have custom wallet implementations
|
|
1770
|
+
* - Need more control over transaction execution
|
|
1771
|
+
*
|
|
1772
|
+
* Token is automatically selected based on chain if not provided:
|
|
1773
|
+
* - Base (8453) and Arbitrum (42161): USDC
|
|
1774
|
+
* - Plasma (9745): USDT
|
|
1775
|
+
*
|
|
1776
|
+
* @param chainId - Chain ID where the deposit was made
|
|
1777
|
+
* @param txHash - Transaction hash of the deposit
|
|
1778
|
+
* @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
|
|
1779
|
+
* @param tokenAddress - Optional: Token address (auto-selected based on chain if not provided)
|
|
1780
|
+
* @returns Log deposit response with success status
|
|
1781
|
+
*
|
|
1782
|
+
* @example
|
|
1783
|
+
* ```typescript
|
|
1784
|
+
* // Execute deposit with Privy (sponsored transaction)
|
|
1785
|
+
* const txHash = await privyWallet.sendTransaction({
|
|
1786
|
+
* to: safeAddress,
|
|
1787
|
+
* data: transferData,
|
|
1788
|
+
* });
|
|
1789
|
+
*
|
|
1790
|
+
* // Log the deposit to Zyfai backend
|
|
1791
|
+
* const result = await sdk.logDeposit(
|
|
1792
|
+
* 8453, // chainId
|
|
1793
|
+
* txHash, // transaction hash from Privy
|
|
1794
|
+
* "100000000" // 100 USDC
|
|
1795
|
+
* );
|
|
1796
|
+
* console.log(result.success); // true
|
|
1797
|
+
* ```
|
|
1798
|
+
*/
|
|
1799
|
+
async logDeposit(chainId, txHash, amount, tokenAddress) {
|
|
1800
|
+
try {
|
|
1801
|
+
if (!isSupportedChain(chainId)) {
|
|
1802
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
1803
|
+
}
|
|
1804
|
+
if (!txHash || !txHash.startsWith("0x")) {
|
|
1805
|
+
throw new Error("Valid transaction hash is required");
|
|
1806
|
+
}
|
|
1807
|
+
if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
|
|
1808
|
+
throw new Error("Valid amount is required");
|
|
1809
|
+
}
|
|
1810
|
+
const token = tokenAddress || getDefaultTokenAddress(chainId);
|
|
1811
|
+
await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
|
|
1812
|
+
chainId,
|
|
1813
|
+
transaction: txHash,
|
|
1814
|
+
token,
|
|
1815
|
+
amount
|
|
1816
|
+
});
|
|
1817
|
+
return {
|
|
1818
|
+
success: true,
|
|
1819
|
+
message: "Deposit logged successfully"
|
|
1820
|
+
};
|
|
1821
|
+
} catch (error) {
|
|
1822
|
+
throw new Error(`Log deposit failed: ${error.message}`);
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1653
1825
|
/**
|
|
1654
1826
|
* Withdraw funds from Safe smart wallet
|
|
1655
1827
|
* Initiates a withdrawal request to the Zyfai API
|
|
@@ -1675,7 +1847,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1675
1847
|
* );
|
|
1676
1848
|
* ```
|
|
1677
1849
|
*/
|
|
1678
|
-
async withdrawFunds(userAddress, chainId, amount) {
|
|
1850
|
+
async withdrawFunds(userAddress, chainId, amount, tokenSymbol) {
|
|
1679
1851
|
try {
|
|
1680
1852
|
if (!userAddress) {
|
|
1681
1853
|
throw new Error("User address is required");
|
|
@@ -1717,12 +1889,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1717
1889
|
if (amount) {
|
|
1718
1890
|
response = await this.httpClient.post(ENDPOINTS.PARTIAL_WITHDRAW, {
|
|
1719
1891
|
chainId,
|
|
1720
|
-
amount
|
|
1892
|
+
amount,
|
|
1893
|
+
tokenSymbol
|
|
1721
1894
|
});
|
|
1722
1895
|
} else {
|
|
1896
|
+
console.log("Full withdrawal", tokenSymbol);
|
|
1723
1897
|
response = await this.httpClient.get(ENDPOINTS.USER_WITHDRAW, {
|
|
1724
|
-
params: { chainId }
|
|
1898
|
+
params: { chainId, tokenSymbol }
|
|
1725
1899
|
});
|
|
1900
|
+
console.log(JSON.stringify(response, null, 2));
|
|
1726
1901
|
}
|
|
1727
1902
|
const success = response?.success ?? true;
|
|
1728
1903
|
const message = response?.message || "Withdrawal request sent";
|
|
@@ -1833,35 +2008,27 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1833
2008
|
* console.log("Chains:", user.user.chains);
|
|
1834
2009
|
* ```
|
|
1835
2010
|
*/
|
|
1836
|
-
async getUserDetails() {
|
|
2011
|
+
async getUserDetails(asset = "usdc") {
|
|
1837
2012
|
try {
|
|
1838
2013
|
await this.authenticateUser();
|
|
1839
2014
|
const response = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
1840
2015
|
const convertedResponse = convertStrategyToPublic(response);
|
|
1841
2016
|
return {
|
|
1842
2017
|
success: true,
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
crosschainStrategy: convertedResponse.crosschainStrategy,
|
|
1858
|
-
agentName: convertedResponse.agentName,
|
|
1859
|
-
customization: convertedResponse.customization,
|
|
1860
|
-
executorProxy: convertedResponse.executorProxy,
|
|
1861
|
-
splitting: convertedResponse.splitting,
|
|
1862
|
-
minSplits: convertedResponse.minSplits,
|
|
1863
|
-
registered: convertedResponse.registered
|
|
1864
|
-
}
|
|
2018
|
+
agentName: convertedResponse.agentName,
|
|
2019
|
+
smartWallet: convertedResponse.smartWallet,
|
|
2020
|
+
chains: convertedResponse.assetTypeSettings?.[asset]?.chains || [],
|
|
2021
|
+
hasActiveSessionKey: convertedResponse.hasActiveSessionKey || false,
|
|
2022
|
+
omniAccount: convertedResponse.omniAccount,
|
|
2023
|
+
asset,
|
|
2024
|
+
autoSelectProtocols: convertedResponse.assetTypeSettings?.[asset]?.autoSelectProtocols,
|
|
2025
|
+
strategy: convertedResponse.assetTypeSettings?.[asset]?.rebalanceStrategy,
|
|
2026
|
+
autocompounding: convertedResponse.assetTypeSettings?.[asset]?.autocompounding,
|
|
2027
|
+
crosschainStrategy: convertedResponse.assetTypeSettings?.[asset]?.crosschainStrategy,
|
|
2028
|
+
splitting: convertedResponse.assetTypeSettings?.[asset]?.splitting,
|
|
2029
|
+
minSplits: convertedResponse.assetTypeSettings?.[asset]?.minSplits || 0,
|
|
2030
|
+
protocols: convertedResponse.assetTypeSettings?.[asset]?.protocols || [],
|
|
2031
|
+
customization: convertedResponse.customization
|
|
1865
2032
|
};
|
|
1866
2033
|
} catch (error) {
|
|
1867
2034
|
throw new Error(
|
|
@@ -1886,18 +2053,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1886
2053
|
async getTVL() {
|
|
1887
2054
|
try {
|
|
1888
2055
|
const response = await this.httpClient.get(ENDPOINTS.DATA_TVL);
|
|
1889
|
-
const byChain = {};
|
|
1890
|
-
for (const key of Object.keys(response)) {
|
|
1891
|
-
const numKey = parseInt(key, 10);
|
|
1892
|
-
if (!isNaN(numKey) && typeof response[key] === "number") {
|
|
1893
|
-
byChain[numKey] = response[key];
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
2056
|
return {
|
|
1897
2057
|
success: true,
|
|
1898
|
-
totalTvl: response.total ||
|
|
1899
|
-
byChain,
|
|
1900
|
-
breakdown: response.breakdown
|
|
2058
|
+
totalTvl: response.total || 0
|
|
1901
2059
|
};
|
|
1902
2060
|
} catch (error) {
|
|
1903
2061
|
throw new Error(`Failed to get TVL: ${error.message}`);
|
|
@@ -1912,20 +2070,28 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1912
2070
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
1913
2071
|
* @param days - Time period: 7, 14, or 30
|
|
1914
2072
|
* @param strategy - Strategy type: "conservative" (default) or "aggressive"
|
|
2073
|
+
* @param chainId - Optional chain ID filter
|
|
2074
|
+
* @param tokenSymbol - Optional token symbol filter (e.g. "USDC", "WETH", "WBTC")
|
|
1915
2075
|
* @returns APY per strategy for a specific chain
|
|
1916
2076
|
*
|
|
1917
2077
|
* @example
|
|
1918
2078
|
* ```typescript
|
|
1919
|
-
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
2079
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative", 8453, "USDC");
|
|
1920
2080
|
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
1921
2081
|
* ```
|
|
1922
2082
|
*/
|
|
1923
|
-
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative") {
|
|
2083
|
+
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative", chainId, tokenSymbol) {
|
|
1924
2084
|
try {
|
|
1925
2085
|
const internalStrategy = toInternalStrategy(strategy);
|
|
1926
2086
|
const internalStrategyShort = internalStrategy === "safe_strategy" ? "safe" : "degen";
|
|
1927
2087
|
const response = await this.httpClient.dataGet(
|
|
1928
|
-
DATA_ENDPOINTS.APY_PER_STRATEGY(
|
|
2088
|
+
DATA_ENDPOINTS.APY_PER_STRATEGY({
|
|
2089
|
+
isCrossChain: crossChain,
|
|
2090
|
+
days,
|
|
2091
|
+
strategy: internalStrategyShort,
|
|
2092
|
+
chainId,
|
|
2093
|
+
tokenSymbol
|
|
2094
|
+
})
|
|
1929
2095
|
);
|
|
1930
2096
|
const convertedData = convertStrategiesToPublicAndNaming(
|
|
1931
2097
|
response.data || []
|
|
@@ -1952,9 +2118,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1952
2118
|
* console.log("Total Volume:", volume.volumeInUSD);
|
|
1953
2119
|
* ```
|
|
1954
2120
|
*/
|
|
1955
|
-
async getVolume() {
|
|
2121
|
+
async getVolume(assetType = "usdc") {
|
|
1956
2122
|
try {
|
|
1957
|
-
const response = await this.httpClient.get(ENDPOINTS.DATA_VOLUME);
|
|
2123
|
+
const response = await this.httpClient.get(ENDPOINTS.DATA_VOLUME(assetType));
|
|
1958
2124
|
return {
|
|
1959
2125
|
success: true,
|
|
1960
2126
|
volumeInUSD: response.volumeInUSD || "0"
|
|
@@ -2121,12 +2287,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2121
2287
|
* Get onchain earnings for a wallet
|
|
2122
2288
|
*
|
|
2123
2289
|
* @param walletAddress - Smart wallet address
|
|
2124
|
-
* @returns Onchain earnings data
|
|
2290
|
+
* @returns Onchain earnings data with per-token breakdowns
|
|
2125
2291
|
*
|
|
2126
2292
|
* @example
|
|
2127
2293
|
* ```typescript
|
|
2128
2294
|
* const earnings = await sdk.getOnchainEarnings("0x...");
|
|
2129
|
-
* console.log("Total
|
|
2295
|
+
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
2130
2296
|
* ```
|
|
2131
2297
|
*/
|
|
2132
2298
|
async getOnchainEarnings(walletAddress) {
|
|
@@ -2141,13 +2307,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2141
2307
|
success: true,
|
|
2142
2308
|
data: {
|
|
2143
2309
|
walletAddress,
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
unrealizedEarnings: response.unrealized_earnings,
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
lastCheckTimestamp: response.last_check_timestamp
|
|
2310
|
+
totalEarningsByToken: response.total_earnings_by_token || {},
|
|
2311
|
+
lifetimeEarningsByToken: response.lifetime_earnings_by_token || {},
|
|
2312
|
+
currentEarningsByChain: response.current_earnings_by_chain || {},
|
|
2313
|
+
unrealizedEarnings: response.unrealized_earnings || {},
|
|
2314
|
+
lastCheckTimestamp: response.last_check_timestamp,
|
|
2315
|
+
lastLogDate: response.last_log_date
|
|
2151
2316
|
}
|
|
2152
2317
|
};
|
|
2153
2318
|
} catch (error) {
|
|
@@ -2161,12 +2326,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2161
2326
|
* This triggers a recalculation of earnings on the backend
|
|
2162
2327
|
*
|
|
2163
2328
|
* @param walletAddress - Smart wallet address
|
|
2164
|
-
* @returns Updated onchain earnings data
|
|
2329
|
+
* @returns Updated onchain earnings data with per-token breakdowns
|
|
2165
2330
|
*
|
|
2166
2331
|
* @example
|
|
2167
2332
|
* ```typescript
|
|
2168
2333
|
* const earnings = await sdk.calculateOnchainEarnings("0x...");
|
|
2169
|
-
* console.log("
|
|
2334
|
+
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
2170
2335
|
* ```
|
|
2171
2336
|
*/
|
|
2172
2337
|
async calculateOnchainEarnings(walletAddress) {
|
|
@@ -2183,11 +2348,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2183
2348
|
success: true,
|
|
2184
2349
|
data: {
|
|
2185
2350
|
walletAddress,
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
unrealizedEarnings: data.unrealized_earnings,
|
|
2190
|
-
lastCheckTimestamp: data.last_check_timestamp
|
|
2351
|
+
totalEarningsByToken: data.total_earnings_by_token || {},
|
|
2352
|
+
lifetimeEarningsByToken: data.lifetime_earnings_by_token || {},
|
|
2353
|
+
currentEarningsByChain: data.current_earnings_by_chain || {},
|
|
2354
|
+
unrealizedEarnings: data.unrealized_earnings || {},
|
|
2355
|
+
lastCheckTimestamp: data.last_check_timestamp,
|
|
2356
|
+
lastLogDate: data.last_log_date
|
|
2191
2357
|
}
|
|
2192
2358
|
};
|
|
2193
2359
|
} catch (error) {
|
|
@@ -2207,7 +2373,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2207
2373
|
* @example
|
|
2208
2374
|
* ```typescript
|
|
2209
2375
|
* const daily = await sdk.getDailyEarnings("0x...", "2024-01-01", "2024-01-31");
|
|
2210
|
-
* daily.data.forEach(d => console.log(d.
|
|
2376
|
+
* daily.data.forEach(d => console.log(d.snapshot_date, d.total_earnings_by_token));
|
|
2211
2377
|
* ```
|
|
2212
2378
|
*/
|
|
2213
2379
|
async getDailyEarnings(walletAddress, startDate, endDate) {
|
|
@@ -2235,61 +2401,25 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2235
2401
|
}
|
|
2236
2402
|
}
|
|
2237
2403
|
// ============================================================================
|
|
2238
|
-
// Portfolio Methods (Data API v2)
|
|
2239
|
-
// ============================================================================
|
|
2240
|
-
/**
|
|
2241
|
-
* Get Debank portfolio for a wallet across multiple chains
|
|
2242
|
-
* Note: This is a paid endpoint and may require authorization
|
|
2243
|
-
*
|
|
2244
|
-
* @param walletAddress - Smart wallet address
|
|
2245
|
-
* @returns Multi-chain portfolio data
|
|
2246
|
-
*
|
|
2247
|
-
* @example
|
|
2248
|
-
* ```typescript
|
|
2249
|
-
* const portfolio = await sdk.getDebankPortfolio("0x...");
|
|
2250
|
-
* console.log("Total value:", portfolio.totalValueUsd);
|
|
2251
|
-
* ```
|
|
2252
|
-
*/
|
|
2253
|
-
async getDebankPortfolio(walletAddress) {
|
|
2254
|
-
try {
|
|
2255
|
-
if (!walletAddress) {
|
|
2256
|
-
throw new Error("Wallet address is required");
|
|
2257
|
-
}
|
|
2258
|
-
const response = await this.httpClient.dataGet(
|
|
2259
|
-
DATA_ENDPOINTS.DEBANK_PORTFOLIO_MULTICHAIN(walletAddress)
|
|
2260
|
-
);
|
|
2261
|
-
const data = response.data || response;
|
|
2262
|
-
return {
|
|
2263
|
-
success: true,
|
|
2264
|
-
walletAddress,
|
|
2265
|
-
totalValueUsd: data.totalValueUsd || 0,
|
|
2266
|
-
chains: data.chains || data
|
|
2267
|
-
};
|
|
2268
|
-
} catch (error) {
|
|
2269
|
-
throw new Error(
|
|
2270
|
-
`Failed to get Debank portfolio: ${error.message}`
|
|
2271
|
-
);
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
// ============================================================================
|
|
2275
2404
|
// Opportunities Methods (Data API v2)
|
|
2276
2405
|
// ============================================================================
|
|
2277
2406
|
/**
|
|
2278
2407
|
* Get conservative (low-risk) yield opportunities
|
|
2279
2408
|
*
|
|
2280
2409
|
* @param chainId - Optional chain ID filter
|
|
2410
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2281
2411
|
* @returns List of conservative yield opportunities
|
|
2282
2412
|
*
|
|
2283
2413
|
* @example
|
|
2284
2414
|
* ```typescript
|
|
2285
|
-
* const opportunities = await sdk.getConservativeOpportunities(8453);
|
|
2415
|
+
* const opportunities = await sdk.getConservativeOpportunities(8453, "USDC");
|
|
2286
2416
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2287
2417
|
* ```
|
|
2288
2418
|
*/
|
|
2289
|
-
async getConservativeOpportunities(chainId) {
|
|
2419
|
+
async getConservativeOpportunities(chainId, asset, status) {
|
|
2290
2420
|
try {
|
|
2291
2421
|
const response = await this.httpClient.dataGet(
|
|
2292
|
-
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
2422
|
+
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId, asset, status)
|
|
2293
2423
|
);
|
|
2294
2424
|
const data = response.data || response || [];
|
|
2295
2425
|
return {
|
|
@@ -2302,7 +2432,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2302
2432
|
protocolName: o.protocol_name || o.protocolName,
|
|
2303
2433
|
poolName: o.pool_name || o.poolName,
|
|
2304
2434
|
chainId: o.chain_id || o.chainId,
|
|
2305
|
-
apy: o.
|
|
2435
|
+
apy: o.combined_apy || 0,
|
|
2306
2436
|
tvl: o.tvl || o.zyfiTvl,
|
|
2307
2437
|
asset: o.asset || o.underlying_token,
|
|
2308
2438
|
risk: o.risk,
|
|
@@ -2320,18 +2450,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2320
2450
|
* Get aggressive (high-risk, high-reward) yield opportunities
|
|
2321
2451
|
*
|
|
2322
2452
|
* @param chainId - Optional chain ID filter
|
|
2453
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2323
2454
|
* @returns List of aggressive opportunities
|
|
2324
2455
|
*
|
|
2325
2456
|
* @example
|
|
2326
2457
|
* ```typescript
|
|
2327
|
-
* const opportunities = await sdk.getAggressiveOpportunities(8453);
|
|
2458
|
+
* const opportunities = await sdk.getAggressiveOpportunities(8453, "WETH");
|
|
2328
2459
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2329
2460
|
* ```
|
|
2330
2461
|
*/
|
|
2331
|
-
async getAggressiveOpportunities(chainId) {
|
|
2462
|
+
async getAggressiveOpportunities(chainId, asset, status) {
|
|
2332
2463
|
try {
|
|
2333
2464
|
const response = await this.httpClient.dataGet(
|
|
2334
|
-
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
|
2465
|
+
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset, status)
|
|
2335
2466
|
);
|
|
2336
2467
|
const data = response.data || response || [];
|
|
2337
2468
|
return {
|
|
@@ -2344,7 +2475,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2344
2475
|
protocolName: o.protocol_name || o.protocolName,
|
|
2345
2476
|
poolName: o.pool_name || o.poolName,
|
|
2346
2477
|
chainId: o.chain_id || o.chainId,
|
|
2347
|
-
apy: o.
|
|
2478
|
+
apy: o.combined_apy || 0,
|
|
2348
2479
|
tvl: o.tvl || o.zyfiTvl,
|
|
2349
2480
|
asset: o.asset || o.underlying_token,
|
|
2350
2481
|
risk: o.risk,
|
|
@@ -2363,6 +2494,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2363
2494
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
2364
2495
|
*
|
|
2365
2496
|
* @param chainId - Optional chain ID filter
|
|
2497
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2366
2498
|
* @returns Active conservative opportunities with risk data
|
|
2367
2499
|
*
|
|
2368
2500
|
* @example
|
|
@@ -2371,10 +2503,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2371
2503
|
* console.log(JSON.stringify(opps, null, 2));
|
|
2372
2504
|
* ```
|
|
2373
2505
|
*/
|
|
2374
|
-
async getActiveConservativeOppsRisk(chainId) {
|
|
2506
|
+
async getActiveConservativeOppsRisk(chainId, asset) {
|
|
2375
2507
|
try {
|
|
2376
2508
|
const response = await this.httpClient.dataGet(
|
|
2377
|
-
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
2509
|
+
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId, asset)
|
|
2378
2510
|
);
|
|
2379
2511
|
const data = response.data || response || [];
|
|
2380
2512
|
const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
|
|
@@ -2408,6 +2540,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2408
2540
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
2409
2541
|
*
|
|
2410
2542
|
* @param chainId - Optional chain ID filter
|
|
2543
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2411
2544
|
* @returns Active aggressive opportunities with risk data
|
|
2412
2545
|
*
|
|
2413
2546
|
* @example
|
|
@@ -2416,10 +2549,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2416
2549
|
* console.log(JSON.stringify(opps, null, 2));
|
|
2417
2550
|
* ```
|
|
2418
2551
|
*/
|
|
2419
|
-
async getActiveAggressiveOppsRisk(chainId) {
|
|
2552
|
+
async getActiveAggressiveOppsRisk(chainId, asset) {
|
|
2420
2553
|
try {
|
|
2421
2554
|
const response = await this.httpClient.dataGet(
|
|
2422
|
-
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
|
2555
|
+
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset)
|
|
2423
2556
|
);
|
|
2424
2557
|
const data = response.data || response || [];
|
|
2425
2558
|
const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
|
|
@@ -2453,10 +2586,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2453
2586
|
* Builds on getActiveConservativeOppsRisk and computes higher-level status indicators
|
|
2454
2587
|
*
|
|
2455
2588
|
* @param chainId - Optional chain ID filter
|
|
2589
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2456
2590
|
* @returns Conservative pools with status data
|
|
2457
2591
|
*/
|
|
2458
|
-
async getConservativePoolStatus(chainId) {
|
|
2459
|
-
const pools = await this.getActiveConservativeOppsRisk(chainId);
|
|
2592
|
+
async getConservativePoolStatus(chainId, asset) {
|
|
2593
|
+
const pools = await this.getActiveConservativeOppsRisk(chainId, asset);
|
|
2460
2594
|
return pools.map((p) => this.derivePoolStatus(p));
|
|
2461
2595
|
}
|
|
2462
2596
|
/**
|
|
@@ -2464,10 +2598,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2464
2598
|
* Builds on getActiveAggressiveOppsRisk and computes higher-level status indicators
|
|
2465
2599
|
*
|
|
2466
2600
|
* @param chainId - Optional chain ID filter
|
|
2601
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2467
2602
|
* @returns Aggressive pools with status data
|
|
2468
2603
|
*/
|
|
2469
|
-
async getAggressivePoolStatus(chainId) {
|
|
2470
|
-
const pools = await this.getActiveAggressiveOppsRisk(chainId);
|
|
2604
|
+
async getAggressivePoolStatus(chainId, asset) {
|
|
2605
|
+
const pools = await this.getActiveAggressiveOppsRisk(chainId, asset);
|
|
2471
2606
|
return pools.map((p) => this.derivePoolStatus(p));
|
|
2472
2607
|
}
|
|
2473
2608
|
derivePoolStatus(p) {
|
|
@@ -2516,12 +2651,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2516
2651
|
*
|
|
2517
2652
|
* @param walletAddress - Smart wallet address
|
|
2518
2653
|
* @param days - Period: "7D", "14D", or "30D" (default: "7D")
|
|
2519
|
-
* @returns Daily APY history with weighted averages
|
|
2654
|
+
* @returns Daily APY history with per-position breakdowns and weighted averages
|
|
2520
2655
|
*
|
|
2521
2656
|
* @example
|
|
2522
2657
|
* ```typescript
|
|
2523
2658
|
* const apyHistory = await sdk.getDailyApyHistory("0x...", "30D");
|
|
2524
|
-
* console.log("
|
|
2659
|
+
* console.log("Weighted APY after fee:", apyHistory.weightedApyAfterFee); // { "USDC": 4.64, "WETH": 1.94 }
|
|
2525
2660
|
* ```
|
|
2526
2661
|
*/
|
|
2527
2662
|
async getDailyApyHistory(walletAddress, days = "7D") {
|