@zyfai/sdk 0.2.23 → 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 +23 -10
- package/dist/index.d.mts +101 -114
- package/dist/index.d.ts +101 -114
- package/dist/index.js +262 -192
- package/dist/index.mjs +262 -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({
|
|
@@ -1740,7 +1847,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1740
1847
|
* );
|
|
1741
1848
|
* ```
|
|
1742
1849
|
*/
|
|
1743
|
-
async withdrawFunds(userAddress, chainId, amount) {
|
|
1850
|
+
async withdrawFunds(userAddress, chainId, amount, tokenSymbol) {
|
|
1744
1851
|
try {
|
|
1745
1852
|
if (!userAddress) {
|
|
1746
1853
|
throw new Error("User address is required");
|
|
@@ -1782,12 +1889,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1782
1889
|
if (amount) {
|
|
1783
1890
|
response = await this.httpClient.post(ENDPOINTS.PARTIAL_WITHDRAW, {
|
|
1784
1891
|
chainId,
|
|
1785
|
-
amount
|
|
1892
|
+
amount,
|
|
1893
|
+
tokenSymbol
|
|
1786
1894
|
});
|
|
1787
1895
|
} else {
|
|
1896
|
+
console.log("Full withdrawal", tokenSymbol);
|
|
1788
1897
|
response = await this.httpClient.get(ENDPOINTS.USER_WITHDRAW, {
|
|
1789
|
-
params: { chainId }
|
|
1898
|
+
params: { chainId, tokenSymbol }
|
|
1790
1899
|
});
|
|
1900
|
+
console.log(JSON.stringify(response, null, 2));
|
|
1791
1901
|
}
|
|
1792
1902
|
const success = response?.success ?? true;
|
|
1793
1903
|
const message = response?.message || "Withdrawal request sent";
|
|
@@ -1898,35 +2008,27 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1898
2008
|
* console.log("Chains:", user.user.chains);
|
|
1899
2009
|
* ```
|
|
1900
2010
|
*/
|
|
1901
|
-
async getUserDetails() {
|
|
2011
|
+
async getUserDetails(asset = "usdc") {
|
|
1902
2012
|
try {
|
|
1903
2013
|
await this.authenticateUser();
|
|
1904
2014
|
const response = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
1905
2015
|
const convertedResponse = convertStrategyToPublic(response);
|
|
1906
2016
|
return {
|
|
1907
2017
|
success: true,
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
crosschainStrategy: convertedResponse.crosschainStrategy,
|
|
1923
|
-
agentName: convertedResponse.agentName,
|
|
1924
|
-
customization: convertedResponse.customization,
|
|
1925
|
-
executorProxy: convertedResponse.executorProxy,
|
|
1926
|
-
splitting: convertedResponse.splitting,
|
|
1927
|
-
minSplits: convertedResponse.minSplits,
|
|
1928
|
-
registered: convertedResponse.registered
|
|
1929
|
-
}
|
|
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
|
|
1930
2032
|
};
|
|
1931
2033
|
} catch (error) {
|
|
1932
2034
|
throw new Error(
|
|
@@ -1951,18 +2053,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1951
2053
|
async getTVL() {
|
|
1952
2054
|
try {
|
|
1953
2055
|
const response = await this.httpClient.get(ENDPOINTS.DATA_TVL);
|
|
1954
|
-
const byChain = {};
|
|
1955
|
-
for (const key of Object.keys(response)) {
|
|
1956
|
-
const numKey = parseInt(key, 10);
|
|
1957
|
-
if (!isNaN(numKey) && typeof response[key] === "number") {
|
|
1958
|
-
byChain[numKey] = response[key];
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
2056
|
return {
|
|
1962
2057
|
success: true,
|
|
1963
|
-
totalTvl: response.total ||
|
|
1964
|
-
byChain,
|
|
1965
|
-
breakdown: response.breakdown
|
|
2058
|
+
totalTvl: response.total || 0
|
|
1966
2059
|
};
|
|
1967
2060
|
} catch (error) {
|
|
1968
2061
|
throw new Error(`Failed to get TVL: ${error.message}`);
|
|
@@ -1977,20 +2070,28 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1977
2070
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
1978
2071
|
* @param days - Time period: 7, 14, or 30
|
|
1979
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")
|
|
1980
2075
|
* @returns APY per strategy for a specific chain
|
|
1981
2076
|
*
|
|
1982
2077
|
* @example
|
|
1983
2078
|
* ```typescript
|
|
1984
|
-
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
2079
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative", 8453, "USDC");
|
|
1985
2080
|
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
1986
2081
|
* ```
|
|
1987
2082
|
*/
|
|
1988
|
-
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative") {
|
|
2083
|
+
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative", chainId, tokenSymbol) {
|
|
1989
2084
|
try {
|
|
1990
2085
|
const internalStrategy = toInternalStrategy(strategy);
|
|
1991
2086
|
const internalStrategyShort = internalStrategy === "safe_strategy" ? "safe" : "degen";
|
|
1992
2087
|
const response = await this.httpClient.dataGet(
|
|
1993
|
-
DATA_ENDPOINTS.APY_PER_STRATEGY(
|
|
2088
|
+
DATA_ENDPOINTS.APY_PER_STRATEGY({
|
|
2089
|
+
isCrossChain: crossChain,
|
|
2090
|
+
days,
|
|
2091
|
+
strategy: internalStrategyShort,
|
|
2092
|
+
chainId,
|
|
2093
|
+
tokenSymbol
|
|
2094
|
+
})
|
|
1994
2095
|
);
|
|
1995
2096
|
const convertedData = convertStrategiesToPublicAndNaming(
|
|
1996
2097
|
response.data || []
|
|
@@ -2017,9 +2118,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2017
2118
|
* console.log("Total Volume:", volume.volumeInUSD);
|
|
2018
2119
|
* ```
|
|
2019
2120
|
*/
|
|
2020
|
-
async getVolume() {
|
|
2121
|
+
async getVolume(assetType = "usdc") {
|
|
2021
2122
|
try {
|
|
2022
|
-
const response = await this.httpClient.get(ENDPOINTS.DATA_VOLUME);
|
|
2123
|
+
const response = await this.httpClient.get(ENDPOINTS.DATA_VOLUME(assetType));
|
|
2023
2124
|
return {
|
|
2024
2125
|
success: true,
|
|
2025
2126
|
volumeInUSD: response.volumeInUSD || "0"
|
|
@@ -2186,12 +2287,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2186
2287
|
* Get onchain earnings for a wallet
|
|
2187
2288
|
*
|
|
2188
2289
|
* @param walletAddress - Smart wallet address
|
|
2189
|
-
* @returns Onchain earnings data
|
|
2290
|
+
* @returns Onchain earnings data with per-token breakdowns
|
|
2190
2291
|
*
|
|
2191
2292
|
* @example
|
|
2192
2293
|
* ```typescript
|
|
2193
2294
|
* const earnings = await sdk.getOnchainEarnings("0x...");
|
|
2194
|
-
* console.log("Total
|
|
2295
|
+
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
2195
2296
|
* ```
|
|
2196
2297
|
*/
|
|
2197
2298
|
async getOnchainEarnings(walletAddress) {
|
|
@@ -2206,13 +2307,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2206
2307
|
success: true,
|
|
2207
2308
|
data: {
|
|
2208
2309
|
walletAddress,
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
unrealizedEarnings: response.unrealized_earnings,
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
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
|
|
2216
2316
|
}
|
|
2217
2317
|
};
|
|
2218
2318
|
} catch (error) {
|
|
@@ -2226,12 +2326,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2226
2326
|
* This triggers a recalculation of earnings on the backend
|
|
2227
2327
|
*
|
|
2228
2328
|
* @param walletAddress - Smart wallet address
|
|
2229
|
-
* @returns Updated onchain earnings data
|
|
2329
|
+
* @returns Updated onchain earnings data with per-token breakdowns
|
|
2230
2330
|
*
|
|
2231
2331
|
* @example
|
|
2232
2332
|
* ```typescript
|
|
2233
2333
|
* const earnings = await sdk.calculateOnchainEarnings("0x...");
|
|
2234
|
-
* console.log("
|
|
2334
|
+
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
2235
2335
|
* ```
|
|
2236
2336
|
*/
|
|
2237
2337
|
async calculateOnchainEarnings(walletAddress) {
|
|
@@ -2248,11 +2348,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2248
2348
|
success: true,
|
|
2249
2349
|
data: {
|
|
2250
2350
|
walletAddress,
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
unrealizedEarnings: data.unrealized_earnings,
|
|
2255
|
-
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
|
|
2256
2357
|
}
|
|
2257
2358
|
};
|
|
2258
2359
|
} catch (error) {
|
|
@@ -2272,7 +2373,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2272
2373
|
* @example
|
|
2273
2374
|
* ```typescript
|
|
2274
2375
|
* const daily = await sdk.getDailyEarnings("0x...", "2024-01-01", "2024-01-31");
|
|
2275
|
-
* daily.data.forEach(d => console.log(d.
|
|
2376
|
+
* daily.data.forEach(d => console.log(d.snapshot_date, d.total_earnings_by_token));
|
|
2276
2377
|
* ```
|
|
2277
2378
|
*/
|
|
2278
2379
|
async getDailyEarnings(walletAddress, startDate, endDate) {
|
|
@@ -2300,61 +2401,25 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2300
2401
|
}
|
|
2301
2402
|
}
|
|
2302
2403
|
// ============================================================================
|
|
2303
|
-
// Portfolio Methods (Data API v2)
|
|
2304
|
-
// ============================================================================
|
|
2305
|
-
/**
|
|
2306
|
-
* Get Debank portfolio for a wallet across multiple chains
|
|
2307
|
-
* Note: This is a paid endpoint and may require authorization
|
|
2308
|
-
*
|
|
2309
|
-
* @param walletAddress - Smart wallet address
|
|
2310
|
-
* @returns Multi-chain portfolio data
|
|
2311
|
-
*
|
|
2312
|
-
* @example
|
|
2313
|
-
* ```typescript
|
|
2314
|
-
* const portfolio = await sdk.getDebankPortfolio("0x...");
|
|
2315
|
-
* console.log("Total value:", portfolio.totalValueUsd);
|
|
2316
|
-
* ```
|
|
2317
|
-
*/
|
|
2318
|
-
async getDebankPortfolio(walletAddress) {
|
|
2319
|
-
try {
|
|
2320
|
-
if (!walletAddress) {
|
|
2321
|
-
throw new Error("Wallet address is required");
|
|
2322
|
-
}
|
|
2323
|
-
const response = await this.httpClient.dataGet(
|
|
2324
|
-
DATA_ENDPOINTS.DEBANK_PORTFOLIO_MULTICHAIN(walletAddress)
|
|
2325
|
-
);
|
|
2326
|
-
const data = response.data || response;
|
|
2327
|
-
return {
|
|
2328
|
-
success: true,
|
|
2329
|
-
walletAddress,
|
|
2330
|
-
totalValueUsd: data.totalValueUsd || 0,
|
|
2331
|
-
chains: data.chains || data
|
|
2332
|
-
};
|
|
2333
|
-
} catch (error) {
|
|
2334
|
-
throw new Error(
|
|
2335
|
-
`Failed to get Debank portfolio: ${error.message}`
|
|
2336
|
-
);
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
// ============================================================================
|
|
2340
2404
|
// Opportunities Methods (Data API v2)
|
|
2341
2405
|
// ============================================================================
|
|
2342
2406
|
/**
|
|
2343
2407
|
* Get conservative (low-risk) yield opportunities
|
|
2344
2408
|
*
|
|
2345
2409
|
* @param chainId - Optional chain ID filter
|
|
2410
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2346
2411
|
* @returns List of conservative yield opportunities
|
|
2347
2412
|
*
|
|
2348
2413
|
* @example
|
|
2349
2414
|
* ```typescript
|
|
2350
|
-
* const opportunities = await sdk.getConservativeOpportunities(8453);
|
|
2415
|
+
* const opportunities = await sdk.getConservativeOpportunities(8453, "USDC");
|
|
2351
2416
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2352
2417
|
* ```
|
|
2353
2418
|
*/
|
|
2354
|
-
async getConservativeOpportunities(chainId) {
|
|
2419
|
+
async getConservativeOpportunities(chainId, asset, status) {
|
|
2355
2420
|
try {
|
|
2356
2421
|
const response = await this.httpClient.dataGet(
|
|
2357
|
-
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
2422
|
+
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId, asset, status)
|
|
2358
2423
|
);
|
|
2359
2424
|
const data = response.data || response || [];
|
|
2360
2425
|
return {
|
|
@@ -2367,7 +2432,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2367
2432
|
protocolName: o.protocol_name || o.protocolName,
|
|
2368
2433
|
poolName: o.pool_name || o.poolName,
|
|
2369
2434
|
chainId: o.chain_id || o.chainId,
|
|
2370
|
-
apy: o.
|
|
2435
|
+
apy: o.combined_apy || 0,
|
|
2371
2436
|
tvl: o.tvl || o.zyfiTvl,
|
|
2372
2437
|
asset: o.asset || o.underlying_token,
|
|
2373
2438
|
risk: o.risk,
|
|
@@ -2385,18 +2450,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2385
2450
|
* Get aggressive (high-risk, high-reward) yield opportunities
|
|
2386
2451
|
*
|
|
2387
2452
|
* @param chainId - Optional chain ID filter
|
|
2453
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2388
2454
|
* @returns List of aggressive opportunities
|
|
2389
2455
|
*
|
|
2390
2456
|
* @example
|
|
2391
2457
|
* ```typescript
|
|
2392
|
-
* const opportunities = await sdk.getAggressiveOpportunities(8453);
|
|
2458
|
+
* const opportunities = await sdk.getAggressiveOpportunities(8453, "WETH");
|
|
2393
2459
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2394
2460
|
* ```
|
|
2395
2461
|
*/
|
|
2396
|
-
async getAggressiveOpportunities(chainId) {
|
|
2462
|
+
async getAggressiveOpportunities(chainId, asset, status) {
|
|
2397
2463
|
try {
|
|
2398
2464
|
const response = await this.httpClient.dataGet(
|
|
2399
|
-
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
|
2465
|
+
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset, status)
|
|
2400
2466
|
);
|
|
2401
2467
|
const data = response.data || response || [];
|
|
2402
2468
|
return {
|
|
@@ -2409,7 +2475,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2409
2475
|
protocolName: o.protocol_name || o.protocolName,
|
|
2410
2476
|
poolName: o.pool_name || o.poolName,
|
|
2411
2477
|
chainId: o.chain_id || o.chainId,
|
|
2412
|
-
apy: o.
|
|
2478
|
+
apy: o.combined_apy || 0,
|
|
2413
2479
|
tvl: o.tvl || o.zyfiTvl,
|
|
2414
2480
|
asset: o.asset || o.underlying_token,
|
|
2415
2481
|
risk: o.risk,
|
|
@@ -2428,6 +2494,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2428
2494
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
2429
2495
|
*
|
|
2430
2496
|
* @param chainId - Optional chain ID filter
|
|
2497
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2431
2498
|
* @returns Active conservative opportunities with risk data
|
|
2432
2499
|
*
|
|
2433
2500
|
* @example
|
|
@@ -2436,10 +2503,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2436
2503
|
* console.log(JSON.stringify(opps, null, 2));
|
|
2437
2504
|
* ```
|
|
2438
2505
|
*/
|
|
2439
|
-
async getActiveConservativeOppsRisk(chainId) {
|
|
2506
|
+
async getActiveConservativeOppsRisk(chainId, asset) {
|
|
2440
2507
|
try {
|
|
2441
2508
|
const response = await this.httpClient.dataGet(
|
|
2442
|
-
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
2509
|
+
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId, asset)
|
|
2443
2510
|
);
|
|
2444
2511
|
const data = response.data || response || [];
|
|
2445
2512
|
const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
|
|
@@ -2473,6 +2540,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2473
2540
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
2474
2541
|
*
|
|
2475
2542
|
* @param chainId - Optional chain ID filter
|
|
2543
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2476
2544
|
* @returns Active aggressive opportunities with risk data
|
|
2477
2545
|
*
|
|
2478
2546
|
* @example
|
|
@@ -2481,10 +2549,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2481
2549
|
* console.log(JSON.stringify(opps, null, 2));
|
|
2482
2550
|
* ```
|
|
2483
2551
|
*/
|
|
2484
|
-
async getActiveAggressiveOppsRisk(chainId) {
|
|
2552
|
+
async getActiveAggressiveOppsRisk(chainId, asset) {
|
|
2485
2553
|
try {
|
|
2486
2554
|
const response = await this.httpClient.dataGet(
|
|
2487
|
-
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
|
2555
|
+
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset)
|
|
2488
2556
|
);
|
|
2489
2557
|
const data = response.data || response || [];
|
|
2490
2558
|
const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
|
|
@@ -2518,10 +2586,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2518
2586
|
* Builds on getActiveConservativeOppsRisk and computes higher-level status indicators
|
|
2519
2587
|
*
|
|
2520
2588
|
* @param chainId - Optional chain ID filter
|
|
2589
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2521
2590
|
* @returns Conservative pools with status data
|
|
2522
2591
|
*/
|
|
2523
|
-
async getConservativePoolStatus(chainId) {
|
|
2524
|
-
const pools = await this.getActiveConservativeOppsRisk(chainId);
|
|
2592
|
+
async getConservativePoolStatus(chainId, asset) {
|
|
2593
|
+
const pools = await this.getActiveConservativeOppsRisk(chainId, asset);
|
|
2525
2594
|
return pools.map((p) => this.derivePoolStatus(p));
|
|
2526
2595
|
}
|
|
2527
2596
|
/**
|
|
@@ -2529,10 +2598,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2529
2598
|
* Builds on getActiveAggressiveOppsRisk and computes higher-level status indicators
|
|
2530
2599
|
*
|
|
2531
2600
|
* @param chainId - Optional chain ID filter
|
|
2601
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2532
2602
|
* @returns Aggressive pools with status data
|
|
2533
2603
|
*/
|
|
2534
|
-
async getAggressivePoolStatus(chainId) {
|
|
2535
|
-
const pools = await this.getActiveAggressiveOppsRisk(chainId);
|
|
2604
|
+
async getAggressivePoolStatus(chainId, asset) {
|
|
2605
|
+
const pools = await this.getActiveAggressiveOppsRisk(chainId, asset);
|
|
2536
2606
|
return pools.map((p) => this.derivePoolStatus(p));
|
|
2537
2607
|
}
|
|
2538
2608
|
derivePoolStatus(p) {
|
|
@@ -2581,12 +2651,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2581
2651
|
*
|
|
2582
2652
|
* @param walletAddress - Smart wallet address
|
|
2583
2653
|
* @param days - Period: "7D", "14D", or "30D" (default: "7D")
|
|
2584
|
-
* @returns Daily APY history with weighted averages
|
|
2654
|
+
* @returns Daily APY history with per-position breakdowns and weighted averages
|
|
2585
2655
|
*
|
|
2586
2656
|
* @example
|
|
2587
2657
|
* ```typescript
|
|
2588
2658
|
* const apyHistory = await sdk.getDailyApyHistory("0x...", "30D");
|
|
2589
|
-
* console.log("
|
|
2659
|
+
* console.log("Weighted APY after fee:", apyHistory.weightedApyAfterFee); // { "USDC": 4.64, "WETH": 1.94 }
|
|
2590
2660
|
* ```
|
|
2591
2661
|
*/
|
|
2592
2662
|
async getDailyApyHistory(walletAddress, days = "7D") {
|