@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.mjs
CHANGED
|
@@ -25,8 +25,8 @@ var ENDPOINTS = {
|
|
|
25
25
|
// Data (v1)
|
|
26
26
|
DATA_POSITION: (walletAddress) => `/data/position?walletAddress=${walletAddress}`,
|
|
27
27
|
DATA_HISTORY: (walletAddress, chainId) => `/data/history?walletAddress=${walletAddress}&chainId=${chainId}`,
|
|
28
|
-
DATA_TVL: "/data/tvl",
|
|
29
|
-
DATA_VOLUME:
|
|
28
|
+
DATA_TVL: "/data/usd-tvl",
|
|
29
|
+
DATA_VOLUME: (assetType) => `/data/volume?assetType=${assetType}`,
|
|
30
30
|
DATA_FIRST_TOPUP: (walletAddress, chainId) => `/data/first-topup?walletAddress=${walletAddress}&chainId=${chainId}`,
|
|
31
31
|
DATA_ACTIVE_WALLETS: (chainId) => `/data/active-wallets?chainId=${chainId}`,
|
|
32
32
|
DATA_BY_EOA: (address) => `/data/by-eoa?address=${address}`,
|
|
@@ -45,25 +45,48 @@ var DATA_ENDPOINTS = {
|
|
|
45
45
|
// User Initialization
|
|
46
46
|
USER_INITIALIZE: "/api/earnings/initialize",
|
|
47
47
|
// Earnings
|
|
48
|
-
ONCHAIN_EARNINGS: (walletAddress) => `/
|
|
49
|
-
CALCULATE_ONCHAIN_EARNINGS: "/
|
|
48
|
+
ONCHAIN_EARNINGS: (walletAddress) => `/onchain-earnings/onchain-earnings?walletAddress=${walletAddress}`,
|
|
49
|
+
CALCULATE_ONCHAIN_EARNINGS: "/onchain-earnings/calculate-onchain-earnings",
|
|
50
50
|
DAILY_EARNINGS: (walletAddress, startDate, endDate) => {
|
|
51
|
-
let url = `/
|
|
51
|
+
let url = `/onchain-earnings/daily-earnings?walletAddress=${walletAddress}`;
|
|
52
52
|
if (startDate) url += `&startDate=${startDate}`;
|
|
53
53
|
if (endDate) url += `&endDate=${endDate}`;
|
|
54
54
|
return url;
|
|
55
55
|
},
|
|
56
|
-
// Portfolio
|
|
57
|
-
DEBANK_PORTFOLIO_MULTICHAIN: (address) => `/debank/portfolio/multichain/${address}`,
|
|
58
56
|
// Opportunities
|
|
59
|
-
OPPORTUNITIES_SAFE: (chainId) =>
|
|
60
|
-
|
|
57
|
+
OPPORTUNITIES_SAFE: (chainId, asset, status) => {
|
|
58
|
+
const params = [];
|
|
59
|
+
if (chainId !== void 0) params.push(`chainId=${chainId}`);
|
|
60
|
+
if (asset) params.push(`asset=${asset}`);
|
|
61
|
+
if (status) params.push(`status=${status}`);
|
|
62
|
+
return params.length > 0 ? `/opportunities/safe?${params.join("&")}` : "/opportunities/safe";
|
|
63
|
+
},
|
|
64
|
+
OPPORTUNITIES_DEGEN: (chainId, asset, status) => {
|
|
65
|
+
const params = [];
|
|
66
|
+
if (chainId !== void 0) params.push(`chainId=${chainId}`);
|
|
67
|
+
if (asset) params.push(`asset=${asset}`);
|
|
68
|
+
if (status) params.push(`status=${status}`);
|
|
69
|
+
return params.length > 0 ? `/opportunities/degen-strategies?${params.join("&")}` : "/opportunities/degen-strategies";
|
|
70
|
+
},
|
|
61
71
|
// APY History
|
|
62
|
-
DAILY_APY_HISTORY_WEIGHTED: (walletAddress, days) => `/daily-apy-history/weighted/${walletAddress}${days ? `?days=${days}` : ""}`,
|
|
72
|
+
DAILY_APY_HISTORY_WEIGHTED: (walletAddress, days) => `/daily-apy-history/weighted-multi-asset/${walletAddress}${days ? `?days=${days}` : ""}`,
|
|
63
73
|
// Rebalance
|
|
64
|
-
REBALANCE_INFO: (
|
|
74
|
+
REBALANCE_INFO: (options) => {
|
|
75
|
+
const params = [];
|
|
76
|
+
if (options?.isCrossChain !== void 0) params.push(`isCrossChain=${options.isCrossChain}`);
|
|
77
|
+
if (options?.tokenSymbol) params.push(`tokenSymbol=${options.tokenSymbol}`);
|
|
78
|
+
return params.length > 0 ? `/rebalance/rebalance-info?${params.join("&")}` : "/rebalance/rebalance-info";
|
|
79
|
+
},
|
|
65
80
|
// APY Per Strategy
|
|
66
|
-
APY_PER_STRATEGY: (
|
|
81
|
+
APY_PER_STRATEGY: (options = {}) => {
|
|
82
|
+
const params = [];
|
|
83
|
+
if (options.isCrossChain !== void 0) params.push(`isCrossChain=${options.isCrossChain}`);
|
|
84
|
+
if (options.days !== void 0) params.push(`days=${options.days}`);
|
|
85
|
+
if (options.strategy) params.push(`strategy=${options.strategy}`);
|
|
86
|
+
if (options.chainId !== void 0) params.push(`chainId=${options.chainId}`);
|
|
87
|
+
if (options.tokenSymbol) params.push(`tokenSymbol=${options.tokenSymbol}`);
|
|
88
|
+
return params.length > 0 ? `/rebalance/rebalance-info?${params.join("&")}` : "/rebalance/rebalance-info";
|
|
89
|
+
}
|
|
67
90
|
};
|
|
68
91
|
|
|
69
92
|
// src/utils/http-client.ts
|
|
@@ -368,8 +391,71 @@ var DEFAULT_TOKEN_ADDRESSES = {
|
|
|
368
391
|
9745: "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb"
|
|
369
392
|
// USDT on Plasma
|
|
370
393
|
};
|
|
371
|
-
var
|
|
372
|
-
|
|
394
|
+
var ASSET_CONFIGS = {
|
|
395
|
+
USDC: {
|
|
396
|
+
symbol: "USDC",
|
|
397
|
+
assetType: "usdc",
|
|
398
|
+
displayName: "USDC",
|
|
399
|
+
icon: "/ai-dashboard/usdc-token.png",
|
|
400
|
+
decimals: 6,
|
|
401
|
+
tokenSymbols: ["USDC", "USDC.e", "USDT", "USDT0"],
|
|
402
|
+
tokenSymbolsByChainId: {
|
|
403
|
+
8453: "USDC",
|
|
404
|
+
42161: "USDC",
|
|
405
|
+
9745: "USDT0",
|
|
406
|
+
146: "USDC.e",
|
|
407
|
+
1: "USDC"
|
|
408
|
+
},
|
|
409
|
+
addresses: {
|
|
410
|
+
8453: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
411
|
+
// Base
|
|
412
|
+
42161: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
413
|
+
// Arbitrum
|
|
414
|
+
9745: "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
|
|
415
|
+
// Plasma
|
|
416
|
+
146: "0x29219dd400f2bf60e5a23d13be72b486d4038894",
|
|
417
|
+
// Sonic
|
|
418
|
+
59144: "0x176211869ca2b568f2a7d4ee941e073a821ee1ff",
|
|
419
|
+
// Linea
|
|
420
|
+
1: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
421
|
+
// Ethereum
|
|
422
|
+
},
|
|
423
|
+
enabled: true
|
|
424
|
+
},
|
|
425
|
+
WETH: {
|
|
426
|
+
symbol: "WETH",
|
|
427
|
+
assetType: "eth",
|
|
428
|
+
displayName: "WETH",
|
|
429
|
+
icon: "/ai-dashboard/eth-token.png",
|
|
430
|
+
decimals: 18,
|
|
431
|
+
tokenSymbols: ["WETH", "ETH"],
|
|
432
|
+
tokenSymbolsByChainId: {
|
|
433
|
+
8453: "WETH",
|
|
434
|
+
42161: "WETH",
|
|
435
|
+
9745: "WETH",
|
|
436
|
+
146: "WETH",
|
|
437
|
+
59144: "WETH",
|
|
438
|
+
1: "WETH"
|
|
439
|
+
},
|
|
440
|
+
addresses: {
|
|
441
|
+
8453: "0x4200000000000000000000000000000000000006",
|
|
442
|
+
// Base
|
|
443
|
+
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
444
|
+
// Arbitrum
|
|
445
|
+
9745: "0x4200000000000000000000000000000000000006",
|
|
446
|
+
// Plasma
|
|
447
|
+
146: "0x039e64f90d4199560e7533692f69448878db85c7",
|
|
448
|
+
// Sonic
|
|
449
|
+
59144: "0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f",
|
|
450
|
+
// Linea
|
|
451
|
+
1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
452
|
+
// Ethereum
|
|
453
|
+
},
|
|
454
|
+
enabled: true
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
var getDefaultTokenAddress = (chainId, asset) => {
|
|
458
|
+
const address = ASSET_CONFIGS[asset || "USDC"]?.addresses[chainId];
|
|
373
459
|
if (!address || address === "0x0000000000000000000000000000000000000000") {
|
|
374
460
|
throw new Error(
|
|
375
461
|
`Default token address not configured for chain ${chainId}. Please provide tokenAddress explicitly.`
|
|
@@ -800,38 +886,39 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
800
886
|
async updateUserProfile(request) {
|
|
801
887
|
try {
|
|
802
888
|
await this.authenticateUser();
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
|
|
889
|
+
const asset = request.asset || "usdc";
|
|
890
|
+
let rebalanceStrategy;
|
|
891
|
+
if (request.strategy) {
|
|
892
|
+
if (!isValidPublicStrategy(request.strategy)) {
|
|
806
893
|
throw new Error(
|
|
807
|
-
`Invalid strategy: ${
|
|
894
|
+
`Invalid strategy: ${request.strategy}. Must be "conservative" or "aggressive".`
|
|
808
895
|
);
|
|
809
896
|
}
|
|
810
|
-
|
|
811
|
-
|
|
897
|
+
rebalanceStrategy = toInternalStrategy(
|
|
898
|
+
request.strategy
|
|
812
899
|
);
|
|
813
900
|
}
|
|
814
|
-
const
|
|
901
|
+
const assetSettings = {};
|
|
902
|
+
if (rebalanceStrategy !== void 0) assetSettings.rebalanceStrategy = rebalanceStrategy;
|
|
903
|
+
if (request.autocompounding !== void 0) assetSettings.autocompounding = request.autocompounding;
|
|
904
|
+
if (request.crosschainStrategy !== void 0) assetSettings.crosschainStrategy = request.crosschainStrategy;
|
|
905
|
+
if (request.splitting !== void 0) assetSettings.splitting = request.splitting;
|
|
906
|
+
if (request.minSplits !== void 0) assetSettings.minSplits = request.minSplits;
|
|
907
|
+
if (request.chains !== void 0) assetSettings.chains = request.chains;
|
|
908
|
+
if (request.autoSelectProtocols !== void 0) assetSettings.autoSelectProtocols = request.autoSelectProtocols;
|
|
909
|
+
if (request.protocols !== void 0) assetSettings.protocols = request.protocols;
|
|
910
|
+
const payload = {
|
|
911
|
+
assetTypeSettings: {
|
|
912
|
+
[asset]: assetSettings
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
if (request.omniAccount !== void 0) payload.omniAccount = request.omniAccount;
|
|
916
|
+
if (request.agentName !== void 0) payload.agentName = request.agentName;
|
|
917
|
+
await this.httpClient.patch(
|
|
815
918
|
ENDPOINTS.USER_ME,
|
|
816
919
|
payload
|
|
817
920
|
);
|
|
818
|
-
return
|
|
819
|
-
success: true,
|
|
820
|
-
userId: response.userId || response.id,
|
|
821
|
-
smartWallet: response.smartWallet,
|
|
822
|
-
chains: response.chains,
|
|
823
|
-
strategy: response.strategy,
|
|
824
|
-
protocols: response.protocols,
|
|
825
|
-
autoSelectProtocols: response.autoSelectProtocols,
|
|
826
|
-
omniAccount: response.omniAccount,
|
|
827
|
-
autocompounding: response.autocompounding,
|
|
828
|
-
agentName: response.agentName,
|
|
829
|
-
crosschainStrategy: response.crosschainStrategy,
|
|
830
|
-
executorProxy: response.executorProxy,
|
|
831
|
-
splitting: response.splitting,
|
|
832
|
-
minSplits: response.minSplits,
|
|
833
|
-
customization: response.customization
|
|
834
|
-
};
|
|
921
|
+
return await this.getUserDetails(asset);
|
|
835
922
|
} catch (error) {
|
|
836
923
|
throw new Error(
|
|
837
924
|
`Failed to update user profile: ${error.message}`
|
|
@@ -858,7 +945,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
858
945
|
*/
|
|
859
946
|
async pauseAgent() {
|
|
860
947
|
try {
|
|
948
|
+
await this.updateUserProfile({
|
|
949
|
+
asset: "usdc",
|
|
950
|
+
protocols: []
|
|
951
|
+
});
|
|
861
952
|
const response = await this.updateUserProfile({
|
|
953
|
+
asset: "eth",
|
|
862
954
|
protocols: []
|
|
863
955
|
});
|
|
864
956
|
return response;
|
|
@@ -867,49 +959,58 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
867
959
|
}
|
|
868
960
|
}
|
|
869
961
|
/**
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
962
|
+
* Resume the agent by restoring protocols based on user's strategy for each asset
|
|
963
|
+
* Fetches available protocols and assigns them based on each asset's strategy
|
|
964
|
+
*
|
|
965
|
+
* @returns Response indicating success and updated user details
|
|
966
|
+
*
|
|
967
|
+
* @example
|
|
968
|
+
* ```typescript
|
|
969
|
+
* const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
|
|
970
|
+
*
|
|
971
|
+
* // Connect account first
|
|
972
|
+
* await sdk.connectAccount();
|
|
973
|
+
*
|
|
974
|
+
* // Resume the agent
|
|
975
|
+
* const result = await sdk.resumeAgent();
|
|
976
|
+
* console.log('Agent resumed:', result.success);
|
|
977
|
+
* ```
|
|
978
|
+
*/
|
|
887
979
|
async resumeAgent() {
|
|
888
980
|
try {
|
|
889
|
-
const
|
|
890
|
-
const
|
|
891
|
-
const
|
|
892
|
-
const convertedStrategy = toInternalStrategy(strategy);
|
|
893
|
-
const chains = userChains && userChains.length > 0 ? userChains : [8453, 42161];
|
|
981
|
+
const userDetailsUSDC = await this.getUserDetails("usdc");
|
|
982
|
+
const userDetailsETH = await this.getUserDetails("eth");
|
|
983
|
+
const chains = userDetailsUSDC.chains && userDetailsUSDC.chains.length > 0 ? userDetailsUSDC.chains : [8453, 42161];
|
|
894
984
|
const allProtocols = await this.httpClient.get(
|
|
895
985
|
ENDPOINTS.PROTOCOLS()
|
|
896
986
|
);
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
)
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
987
|
+
const usdcStrategy = userDetailsUSDC.strategy || "safe_strategy";
|
|
988
|
+
const ethStrategy = userDetailsETH.strategy || "safe_strategy";
|
|
989
|
+
const filterProtocolsByStrategy = (strategy) => {
|
|
990
|
+
return allProtocols.filter((protocol) => {
|
|
991
|
+
const hasMatchingChain = protocol.chains.some(
|
|
992
|
+
(chain) => chains.includes(chain)
|
|
993
|
+
);
|
|
994
|
+
if (!hasMatchingChain) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
if (strategy === "degen_strategy") {
|
|
998
|
+
return protocol.strategies?.includes("safe_strategy") || protocol.strategies?.includes("degen_strategy");
|
|
999
|
+
}
|
|
1000
|
+
return protocol.strategies?.includes("safe_strategy");
|
|
1001
|
+
}).map((protocol) => protocol.id);
|
|
1002
|
+
};
|
|
1003
|
+
const usdcProtocols = filterProtocolsByStrategy(usdcStrategy);
|
|
1004
|
+
const ethProtocols = filterProtocolsByStrategy(ethStrategy);
|
|
1005
|
+
await this.updateUserProfile({
|
|
1006
|
+
asset: "usdc",
|
|
1007
|
+
protocols: usdcProtocols
|
|
911
1008
|
});
|
|
912
|
-
|
|
1009
|
+
const updatedUserDetailsETH = await this.updateUserProfile({
|
|
1010
|
+
asset: "eth",
|
|
1011
|
+
protocols: ethProtocols
|
|
1012
|
+
});
|
|
1013
|
+
return updatedUserDetailsETH;
|
|
913
1014
|
} catch (error) {
|
|
914
1015
|
throw new Error(`Failed to resume agent: ${error.message}`);
|
|
915
1016
|
}
|
|
@@ -1496,14 +1597,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1496
1597
|
async updateUserProtocols(chainId) {
|
|
1497
1598
|
try {
|
|
1498
1599
|
const protocolsResponse = await this.getAvailableProtocols(chainId);
|
|
1499
|
-
|
|
1600
|
+
const userDetails = await this.getUserDetails();
|
|
1601
|
+
const filteredProtocols = userDetails.strategy ? protocolsResponse.protocols.filter((p) => p.strategies?.includes(userDetails.strategy)) : protocolsResponse.protocols;
|
|
1602
|
+
if (!filteredProtocols || filteredProtocols.length === 0) {
|
|
1500
1603
|
console.warn(`No protocols available for chain ${chainId}`);
|
|
1501
1604
|
return;
|
|
1502
1605
|
}
|
|
1503
|
-
const protocolIds =
|
|
1606
|
+
const protocolIds = filteredProtocols.map((p) => p.id);
|
|
1504
1607
|
await this.updateUserProfile({
|
|
1505
1608
|
protocols: protocolIds
|
|
1506
1609
|
});
|
|
1610
|
+
await this.updateUserProfile({
|
|
1611
|
+
protocols: protocolIds,
|
|
1612
|
+
asset: "eth"
|
|
1613
|
+
});
|
|
1507
1614
|
} catch (error) {
|
|
1508
1615
|
console.warn(
|
|
1509
1616
|
`Failed to update user protocols: ${error.message}`
|
|
@@ -1565,7 +1672,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1565
1672
|
* );
|
|
1566
1673
|
* ```
|
|
1567
1674
|
*/
|
|
1568
|
-
async depositFunds(userAddress, chainId, amount) {
|
|
1675
|
+
async depositFunds(userAddress, chainId, amount, asset) {
|
|
1569
1676
|
try {
|
|
1570
1677
|
if (!userAddress) {
|
|
1571
1678
|
throw new Error("User address is required");
|
|
@@ -1576,7 +1683,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1576
1683
|
if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
|
|
1577
1684
|
throw new Error("Valid amount is required");
|
|
1578
1685
|
}
|
|
1579
|
-
const token = getDefaultTokenAddress(chainId);
|
|
1686
|
+
const token = getDefaultTokenAddress(chainId, asset);
|
|
1580
1687
|
const walletClient = this.getWalletClient();
|
|
1581
1688
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1582
1689
|
const safeAddress = await getDeterministicSafeAddress({
|
|
@@ -1628,6 +1735,71 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1628
1735
|
throw new Error(`Deposit failed: ${error.message}`);
|
|
1629
1736
|
}
|
|
1630
1737
|
}
|
|
1738
|
+
/**
|
|
1739
|
+
* Log a deposit that was executed client-side
|
|
1740
|
+
*
|
|
1741
|
+
* Use this method when you execute the deposit transaction yourself (e.g., with Privy,
|
|
1742
|
+
* sponsored transactions, or any custom wallet implementation) and need to register
|
|
1743
|
+
* the deposit with the Zyfai backend for tracking and yield optimization.
|
|
1744
|
+
*
|
|
1745
|
+
* This is useful for partners who:
|
|
1746
|
+
* - Use sponsored/gasless transactions (Privy, Biconomy, etc.)
|
|
1747
|
+
* - Have custom wallet implementations
|
|
1748
|
+
* - Need more control over transaction execution
|
|
1749
|
+
*
|
|
1750
|
+
* Token is automatically selected based on chain if not provided:
|
|
1751
|
+
* - Base (8453) and Arbitrum (42161): USDC
|
|
1752
|
+
* - Plasma (9745): USDT
|
|
1753
|
+
*
|
|
1754
|
+
* @param chainId - Chain ID where the deposit was made
|
|
1755
|
+
* @param txHash - Transaction hash of the deposit
|
|
1756
|
+
* @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
|
|
1757
|
+
* @param tokenAddress - Optional: Token address (auto-selected based on chain if not provided)
|
|
1758
|
+
* @returns Log deposit response with success status
|
|
1759
|
+
*
|
|
1760
|
+
* @example
|
|
1761
|
+
* ```typescript
|
|
1762
|
+
* // Execute deposit with Privy (sponsored transaction)
|
|
1763
|
+
* const txHash = await privyWallet.sendTransaction({
|
|
1764
|
+
* to: safeAddress,
|
|
1765
|
+
* data: transferData,
|
|
1766
|
+
* });
|
|
1767
|
+
*
|
|
1768
|
+
* // Log the deposit to Zyfai backend
|
|
1769
|
+
* const result = await sdk.logDeposit(
|
|
1770
|
+
* 8453, // chainId
|
|
1771
|
+
* txHash, // transaction hash from Privy
|
|
1772
|
+
* "100000000" // 100 USDC
|
|
1773
|
+
* );
|
|
1774
|
+
* console.log(result.success); // true
|
|
1775
|
+
* ```
|
|
1776
|
+
*/
|
|
1777
|
+
async logDeposit(chainId, txHash, amount, tokenAddress) {
|
|
1778
|
+
try {
|
|
1779
|
+
if (!isSupportedChain(chainId)) {
|
|
1780
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
1781
|
+
}
|
|
1782
|
+
if (!txHash || !txHash.startsWith("0x")) {
|
|
1783
|
+
throw new Error("Valid transaction hash is required");
|
|
1784
|
+
}
|
|
1785
|
+
if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
|
|
1786
|
+
throw new Error("Valid amount is required");
|
|
1787
|
+
}
|
|
1788
|
+
const token = tokenAddress || getDefaultTokenAddress(chainId);
|
|
1789
|
+
await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
|
|
1790
|
+
chainId,
|
|
1791
|
+
transaction: txHash,
|
|
1792
|
+
token,
|
|
1793
|
+
amount
|
|
1794
|
+
});
|
|
1795
|
+
return {
|
|
1796
|
+
success: true,
|
|
1797
|
+
message: "Deposit logged successfully"
|
|
1798
|
+
};
|
|
1799
|
+
} catch (error) {
|
|
1800
|
+
throw new Error(`Log deposit failed: ${error.message}`);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1631
1803
|
/**
|
|
1632
1804
|
* Withdraw funds from Safe smart wallet
|
|
1633
1805
|
* Initiates a withdrawal request to the Zyfai API
|
|
@@ -1653,7 +1825,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1653
1825
|
* );
|
|
1654
1826
|
* ```
|
|
1655
1827
|
*/
|
|
1656
|
-
async withdrawFunds(userAddress, chainId, amount) {
|
|
1828
|
+
async withdrawFunds(userAddress, chainId, amount, tokenSymbol) {
|
|
1657
1829
|
try {
|
|
1658
1830
|
if (!userAddress) {
|
|
1659
1831
|
throw new Error("User address is required");
|
|
@@ -1695,12 +1867,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1695
1867
|
if (amount) {
|
|
1696
1868
|
response = await this.httpClient.post(ENDPOINTS.PARTIAL_WITHDRAW, {
|
|
1697
1869
|
chainId,
|
|
1698
|
-
amount
|
|
1870
|
+
amount,
|
|
1871
|
+
tokenSymbol
|
|
1699
1872
|
});
|
|
1700
1873
|
} else {
|
|
1874
|
+
console.log("Full withdrawal", tokenSymbol);
|
|
1701
1875
|
response = await this.httpClient.get(ENDPOINTS.USER_WITHDRAW, {
|
|
1702
|
-
params: { chainId }
|
|
1876
|
+
params: { chainId, tokenSymbol }
|
|
1703
1877
|
});
|
|
1878
|
+
console.log(JSON.stringify(response, null, 2));
|
|
1704
1879
|
}
|
|
1705
1880
|
const success = response?.success ?? true;
|
|
1706
1881
|
const message = response?.message || "Withdrawal request sent";
|
|
@@ -1811,35 +1986,27 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1811
1986
|
* console.log("Chains:", user.user.chains);
|
|
1812
1987
|
* ```
|
|
1813
1988
|
*/
|
|
1814
|
-
async getUserDetails() {
|
|
1989
|
+
async getUserDetails(asset = "usdc") {
|
|
1815
1990
|
try {
|
|
1816
1991
|
await this.authenticateUser();
|
|
1817
1992
|
const response = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
1818
1993
|
const convertedResponse = convertStrategyToPublic(response);
|
|
1819
1994
|
return {
|
|
1820
1995
|
success: true,
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
crosschainStrategy: convertedResponse.crosschainStrategy,
|
|
1836
|
-
agentName: convertedResponse.agentName,
|
|
1837
|
-
customization: convertedResponse.customization,
|
|
1838
|
-
executorProxy: convertedResponse.executorProxy,
|
|
1839
|
-
splitting: convertedResponse.splitting,
|
|
1840
|
-
minSplits: convertedResponse.minSplits,
|
|
1841
|
-
registered: convertedResponse.registered
|
|
1842
|
-
}
|
|
1996
|
+
agentName: convertedResponse.agentName,
|
|
1997
|
+
smartWallet: convertedResponse.smartWallet,
|
|
1998
|
+
chains: convertedResponse.assetTypeSettings?.[asset]?.chains || [],
|
|
1999
|
+
hasActiveSessionKey: convertedResponse.hasActiveSessionKey || false,
|
|
2000
|
+
omniAccount: convertedResponse.omniAccount,
|
|
2001
|
+
asset,
|
|
2002
|
+
autoSelectProtocols: convertedResponse.assetTypeSettings?.[asset]?.autoSelectProtocols,
|
|
2003
|
+
strategy: convertedResponse.assetTypeSettings?.[asset]?.rebalanceStrategy,
|
|
2004
|
+
autocompounding: convertedResponse.assetTypeSettings?.[asset]?.autocompounding,
|
|
2005
|
+
crosschainStrategy: convertedResponse.assetTypeSettings?.[asset]?.crosschainStrategy,
|
|
2006
|
+
splitting: convertedResponse.assetTypeSettings?.[asset]?.splitting,
|
|
2007
|
+
minSplits: convertedResponse.assetTypeSettings?.[asset]?.minSplits || 0,
|
|
2008
|
+
protocols: convertedResponse.assetTypeSettings?.[asset]?.protocols || [],
|
|
2009
|
+
customization: convertedResponse.customization
|
|
1843
2010
|
};
|
|
1844
2011
|
} catch (error) {
|
|
1845
2012
|
throw new Error(
|
|
@@ -1864,18 +2031,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1864
2031
|
async getTVL() {
|
|
1865
2032
|
try {
|
|
1866
2033
|
const response = await this.httpClient.get(ENDPOINTS.DATA_TVL);
|
|
1867
|
-
const byChain = {};
|
|
1868
|
-
for (const key of Object.keys(response)) {
|
|
1869
|
-
const numKey = parseInt(key, 10);
|
|
1870
|
-
if (!isNaN(numKey) && typeof response[key] === "number") {
|
|
1871
|
-
byChain[numKey] = response[key];
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
2034
|
return {
|
|
1875
2035
|
success: true,
|
|
1876
|
-
totalTvl: response.total ||
|
|
1877
|
-
byChain,
|
|
1878
|
-
breakdown: response.breakdown
|
|
2036
|
+
totalTvl: response.total || 0
|
|
1879
2037
|
};
|
|
1880
2038
|
} catch (error) {
|
|
1881
2039
|
throw new Error(`Failed to get TVL: ${error.message}`);
|
|
@@ -1890,20 +2048,28 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1890
2048
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
1891
2049
|
* @param days - Time period: 7, 14, or 30
|
|
1892
2050
|
* @param strategy - Strategy type: "conservative" (default) or "aggressive"
|
|
2051
|
+
* @param chainId - Optional chain ID filter
|
|
2052
|
+
* @param tokenSymbol - Optional token symbol filter (e.g. "USDC", "WETH", "WBTC")
|
|
1893
2053
|
* @returns APY per strategy for a specific chain
|
|
1894
2054
|
*
|
|
1895
2055
|
* @example
|
|
1896
2056
|
* ```typescript
|
|
1897
|
-
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
2057
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative", 8453, "USDC");
|
|
1898
2058
|
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
1899
2059
|
* ```
|
|
1900
2060
|
*/
|
|
1901
|
-
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative") {
|
|
2061
|
+
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative", chainId, tokenSymbol) {
|
|
1902
2062
|
try {
|
|
1903
2063
|
const internalStrategy = toInternalStrategy(strategy);
|
|
1904
2064
|
const internalStrategyShort = internalStrategy === "safe_strategy" ? "safe" : "degen";
|
|
1905
2065
|
const response = await this.httpClient.dataGet(
|
|
1906
|
-
DATA_ENDPOINTS.APY_PER_STRATEGY(
|
|
2066
|
+
DATA_ENDPOINTS.APY_PER_STRATEGY({
|
|
2067
|
+
isCrossChain: crossChain,
|
|
2068
|
+
days,
|
|
2069
|
+
strategy: internalStrategyShort,
|
|
2070
|
+
chainId,
|
|
2071
|
+
tokenSymbol
|
|
2072
|
+
})
|
|
1907
2073
|
);
|
|
1908
2074
|
const convertedData = convertStrategiesToPublicAndNaming(
|
|
1909
2075
|
response.data || []
|
|
@@ -1930,9 +2096,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1930
2096
|
* console.log("Total Volume:", volume.volumeInUSD);
|
|
1931
2097
|
* ```
|
|
1932
2098
|
*/
|
|
1933
|
-
async getVolume() {
|
|
2099
|
+
async getVolume(assetType = "usdc") {
|
|
1934
2100
|
try {
|
|
1935
|
-
const response = await this.httpClient.get(ENDPOINTS.DATA_VOLUME);
|
|
2101
|
+
const response = await this.httpClient.get(ENDPOINTS.DATA_VOLUME(assetType));
|
|
1936
2102
|
return {
|
|
1937
2103
|
success: true,
|
|
1938
2104
|
volumeInUSD: response.volumeInUSD || "0"
|
|
@@ -2099,12 +2265,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2099
2265
|
* Get onchain earnings for a wallet
|
|
2100
2266
|
*
|
|
2101
2267
|
* @param walletAddress - Smart wallet address
|
|
2102
|
-
* @returns Onchain earnings data
|
|
2268
|
+
* @returns Onchain earnings data with per-token breakdowns
|
|
2103
2269
|
*
|
|
2104
2270
|
* @example
|
|
2105
2271
|
* ```typescript
|
|
2106
2272
|
* const earnings = await sdk.getOnchainEarnings("0x...");
|
|
2107
|
-
* console.log("Total
|
|
2273
|
+
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
2108
2274
|
* ```
|
|
2109
2275
|
*/
|
|
2110
2276
|
async getOnchainEarnings(walletAddress) {
|
|
@@ -2119,13 +2285,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2119
2285
|
success: true,
|
|
2120
2286
|
data: {
|
|
2121
2287
|
walletAddress,
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
unrealizedEarnings: response.unrealized_earnings,
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
lastCheckTimestamp: response.last_check_timestamp
|
|
2288
|
+
totalEarningsByToken: response.total_earnings_by_token || {},
|
|
2289
|
+
lifetimeEarningsByToken: response.lifetime_earnings_by_token || {},
|
|
2290
|
+
currentEarningsByChain: response.current_earnings_by_chain || {},
|
|
2291
|
+
unrealizedEarnings: response.unrealized_earnings || {},
|
|
2292
|
+
lastCheckTimestamp: response.last_check_timestamp,
|
|
2293
|
+
lastLogDate: response.last_log_date
|
|
2129
2294
|
}
|
|
2130
2295
|
};
|
|
2131
2296
|
} catch (error) {
|
|
@@ -2139,12 +2304,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2139
2304
|
* This triggers a recalculation of earnings on the backend
|
|
2140
2305
|
*
|
|
2141
2306
|
* @param walletAddress - Smart wallet address
|
|
2142
|
-
* @returns Updated onchain earnings data
|
|
2307
|
+
* @returns Updated onchain earnings data with per-token breakdowns
|
|
2143
2308
|
*
|
|
2144
2309
|
* @example
|
|
2145
2310
|
* ```typescript
|
|
2146
2311
|
* const earnings = await sdk.calculateOnchainEarnings("0x...");
|
|
2147
|
-
* console.log("
|
|
2312
|
+
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
2148
2313
|
* ```
|
|
2149
2314
|
*/
|
|
2150
2315
|
async calculateOnchainEarnings(walletAddress) {
|
|
@@ -2161,11 +2326,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2161
2326
|
success: true,
|
|
2162
2327
|
data: {
|
|
2163
2328
|
walletAddress,
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
unrealizedEarnings: data.unrealized_earnings,
|
|
2168
|
-
lastCheckTimestamp: data.last_check_timestamp
|
|
2329
|
+
totalEarningsByToken: data.total_earnings_by_token || {},
|
|
2330
|
+
lifetimeEarningsByToken: data.lifetime_earnings_by_token || {},
|
|
2331
|
+
currentEarningsByChain: data.current_earnings_by_chain || {},
|
|
2332
|
+
unrealizedEarnings: data.unrealized_earnings || {},
|
|
2333
|
+
lastCheckTimestamp: data.last_check_timestamp,
|
|
2334
|
+
lastLogDate: data.last_log_date
|
|
2169
2335
|
}
|
|
2170
2336
|
};
|
|
2171
2337
|
} catch (error) {
|
|
@@ -2185,7 +2351,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2185
2351
|
* @example
|
|
2186
2352
|
* ```typescript
|
|
2187
2353
|
* const daily = await sdk.getDailyEarnings("0x...", "2024-01-01", "2024-01-31");
|
|
2188
|
-
* daily.data.forEach(d => console.log(d.
|
|
2354
|
+
* daily.data.forEach(d => console.log(d.snapshot_date, d.total_earnings_by_token));
|
|
2189
2355
|
* ```
|
|
2190
2356
|
*/
|
|
2191
2357
|
async getDailyEarnings(walletAddress, startDate, endDate) {
|
|
@@ -2213,61 +2379,25 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2213
2379
|
}
|
|
2214
2380
|
}
|
|
2215
2381
|
// ============================================================================
|
|
2216
|
-
// Portfolio Methods (Data API v2)
|
|
2217
|
-
// ============================================================================
|
|
2218
|
-
/**
|
|
2219
|
-
* Get Debank portfolio for a wallet across multiple chains
|
|
2220
|
-
* Note: This is a paid endpoint and may require authorization
|
|
2221
|
-
*
|
|
2222
|
-
* @param walletAddress - Smart wallet address
|
|
2223
|
-
* @returns Multi-chain portfolio data
|
|
2224
|
-
*
|
|
2225
|
-
* @example
|
|
2226
|
-
* ```typescript
|
|
2227
|
-
* const portfolio = await sdk.getDebankPortfolio("0x...");
|
|
2228
|
-
* console.log("Total value:", portfolio.totalValueUsd);
|
|
2229
|
-
* ```
|
|
2230
|
-
*/
|
|
2231
|
-
async getDebankPortfolio(walletAddress) {
|
|
2232
|
-
try {
|
|
2233
|
-
if (!walletAddress) {
|
|
2234
|
-
throw new Error("Wallet address is required");
|
|
2235
|
-
}
|
|
2236
|
-
const response = await this.httpClient.dataGet(
|
|
2237
|
-
DATA_ENDPOINTS.DEBANK_PORTFOLIO_MULTICHAIN(walletAddress)
|
|
2238
|
-
);
|
|
2239
|
-
const data = response.data || response;
|
|
2240
|
-
return {
|
|
2241
|
-
success: true,
|
|
2242
|
-
walletAddress,
|
|
2243
|
-
totalValueUsd: data.totalValueUsd || 0,
|
|
2244
|
-
chains: data.chains || data
|
|
2245
|
-
};
|
|
2246
|
-
} catch (error) {
|
|
2247
|
-
throw new Error(
|
|
2248
|
-
`Failed to get Debank portfolio: ${error.message}`
|
|
2249
|
-
);
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
// ============================================================================
|
|
2253
2382
|
// Opportunities Methods (Data API v2)
|
|
2254
2383
|
// ============================================================================
|
|
2255
2384
|
/**
|
|
2256
2385
|
* Get conservative (low-risk) yield opportunities
|
|
2257
2386
|
*
|
|
2258
2387
|
* @param chainId - Optional chain ID filter
|
|
2388
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2259
2389
|
* @returns List of conservative yield opportunities
|
|
2260
2390
|
*
|
|
2261
2391
|
* @example
|
|
2262
2392
|
* ```typescript
|
|
2263
|
-
* const opportunities = await sdk.getConservativeOpportunities(8453);
|
|
2393
|
+
* const opportunities = await sdk.getConservativeOpportunities(8453, "USDC");
|
|
2264
2394
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2265
2395
|
* ```
|
|
2266
2396
|
*/
|
|
2267
|
-
async getConservativeOpportunities(chainId) {
|
|
2397
|
+
async getConservativeOpportunities(chainId, asset, status) {
|
|
2268
2398
|
try {
|
|
2269
2399
|
const response = await this.httpClient.dataGet(
|
|
2270
|
-
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
2400
|
+
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId, asset, status)
|
|
2271
2401
|
);
|
|
2272
2402
|
const data = response.data || response || [];
|
|
2273
2403
|
return {
|
|
@@ -2280,7 +2410,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2280
2410
|
protocolName: o.protocol_name || o.protocolName,
|
|
2281
2411
|
poolName: o.pool_name || o.poolName,
|
|
2282
2412
|
chainId: o.chain_id || o.chainId,
|
|
2283
|
-
apy: o.
|
|
2413
|
+
apy: o.combined_apy || 0,
|
|
2284
2414
|
tvl: o.tvl || o.zyfiTvl,
|
|
2285
2415
|
asset: o.asset || o.underlying_token,
|
|
2286
2416
|
risk: o.risk,
|
|
@@ -2298,18 +2428,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2298
2428
|
* Get aggressive (high-risk, high-reward) yield opportunities
|
|
2299
2429
|
*
|
|
2300
2430
|
* @param chainId - Optional chain ID filter
|
|
2431
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2301
2432
|
* @returns List of aggressive opportunities
|
|
2302
2433
|
*
|
|
2303
2434
|
* @example
|
|
2304
2435
|
* ```typescript
|
|
2305
|
-
* const opportunities = await sdk.getAggressiveOpportunities(8453);
|
|
2436
|
+
* const opportunities = await sdk.getAggressiveOpportunities(8453, "WETH");
|
|
2306
2437
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2307
2438
|
* ```
|
|
2308
2439
|
*/
|
|
2309
|
-
async getAggressiveOpportunities(chainId) {
|
|
2440
|
+
async getAggressiveOpportunities(chainId, asset, status) {
|
|
2310
2441
|
try {
|
|
2311
2442
|
const response = await this.httpClient.dataGet(
|
|
2312
|
-
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
|
2443
|
+
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset, status)
|
|
2313
2444
|
);
|
|
2314
2445
|
const data = response.data || response || [];
|
|
2315
2446
|
return {
|
|
@@ -2322,7 +2453,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2322
2453
|
protocolName: o.protocol_name || o.protocolName,
|
|
2323
2454
|
poolName: o.pool_name || o.poolName,
|
|
2324
2455
|
chainId: o.chain_id || o.chainId,
|
|
2325
|
-
apy: o.
|
|
2456
|
+
apy: o.combined_apy || 0,
|
|
2326
2457
|
tvl: o.tvl || o.zyfiTvl,
|
|
2327
2458
|
asset: o.asset || o.underlying_token,
|
|
2328
2459
|
risk: o.risk,
|
|
@@ -2341,6 +2472,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2341
2472
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
2342
2473
|
*
|
|
2343
2474
|
* @param chainId - Optional chain ID filter
|
|
2475
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2344
2476
|
* @returns Active conservative opportunities with risk data
|
|
2345
2477
|
*
|
|
2346
2478
|
* @example
|
|
@@ -2349,10 +2481,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2349
2481
|
* console.log(JSON.stringify(opps, null, 2));
|
|
2350
2482
|
* ```
|
|
2351
2483
|
*/
|
|
2352
|
-
async getActiveConservativeOppsRisk(chainId) {
|
|
2484
|
+
async getActiveConservativeOppsRisk(chainId, asset) {
|
|
2353
2485
|
try {
|
|
2354
2486
|
const response = await this.httpClient.dataGet(
|
|
2355
|
-
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
2487
|
+
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId, asset)
|
|
2356
2488
|
);
|
|
2357
2489
|
const data = response.data || response || [];
|
|
2358
2490
|
const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
|
|
@@ -2386,6 +2518,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2386
2518
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
2387
2519
|
*
|
|
2388
2520
|
* @param chainId - Optional chain ID filter
|
|
2521
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2389
2522
|
* @returns Active aggressive opportunities with risk data
|
|
2390
2523
|
*
|
|
2391
2524
|
* @example
|
|
@@ -2394,10 +2527,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2394
2527
|
* console.log(JSON.stringify(opps, null, 2));
|
|
2395
2528
|
* ```
|
|
2396
2529
|
*/
|
|
2397
|
-
async getActiveAggressiveOppsRisk(chainId) {
|
|
2530
|
+
async getActiveAggressiveOppsRisk(chainId, asset) {
|
|
2398
2531
|
try {
|
|
2399
2532
|
const response = await this.httpClient.dataGet(
|
|
2400
|
-
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
|
2533
|
+
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset)
|
|
2401
2534
|
);
|
|
2402
2535
|
const data = response.data || response || [];
|
|
2403
2536
|
const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
|
|
@@ -2431,10 +2564,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2431
2564
|
* Builds on getActiveConservativeOppsRisk and computes higher-level status indicators
|
|
2432
2565
|
*
|
|
2433
2566
|
* @param chainId - Optional chain ID filter
|
|
2567
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2434
2568
|
* @returns Conservative pools with status data
|
|
2435
2569
|
*/
|
|
2436
|
-
async getConservativePoolStatus(chainId) {
|
|
2437
|
-
const pools = await this.getActiveConservativeOppsRisk(chainId);
|
|
2570
|
+
async getConservativePoolStatus(chainId, asset) {
|
|
2571
|
+
const pools = await this.getActiveConservativeOppsRisk(chainId, asset);
|
|
2438
2572
|
return pools.map((p) => this.derivePoolStatus(p));
|
|
2439
2573
|
}
|
|
2440
2574
|
/**
|
|
@@ -2442,10 +2576,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2442
2576
|
* Builds on getActiveAggressiveOppsRisk and computes higher-level status indicators
|
|
2443
2577
|
*
|
|
2444
2578
|
* @param chainId - Optional chain ID filter
|
|
2579
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2445
2580
|
* @returns Aggressive pools with status data
|
|
2446
2581
|
*/
|
|
2447
|
-
async getAggressivePoolStatus(chainId) {
|
|
2448
|
-
const pools = await this.getActiveAggressiveOppsRisk(chainId);
|
|
2582
|
+
async getAggressivePoolStatus(chainId, asset) {
|
|
2583
|
+
const pools = await this.getActiveAggressiveOppsRisk(chainId, asset);
|
|
2449
2584
|
return pools.map((p) => this.derivePoolStatus(p));
|
|
2450
2585
|
}
|
|
2451
2586
|
derivePoolStatus(p) {
|
|
@@ -2494,12 +2629,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2494
2629
|
*
|
|
2495
2630
|
* @param walletAddress - Smart wallet address
|
|
2496
2631
|
* @param days - Period: "7D", "14D", or "30D" (default: "7D")
|
|
2497
|
-
* @returns Daily APY history with weighted averages
|
|
2632
|
+
* @returns Daily APY history with per-position breakdowns and weighted averages
|
|
2498
2633
|
*
|
|
2499
2634
|
* @example
|
|
2500
2635
|
* ```typescript
|
|
2501
2636
|
* const apyHistory = await sdk.getDailyApyHistory("0x...", "30D");
|
|
2502
|
-
* console.log("
|
|
2637
|
+
* console.log("Weighted APY after fee:", apyHistory.weightedApyAfterFee); // { "USDC": 4.64, "WETH": 1.94 }
|
|
2503
2638
|
* ```
|
|
2504
2639
|
*/
|
|
2505
2640
|
async getDailyApyHistory(walletAddress, days = "7D") {
|