@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.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({
|
|
@@ -1718,7 +1825,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1718
1825
|
* );
|
|
1719
1826
|
* ```
|
|
1720
1827
|
*/
|
|
1721
|
-
async withdrawFunds(userAddress, chainId, amount) {
|
|
1828
|
+
async withdrawFunds(userAddress, chainId, amount, tokenSymbol) {
|
|
1722
1829
|
try {
|
|
1723
1830
|
if (!userAddress) {
|
|
1724
1831
|
throw new Error("User address is required");
|
|
@@ -1760,12 +1867,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1760
1867
|
if (amount) {
|
|
1761
1868
|
response = await this.httpClient.post(ENDPOINTS.PARTIAL_WITHDRAW, {
|
|
1762
1869
|
chainId,
|
|
1763
|
-
amount
|
|
1870
|
+
amount,
|
|
1871
|
+
tokenSymbol
|
|
1764
1872
|
});
|
|
1765
1873
|
} else {
|
|
1874
|
+
console.log("Full withdrawal", tokenSymbol);
|
|
1766
1875
|
response = await this.httpClient.get(ENDPOINTS.USER_WITHDRAW, {
|
|
1767
|
-
params: { chainId }
|
|
1876
|
+
params: { chainId, tokenSymbol }
|
|
1768
1877
|
});
|
|
1878
|
+
console.log(JSON.stringify(response, null, 2));
|
|
1769
1879
|
}
|
|
1770
1880
|
const success = response?.success ?? true;
|
|
1771
1881
|
const message = response?.message || "Withdrawal request sent";
|
|
@@ -1876,35 +1986,27 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1876
1986
|
* console.log("Chains:", user.user.chains);
|
|
1877
1987
|
* ```
|
|
1878
1988
|
*/
|
|
1879
|
-
async getUserDetails() {
|
|
1989
|
+
async getUserDetails(asset = "usdc") {
|
|
1880
1990
|
try {
|
|
1881
1991
|
await this.authenticateUser();
|
|
1882
1992
|
const response = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
1883
1993
|
const convertedResponse = convertStrategyToPublic(response);
|
|
1884
1994
|
return {
|
|
1885
1995
|
success: true,
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
crosschainStrategy: convertedResponse.crosschainStrategy,
|
|
1901
|
-
agentName: convertedResponse.agentName,
|
|
1902
|
-
customization: convertedResponse.customization,
|
|
1903
|
-
executorProxy: convertedResponse.executorProxy,
|
|
1904
|
-
splitting: convertedResponse.splitting,
|
|
1905
|
-
minSplits: convertedResponse.minSplits,
|
|
1906
|
-
registered: convertedResponse.registered
|
|
1907
|
-
}
|
|
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
|
|
1908
2010
|
};
|
|
1909
2011
|
} catch (error) {
|
|
1910
2012
|
throw new Error(
|
|
@@ -1929,18 +2031,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1929
2031
|
async getTVL() {
|
|
1930
2032
|
try {
|
|
1931
2033
|
const response = await this.httpClient.get(ENDPOINTS.DATA_TVL);
|
|
1932
|
-
const byChain = {};
|
|
1933
|
-
for (const key of Object.keys(response)) {
|
|
1934
|
-
const numKey = parseInt(key, 10);
|
|
1935
|
-
if (!isNaN(numKey) && typeof response[key] === "number") {
|
|
1936
|
-
byChain[numKey] = response[key];
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
2034
|
return {
|
|
1940
2035
|
success: true,
|
|
1941
|
-
totalTvl: response.total ||
|
|
1942
|
-
byChain,
|
|
1943
|
-
breakdown: response.breakdown
|
|
2036
|
+
totalTvl: response.total || 0
|
|
1944
2037
|
};
|
|
1945
2038
|
} catch (error) {
|
|
1946
2039
|
throw new Error(`Failed to get TVL: ${error.message}`);
|
|
@@ -1955,20 +2048,28 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1955
2048
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
1956
2049
|
* @param days - Time period: 7, 14, or 30
|
|
1957
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")
|
|
1958
2053
|
* @returns APY per strategy for a specific chain
|
|
1959
2054
|
*
|
|
1960
2055
|
* @example
|
|
1961
2056
|
* ```typescript
|
|
1962
|
-
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
2057
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative", 8453, "USDC");
|
|
1963
2058
|
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
1964
2059
|
* ```
|
|
1965
2060
|
*/
|
|
1966
|
-
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative") {
|
|
2061
|
+
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative", chainId, tokenSymbol) {
|
|
1967
2062
|
try {
|
|
1968
2063
|
const internalStrategy = toInternalStrategy(strategy);
|
|
1969
2064
|
const internalStrategyShort = internalStrategy === "safe_strategy" ? "safe" : "degen";
|
|
1970
2065
|
const response = await this.httpClient.dataGet(
|
|
1971
|
-
DATA_ENDPOINTS.APY_PER_STRATEGY(
|
|
2066
|
+
DATA_ENDPOINTS.APY_PER_STRATEGY({
|
|
2067
|
+
isCrossChain: crossChain,
|
|
2068
|
+
days,
|
|
2069
|
+
strategy: internalStrategyShort,
|
|
2070
|
+
chainId,
|
|
2071
|
+
tokenSymbol
|
|
2072
|
+
})
|
|
1972
2073
|
);
|
|
1973
2074
|
const convertedData = convertStrategiesToPublicAndNaming(
|
|
1974
2075
|
response.data || []
|
|
@@ -1995,9 +2096,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1995
2096
|
* console.log("Total Volume:", volume.volumeInUSD);
|
|
1996
2097
|
* ```
|
|
1997
2098
|
*/
|
|
1998
|
-
async getVolume() {
|
|
2099
|
+
async getVolume(assetType = "usdc") {
|
|
1999
2100
|
try {
|
|
2000
|
-
const response = await this.httpClient.get(ENDPOINTS.DATA_VOLUME);
|
|
2101
|
+
const response = await this.httpClient.get(ENDPOINTS.DATA_VOLUME(assetType));
|
|
2001
2102
|
return {
|
|
2002
2103
|
success: true,
|
|
2003
2104
|
volumeInUSD: response.volumeInUSD || "0"
|
|
@@ -2164,12 +2265,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2164
2265
|
* Get onchain earnings for a wallet
|
|
2165
2266
|
*
|
|
2166
2267
|
* @param walletAddress - Smart wallet address
|
|
2167
|
-
* @returns Onchain earnings data
|
|
2268
|
+
* @returns Onchain earnings data with per-token breakdowns
|
|
2168
2269
|
*
|
|
2169
2270
|
* @example
|
|
2170
2271
|
* ```typescript
|
|
2171
2272
|
* const earnings = await sdk.getOnchainEarnings("0x...");
|
|
2172
|
-
* console.log("Total
|
|
2273
|
+
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
2173
2274
|
* ```
|
|
2174
2275
|
*/
|
|
2175
2276
|
async getOnchainEarnings(walletAddress) {
|
|
@@ -2184,13 +2285,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2184
2285
|
success: true,
|
|
2185
2286
|
data: {
|
|
2186
2287
|
walletAddress,
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
unrealizedEarnings: response.unrealized_earnings,
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
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
|
|
2194
2294
|
}
|
|
2195
2295
|
};
|
|
2196
2296
|
} catch (error) {
|
|
@@ -2204,12 +2304,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2204
2304
|
* This triggers a recalculation of earnings on the backend
|
|
2205
2305
|
*
|
|
2206
2306
|
* @param walletAddress - Smart wallet address
|
|
2207
|
-
* @returns Updated onchain earnings data
|
|
2307
|
+
* @returns Updated onchain earnings data with per-token breakdowns
|
|
2208
2308
|
*
|
|
2209
2309
|
* @example
|
|
2210
2310
|
* ```typescript
|
|
2211
2311
|
* const earnings = await sdk.calculateOnchainEarnings("0x...");
|
|
2212
|
-
* console.log("
|
|
2312
|
+
* console.log("Total USDC:", earnings.data.totalEarningsByToken["USDC"]);
|
|
2213
2313
|
* ```
|
|
2214
2314
|
*/
|
|
2215
2315
|
async calculateOnchainEarnings(walletAddress) {
|
|
@@ -2226,11 +2326,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2226
2326
|
success: true,
|
|
2227
2327
|
data: {
|
|
2228
2328
|
walletAddress,
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
unrealizedEarnings: data.unrealized_earnings,
|
|
2233
|
-
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
|
|
2234
2335
|
}
|
|
2235
2336
|
};
|
|
2236
2337
|
} catch (error) {
|
|
@@ -2250,7 +2351,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2250
2351
|
* @example
|
|
2251
2352
|
* ```typescript
|
|
2252
2353
|
* const daily = await sdk.getDailyEarnings("0x...", "2024-01-01", "2024-01-31");
|
|
2253
|
-
* daily.data.forEach(d => console.log(d.
|
|
2354
|
+
* daily.data.forEach(d => console.log(d.snapshot_date, d.total_earnings_by_token));
|
|
2254
2355
|
* ```
|
|
2255
2356
|
*/
|
|
2256
2357
|
async getDailyEarnings(walletAddress, startDate, endDate) {
|
|
@@ -2278,61 +2379,25 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2278
2379
|
}
|
|
2279
2380
|
}
|
|
2280
2381
|
// ============================================================================
|
|
2281
|
-
// Portfolio Methods (Data API v2)
|
|
2282
|
-
// ============================================================================
|
|
2283
|
-
/**
|
|
2284
|
-
* Get Debank portfolio for a wallet across multiple chains
|
|
2285
|
-
* Note: This is a paid endpoint and may require authorization
|
|
2286
|
-
*
|
|
2287
|
-
* @param walletAddress - Smart wallet address
|
|
2288
|
-
* @returns Multi-chain portfolio data
|
|
2289
|
-
*
|
|
2290
|
-
* @example
|
|
2291
|
-
* ```typescript
|
|
2292
|
-
* const portfolio = await sdk.getDebankPortfolio("0x...");
|
|
2293
|
-
* console.log("Total value:", portfolio.totalValueUsd);
|
|
2294
|
-
* ```
|
|
2295
|
-
*/
|
|
2296
|
-
async getDebankPortfolio(walletAddress) {
|
|
2297
|
-
try {
|
|
2298
|
-
if (!walletAddress) {
|
|
2299
|
-
throw new Error("Wallet address is required");
|
|
2300
|
-
}
|
|
2301
|
-
const response = await this.httpClient.dataGet(
|
|
2302
|
-
DATA_ENDPOINTS.DEBANK_PORTFOLIO_MULTICHAIN(walletAddress)
|
|
2303
|
-
);
|
|
2304
|
-
const data = response.data || response;
|
|
2305
|
-
return {
|
|
2306
|
-
success: true,
|
|
2307
|
-
walletAddress,
|
|
2308
|
-
totalValueUsd: data.totalValueUsd || 0,
|
|
2309
|
-
chains: data.chains || data
|
|
2310
|
-
};
|
|
2311
|
-
} catch (error) {
|
|
2312
|
-
throw new Error(
|
|
2313
|
-
`Failed to get Debank portfolio: ${error.message}`
|
|
2314
|
-
);
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
|
-
// ============================================================================
|
|
2318
2382
|
// Opportunities Methods (Data API v2)
|
|
2319
2383
|
// ============================================================================
|
|
2320
2384
|
/**
|
|
2321
2385
|
* Get conservative (low-risk) yield opportunities
|
|
2322
2386
|
*
|
|
2323
2387
|
* @param chainId - Optional chain ID filter
|
|
2388
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2324
2389
|
* @returns List of conservative yield opportunities
|
|
2325
2390
|
*
|
|
2326
2391
|
* @example
|
|
2327
2392
|
* ```typescript
|
|
2328
|
-
* const opportunities = await sdk.getConservativeOpportunities(8453);
|
|
2393
|
+
* const opportunities = await sdk.getConservativeOpportunities(8453, "USDC");
|
|
2329
2394
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2330
2395
|
* ```
|
|
2331
2396
|
*/
|
|
2332
|
-
async getConservativeOpportunities(chainId) {
|
|
2397
|
+
async getConservativeOpportunities(chainId, asset, status) {
|
|
2333
2398
|
try {
|
|
2334
2399
|
const response = await this.httpClient.dataGet(
|
|
2335
|
-
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
2400
|
+
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId, asset, status)
|
|
2336
2401
|
);
|
|
2337
2402
|
const data = response.data || response || [];
|
|
2338
2403
|
return {
|
|
@@ -2345,7 +2410,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2345
2410
|
protocolName: o.protocol_name || o.protocolName,
|
|
2346
2411
|
poolName: o.pool_name || o.poolName,
|
|
2347
2412
|
chainId: o.chain_id || o.chainId,
|
|
2348
|
-
apy: o.
|
|
2413
|
+
apy: o.combined_apy || 0,
|
|
2349
2414
|
tvl: o.tvl || o.zyfiTvl,
|
|
2350
2415
|
asset: o.asset || o.underlying_token,
|
|
2351
2416
|
risk: o.risk,
|
|
@@ -2363,18 +2428,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2363
2428
|
* Get aggressive (high-risk, high-reward) yield opportunities
|
|
2364
2429
|
*
|
|
2365
2430
|
* @param chainId - Optional chain ID filter
|
|
2431
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2366
2432
|
* @returns List of aggressive opportunities
|
|
2367
2433
|
*
|
|
2368
2434
|
* @example
|
|
2369
2435
|
* ```typescript
|
|
2370
|
-
* const opportunities = await sdk.getAggressiveOpportunities(8453);
|
|
2436
|
+
* const opportunities = await sdk.getAggressiveOpportunities(8453, "WETH");
|
|
2371
2437
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2372
2438
|
* ```
|
|
2373
2439
|
*/
|
|
2374
|
-
async getAggressiveOpportunities(chainId) {
|
|
2440
|
+
async getAggressiveOpportunities(chainId, asset, status) {
|
|
2375
2441
|
try {
|
|
2376
2442
|
const response = await this.httpClient.dataGet(
|
|
2377
|
-
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
|
2443
|
+
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset, status)
|
|
2378
2444
|
);
|
|
2379
2445
|
const data = response.data || response || [];
|
|
2380
2446
|
return {
|
|
@@ -2387,7 +2453,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2387
2453
|
protocolName: o.protocol_name || o.protocolName,
|
|
2388
2454
|
poolName: o.pool_name || o.poolName,
|
|
2389
2455
|
chainId: o.chain_id || o.chainId,
|
|
2390
|
-
apy: o.
|
|
2456
|
+
apy: o.combined_apy || 0,
|
|
2391
2457
|
tvl: o.tvl || o.zyfiTvl,
|
|
2392
2458
|
asset: o.asset || o.underlying_token,
|
|
2393
2459
|
risk: o.risk,
|
|
@@ -2406,6 +2472,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2406
2472
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
2407
2473
|
*
|
|
2408
2474
|
* @param chainId - Optional chain ID filter
|
|
2475
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2409
2476
|
* @returns Active conservative opportunities with risk data
|
|
2410
2477
|
*
|
|
2411
2478
|
* @example
|
|
@@ -2414,10 +2481,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2414
2481
|
* console.log(JSON.stringify(opps, null, 2));
|
|
2415
2482
|
* ```
|
|
2416
2483
|
*/
|
|
2417
|
-
async getActiveConservativeOppsRisk(chainId) {
|
|
2484
|
+
async getActiveConservativeOppsRisk(chainId, asset) {
|
|
2418
2485
|
try {
|
|
2419
2486
|
const response = await this.httpClient.dataGet(
|
|
2420
|
-
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
2487
|
+
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId, asset)
|
|
2421
2488
|
);
|
|
2422
2489
|
const data = response.data || response || [];
|
|
2423
2490
|
const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
|
|
@@ -2451,6 +2518,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2451
2518
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
2452
2519
|
*
|
|
2453
2520
|
* @param chainId - Optional chain ID filter
|
|
2521
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2454
2522
|
* @returns Active aggressive opportunities with risk data
|
|
2455
2523
|
*
|
|
2456
2524
|
* @example
|
|
@@ -2459,10 +2527,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2459
2527
|
* console.log(JSON.stringify(opps, null, 2));
|
|
2460
2528
|
* ```
|
|
2461
2529
|
*/
|
|
2462
|
-
async getActiveAggressiveOppsRisk(chainId) {
|
|
2530
|
+
async getActiveAggressiveOppsRisk(chainId, asset) {
|
|
2463
2531
|
try {
|
|
2464
2532
|
const response = await this.httpClient.dataGet(
|
|
2465
|
-
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
|
2533
|
+
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset)
|
|
2466
2534
|
);
|
|
2467
2535
|
const data = response.data || response || [];
|
|
2468
2536
|
const active = Array.isArray(data) ? data.filter((o) => o.status === "live").map((o) => {
|
|
@@ -2496,10 +2564,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2496
2564
|
* Builds on getActiveConservativeOppsRisk and computes higher-level status indicators
|
|
2497
2565
|
*
|
|
2498
2566
|
* @param chainId - Optional chain ID filter
|
|
2567
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2499
2568
|
* @returns Conservative pools with status data
|
|
2500
2569
|
*/
|
|
2501
|
-
async getConservativePoolStatus(chainId) {
|
|
2502
|
-
const pools = await this.getActiveConservativeOppsRisk(chainId);
|
|
2570
|
+
async getConservativePoolStatus(chainId, asset) {
|
|
2571
|
+
const pools = await this.getActiveConservativeOppsRisk(chainId, asset);
|
|
2503
2572
|
return pools.map((p) => this.derivePoolStatus(p));
|
|
2504
2573
|
}
|
|
2505
2574
|
/**
|
|
@@ -2507,10 +2576,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2507
2576
|
* Builds on getActiveAggressiveOppsRisk and computes higher-level status indicators
|
|
2508
2577
|
*
|
|
2509
2578
|
* @param chainId - Optional chain ID filter
|
|
2579
|
+
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
2510
2580
|
* @returns Aggressive pools with status data
|
|
2511
2581
|
*/
|
|
2512
|
-
async getAggressivePoolStatus(chainId) {
|
|
2513
|
-
const pools = await this.getActiveAggressiveOppsRisk(chainId);
|
|
2582
|
+
async getAggressivePoolStatus(chainId, asset) {
|
|
2583
|
+
const pools = await this.getActiveAggressiveOppsRisk(chainId, asset);
|
|
2514
2584
|
return pools.map((p) => this.derivePoolStatus(p));
|
|
2515
2585
|
}
|
|
2516
2586
|
derivePoolStatus(p) {
|
|
@@ -2559,12 +2629,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2559
2629
|
*
|
|
2560
2630
|
* @param walletAddress - Smart wallet address
|
|
2561
2631
|
* @param days - Period: "7D", "14D", or "30D" (default: "7D")
|
|
2562
|
-
* @returns Daily APY history with weighted averages
|
|
2632
|
+
* @returns Daily APY history with per-position breakdowns and weighted averages
|
|
2563
2633
|
*
|
|
2564
2634
|
* @example
|
|
2565
2635
|
* ```typescript
|
|
2566
2636
|
* const apyHistory = await sdk.getDailyApyHistory("0x...", "30D");
|
|
2567
|
-
* console.log("
|
|
2637
|
+
* console.log("Weighted APY after fee:", apyHistory.weightedApyAfterFee); // { "USDC": 4.64, "WETH": 1.94 }
|
|
2568
2638
|
* ```
|
|
2569
2639
|
*/
|
|
2570
2640
|
async getDailyApyHistory(walletAddress, days = "7D") {
|