@zyfai/sdk 0.2.0 → 0.2.2
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 +7 -7
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +61 -26
- package/dist/index.mjs +61 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -578,21 +578,21 @@ console.log("Average Weighted APY:", apyHistory.averageWeightedApy);
|
|
|
578
578
|
|
|
579
579
|
### 10. Opportunities & Strategies
|
|
580
580
|
|
|
581
|
-
#### Get
|
|
581
|
+
#### Get Conservative Opportunities (Low Risk)
|
|
582
582
|
|
|
583
583
|
```typescript
|
|
584
|
-
const
|
|
585
|
-
|
|
584
|
+
const conservativeOpps = await sdk.getConservativeOpportunities(8453);
|
|
585
|
+
conservativeOpps.data.forEach((o) => {
|
|
586
586
|
console.log(`${o.protocolName} - ${o.poolName}: ${o.apy}% APY`);
|
|
587
587
|
});
|
|
588
588
|
```
|
|
589
589
|
|
|
590
|
-
#### Get
|
|
590
|
+
#### Get Aggressive Opportunities (High Risk)
|
|
591
591
|
|
|
592
592
|
```typescript
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
console.log(`${
|
|
593
|
+
const aggressiveOpps = await sdk.getAggressiveOpportunities(8453);
|
|
594
|
+
aggressiveOpps.data.forEach((o) => {
|
|
595
|
+
console.log(`${o.protocolName} - ${o.poolName}: ${o.apy}% APY`);
|
|
596
596
|
});
|
|
597
597
|
```
|
|
598
598
|
|
package/dist/index.d.mts
CHANGED
|
@@ -823,24 +823,24 @@ declare class ZyfaiSDK {
|
|
|
823
823
|
*
|
|
824
824
|
* @example
|
|
825
825
|
* ```typescript
|
|
826
|
-
* const opportunities = await sdk.
|
|
826
|
+
* const opportunities = await sdk.getConservativeOpportunities(8453);
|
|
827
827
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
828
828
|
* ```
|
|
829
829
|
*/
|
|
830
|
-
|
|
830
|
+
getConservativeOpportunities(chainId?: number): Promise<OpportunitiesResponse>;
|
|
831
831
|
/**
|
|
832
|
-
* Get aggressive (high-risk, high-reward) yield
|
|
832
|
+
* Get aggressive (high-risk, high-reward) yield opportunities
|
|
833
833
|
*
|
|
834
834
|
* @param chainId - Optional chain ID filter
|
|
835
|
-
* @returns List of aggressive
|
|
835
|
+
* @returns List of aggressive opportunities
|
|
836
836
|
*
|
|
837
837
|
* @example
|
|
838
838
|
* ```typescript
|
|
839
|
-
* const
|
|
840
|
-
*
|
|
839
|
+
* const opportunities = await sdk.getAggressiveOpportunities(8453);
|
|
840
|
+
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
841
841
|
* ```
|
|
842
842
|
*/
|
|
843
|
-
|
|
843
|
+
getAggressiveOpportunities(chainId?: number): Promise<OpportunitiesResponse>;
|
|
844
844
|
/**
|
|
845
845
|
* Get daily APY history with weighted average for a wallet
|
|
846
846
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -823,24 +823,24 @@ declare class ZyfaiSDK {
|
|
|
823
823
|
*
|
|
824
824
|
* @example
|
|
825
825
|
* ```typescript
|
|
826
|
-
* const opportunities = await sdk.
|
|
826
|
+
* const opportunities = await sdk.getConservativeOpportunities(8453);
|
|
827
827
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
828
828
|
* ```
|
|
829
829
|
*/
|
|
830
|
-
|
|
830
|
+
getConservativeOpportunities(chainId?: number): Promise<OpportunitiesResponse>;
|
|
831
831
|
/**
|
|
832
|
-
* Get aggressive (high-risk, high-reward) yield
|
|
832
|
+
* Get aggressive (high-risk, high-reward) yield opportunities
|
|
833
833
|
*
|
|
834
834
|
* @param chainId - Optional chain ID filter
|
|
835
|
-
* @returns List of aggressive
|
|
835
|
+
* @returns List of aggressive opportunities
|
|
836
836
|
*
|
|
837
837
|
* @example
|
|
838
838
|
* ```typescript
|
|
839
|
-
* const
|
|
840
|
-
*
|
|
839
|
+
* const opportunities = await sdk.getAggressiveOpportunities(8453);
|
|
840
|
+
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
841
841
|
* ```
|
|
842
842
|
*/
|
|
843
|
-
|
|
843
|
+
getAggressiveOpportunities(chainId?: number): Promise<OpportunitiesResponse>;
|
|
844
844
|
/**
|
|
845
845
|
* Get daily APY history with weighted average for a wallet
|
|
846
846
|
*
|
package/dist/index.js
CHANGED
|
@@ -637,6 +637,35 @@ function toInternalStrategy(publicStrategy) {
|
|
|
637
637
|
);
|
|
638
638
|
}
|
|
639
639
|
}
|
|
640
|
+
function toPublicStrategy(internalStrategy) {
|
|
641
|
+
if (internalStrategy === "safe_strategy" || internalStrategy === "safe") {
|
|
642
|
+
return "conservative";
|
|
643
|
+
}
|
|
644
|
+
if (internalStrategy === "degen_strategy" || internalStrategy === "degen") {
|
|
645
|
+
return "aggressive";
|
|
646
|
+
}
|
|
647
|
+
throw new Error(
|
|
648
|
+
`Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy" or "degen_strategy".`
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
function convertStrategyToPublic(obj) {
|
|
652
|
+
if (!obj.strategy) {
|
|
653
|
+
return obj;
|
|
654
|
+
}
|
|
655
|
+
try {
|
|
656
|
+
return {
|
|
657
|
+
...obj,
|
|
658
|
+
strategy: toPublicStrategy(
|
|
659
|
+
obj.strategy
|
|
660
|
+
)
|
|
661
|
+
};
|
|
662
|
+
} catch {
|
|
663
|
+
return obj;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function convertStrategiesToPublic(array) {
|
|
667
|
+
return array.map((item) => convertStrategyToPublic(item));
|
|
668
|
+
}
|
|
640
669
|
|
|
641
670
|
// src/core/ZyfaiSDK.ts
|
|
642
671
|
var import_siwe = require("siwe");
|
|
@@ -1538,10 +1567,11 @@ var ZyfaiSDK = class {
|
|
|
1538
1567
|
const response = await this.httpClient.get(
|
|
1539
1568
|
ENDPOINTS.DATA_POSITION(smartWalletInfo.smartWallet)
|
|
1540
1569
|
);
|
|
1570
|
+
const convertedPositions = response ? [convertStrategyToPublic(response)] : [];
|
|
1541
1571
|
return {
|
|
1542
1572
|
success: true,
|
|
1543
1573
|
userAddress,
|
|
1544
|
-
positions:
|
|
1574
|
+
positions: convertedPositions
|
|
1545
1575
|
};
|
|
1546
1576
|
} catch (error) {
|
|
1547
1577
|
throw new Error(`Failed to get positions: ${error.message}`);
|
|
@@ -1568,25 +1598,26 @@ var ZyfaiSDK = class {
|
|
|
1568
1598
|
try {
|
|
1569
1599
|
await this.authenticateUser();
|
|
1570
1600
|
const response = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
1601
|
+
const convertedResponse = convertStrategyToPublic(response);
|
|
1571
1602
|
return {
|
|
1572
1603
|
success: true,
|
|
1573
1604
|
user: {
|
|
1574
|
-
id:
|
|
1575
|
-
address:
|
|
1576
|
-
smartWallet:
|
|
1577
|
-
chains:
|
|
1578
|
-
protocols:
|
|
1579
|
-
hasActiveSessionKey:
|
|
1580
|
-
email:
|
|
1581
|
-
strategy:
|
|
1582
|
-
telegramId:
|
|
1583
|
-
walletType:
|
|
1584
|
-
autoSelectProtocols:
|
|
1585
|
-
autocompounding:
|
|
1586
|
-
omniAccount:
|
|
1587
|
-
crosschainStrategy:
|
|
1588
|
-
agentName:
|
|
1589
|
-
customization:
|
|
1605
|
+
id: convertedResponse.id,
|
|
1606
|
+
address: convertedResponse.address,
|
|
1607
|
+
smartWallet: convertedResponse.smartWallet,
|
|
1608
|
+
chains: convertedResponse.chains || [],
|
|
1609
|
+
protocols: convertedResponse.protocols || [],
|
|
1610
|
+
hasActiveSessionKey: convertedResponse.hasActiveSessionKey || false,
|
|
1611
|
+
email: convertedResponse.email,
|
|
1612
|
+
strategy: convertedResponse.strategy,
|
|
1613
|
+
telegramId: convertedResponse.telegramId,
|
|
1614
|
+
walletType: convertedResponse.walletType,
|
|
1615
|
+
autoSelectProtocols: convertedResponse.autoSelectProtocols || false,
|
|
1616
|
+
autocompounding: convertedResponse.autocompounding,
|
|
1617
|
+
omniAccount: convertedResponse.omniAccount,
|
|
1618
|
+
crosschainStrategy: convertedResponse.crosschainStrategy,
|
|
1619
|
+
agentName: convertedResponse.agentName,
|
|
1620
|
+
customization: convertedResponse.customization
|
|
1590
1621
|
}
|
|
1591
1622
|
};
|
|
1592
1623
|
} catch (error) {
|
|
@@ -1653,10 +1684,13 @@ var ZyfaiSDK = class {
|
|
|
1653
1684
|
const response = await this.httpClient.dataGet(
|
|
1654
1685
|
DATA_ENDPOINTS.APY_PER_STRATEGY(crossChain, days, internalStrategyShort)
|
|
1655
1686
|
);
|
|
1687
|
+
const convertedData = convertStrategiesToPublic(
|
|
1688
|
+
response.data || []
|
|
1689
|
+
);
|
|
1656
1690
|
return {
|
|
1657
1691
|
success: true,
|
|
1658
1692
|
count: response.count || 0,
|
|
1659
|
-
data:
|
|
1693
|
+
data: convertedData
|
|
1660
1694
|
};
|
|
1661
1695
|
} catch (error) {
|
|
1662
1696
|
throw new Error(
|
|
@@ -1826,10 +1860,11 @@ var ZyfaiSDK = class {
|
|
|
1826
1860
|
if (options?.fromDate) endpoint += `&fromDate=${options.fromDate}`;
|
|
1827
1861
|
if (options?.toDate) endpoint += `&toDate=${options.toDate}`;
|
|
1828
1862
|
const response = await this.httpClient.get(endpoint);
|
|
1863
|
+
const convertedData = convertStrategiesToPublic(response.data || []);
|
|
1829
1864
|
return {
|
|
1830
1865
|
success: true,
|
|
1831
1866
|
walletAddress,
|
|
1832
|
-
data:
|
|
1867
|
+
data: convertedData,
|
|
1833
1868
|
total: response.total || 0
|
|
1834
1869
|
};
|
|
1835
1870
|
} catch (error) {
|
|
@@ -2004,11 +2039,11 @@ var ZyfaiSDK = class {
|
|
|
2004
2039
|
*
|
|
2005
2040
|
* @example
|
|
2006
2041
|
* ```typescript
|
|
2007
|
-
* const opportunities = await sdk.
|
|
2042
|
+
* const opportunities = await sdk.getConservativeOpportunities(8453);
|
|
2008
2043
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2009
2044
|
* ```
|
|
2010
2045
|
*/
|
|
2011
|
-
async
|
|
2046
|
+
async getConservativeOpportunities(chainId) {
|
|
2012
2047
|
try {
|
|
2013
2048
|
const response = await this.httpClient.dataGet(
|
|
2014
2049
|
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
@@ -2039,18 +2074,18 @@ var ZyfaiSDK = class {
|
|
|
2039
2074
|
}
|
|
2040
2075
|
}
|
|
2041
2076
|
/**
|
|
2042
|
-
* Get aggressive (high-risk, high-reward) yield
|
|
2077
|
+
* Get aggressive (high-risk, high-reward) yield opportunities
|
|
2043
2078
|
*
|
|
2044
2079
|
* @param chainId - Optional chain ID filter
|
|
2045
|
-
* @returns List of aggressive
|
|
2080
|
+
* @returns List of aggressive opportunities
|
|
2046
2081
|
*
|
|
2047
2082
|
* @example
|
|
2048
2083
|
* ```typescript
|
|
2049
|
-
* const
|
|
2050
|
-
*
|
|
2084
|
+
* const opportunities = await sdk.getAggressiveOpportunities(8453);
|
|
2085
|
+
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2051
2086
|
* ```
|
|
2052
2087
|
*/
|
|
2053
|
-
async
|
|
2088
|
+
async getAggressiveOpportunities(chainId) {
|
|
2054
2089
|
try {
|
|
2055
2090
|
const response = await this.httpClient.dataGet(
|
|
2056
2091
|
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
package/dist/index.mjs
CHANGED
|
@@ -614,6 +614,35 @@ function toInternalStrategy(publicStrategy) {
|
|
|
614
614
|
);
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
|
+
function toPublicStrategy(internalStrategy) {
|
|
618
|
+
if (internalStrategy === "safe_strategy" || internalStrategy === "safe") {
|
|
619
|
+
return "conservative";
|
|
620
|
+
}
|
|
621
|
+
if (internalStrategy === "degen_strategy" || internalStrategy === "degen") {
|
|
622
|
+
return "aggressive";
|
|
623
|
+
}
|
|
624
|
+
throw new Error(
|
|
625
|
+
`Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy" or "degen_strategy".`
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
function convertStrategyToPublic(obj) {
|
|
629
|
+
if (!obj.strategy) {
|
|
630
|
+
return obj;
|
|
631
|
+
}
|
|
632
|
+
try {
|
|
633
|
+
return {
|
|
634
|
+
...obj,
|
|
635
|
+
strategy: toPublicStrategy(
|
|
636
|
+
obj.strategy
|
|
637
|
+
)
|
|
638
|
+
};
|
|
639
|
+
} catch {
|
|
640
|
+
return obj;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
function convertStrategiesToPublic(array) {
|
|
644
|
+
return array.map((item) => convertStrategyToPublic(item));
|
|
645
|
+
}
|
|
617
646
|
|
|
618
647
|
// src/core/ZyfaiSDK.ts
|
|
619
648
|
import { SiweMessage } from "siwe";
|
|
@@ -1515,10 +1544,11 @@ var ZyfaiSDK = class {
|
|
|
1515
1544
|
const response = await this.httpClient.get(
|
|
1516
1545
|
ENDPOINTS.DATA_POSITION(smartWalletInfo.smartWallet)
|
|
1517
1546
|
);
|
|
1547
|
+
const convertedPositions = response ? [convertStrategyToPublic(response)] : [];
|
|
1518
1548
|
return {
|
|
1519
1549
|
success: true,
|
|
1520
1550
|
userAddress,
|
|
1521
|
-
positions:
|
|
1551
|
+
positions: convertedPositions
|
|
1522
1552
|
};
|
|
1523
1553
|
} catch (error) {
|
|
1524
1554
|
throw new Error(`Failed to get positions: ${error.message}`);
|
|
@@ -1545,25 +1575,26 @@ var ZyfaiSDK = class {
|
|
|
1545
1575
|
try {
|
|
1546
1576
|
await this.authenticateUser();
|
|
1547
1577
|
const response = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
1578
|
+
const convertedResponse = convertStrategyToPublic(response);
|
|
1548
1579
|
return {
|
|
1549
1580
|
success: true,
|
|
1550
1581
|
user: {
|
|
1551
|
-
id:
|
|
1552
|
-
address:
|
|
1553
|
-
smartWallet:
|
|
1554
|
-
chains:
|
|
1555
|
-
protocols:
|
|
1556
|
-
hasActiveSessionKey:
|
|
1557
|
-
email:
|
|
1558
|
-
strategy:
|
|
1559
|
-
telegramId:
|
|
1560
|
-
walletType:
|
|
1561
|
-
autoSelectProtocols:
|
|
1562
|
-
autocompounding:
|
|
1563
|
-
omniAccount:
|
|
1564
|
-
crosschainStrategy:
|
|
1565
|
-
agentName:
|
|
1566
|
-
customization:
|
|
1582
|
+
id: convertedResponse.id,
|
|
1583
|
+
address: convertedResponse.address,
|
|
1584
|
+
smartWallet: convertedResponse.smartWallet,
|
|
1585
|
+
chains: convertedResponse.chains || [],
|
|
1586
|
+
protocols: convertedResponse.protocols || [],
|
|
1587
|
+
hasActiveSessionKey: convertedResponse.hasActiveSessionKey || false,
|
|
1588
|
+
email: convertedResponse.email,
|
|
1589
|
+
strategy: convertedResponse.strategy,
|
|
1590
|
+
telegramId: convertedResponse.telegramId,
|
|
1591
|
+
walletType: convertedResponse.walletType,
|
|
1592
|
+
autoSelectProtocols: convertedResponse.autoSelectProtocols || false,
|
|
1593
|
+
autocompounding: convertedResponse.autocompounding,
|
|
1594
|
+
omniAccount: convertedResponse.omniAccount,
|
|
1595
|
+
crosschainStrategy: convertedResponse.crosschainStrategy,
|
|
1596
|
+
agentName: convertedResponse.agentName,
|
|
1597
|
+
customization: convertedResponse.customization
|
|
1567
1598
|
}
|
|
1568
1599
|
};
|
|
1569
1600
|
} catch (error) {
|
|
@@ -1630,10 +1661,13 @@ var ZyfaiSDK = class {
|
|
|
1630
1661
|
const response = await this.httpClient.dataGet(
|
|
1631
1662
|
DATA_ENDPOINTS.APY_PER_STRATEGY(crossChain, days, internalStrategyShort)
|
|
1632
1663
|
);
|
|
1664
|
+
const convertedData = convertStrategiesToPublic(
|
|
1665
|
+
response.data || []
|
|
1666
|
+
);
|
|
1633
1667
|
return {
|
|
1634
1668
|
success: true,
|
|
1635
1669
|
count: response.count || 0,
|
|
1636
|
-
data:
|
|
1670
|
+
data: convertedData
|
|
1637
1671
|
};
|
|
1638
1672
|
} catch (error) {
|
|
1639
1673
|
throw new Error(
|
|
@@ -1803,10 +1837,11 @@ var ZyfaiSDK = class {
|
|
|
1803
1837
|
if (options?.fromDate) endpoint += `&fromDate=${options.fromDate}`;
|
|
1804
1838
|
if (options?.toDate) endpoint += `&toDate=${options.toDate}`;
|
|
1805
1839
|
const response = await this.httpClient.get(endpoint);
|
|
1840
|
+
const convertedData = convertStrategiesToPublic(response.data || []);
|
|
1806
1841
|
return {
|
|
1807
1842
|
success: true,
|
|
1808
1843
|
walletAddress,
|
|
1809
|
-
data:
|
|
1844
|
+
data: convertedData,
|
|
1810
1845
|
total: response.total || 0
|
|
1811
1846
|
};
|
|
1812
1847
|
} catch (error) {
|
|
@@ -1981,11 +2016,11 @@ var ZyfaiSDK = class {
|
|
|
1981
2016
|
*
|
|
1982
2017
|
* @example
|
|
1983
2018
|
* ```typescript
|
|
1984
|
-
* const opportunities = await sdk.
|
|
2019
|
+
* const opportunities = await sdk.getConservativeOpportunities(8453);
|
|
1985
2020
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
1986
2021
|
* ```
|
|
1987
2022
|
*/
|
|
1988
|
-
async
|
|
2023
|
+
async getConservativeOpportunities(chainId) {
|
|
1989
2024
|
try {
|
|
1990
2025
|
const response = await this.httpClient.dataGet(
|
|
1991
2026
|
DATA_ENDPOINTS.OPPORTUNITIES_SAFE(chainId)
|
|
@@ -2016,18 +2051,18 @@ var ZyfaiSDK = class {
|
|
|
2016
2051
|
}
|
|
2017
2052
|
}
|
|
2018
2053
|
/**
|
|
2019
|
-
* Get aggressive (high-risk, high-reward) yield
|
|
2054
|
+
* Get aggressive (high-risk, high-reward) yield opportunities
|
|
2020
2055
|
*
|
|
2021
2056
|
* @param chainId - Optional chain ID filter
|
|
2022
|
-
* @returns List of aggressive
|
|
2057
|
+
* @returns List of aggressive opportunities
|
|
2023
2058
|
*
|
|
2024
2059
|
* @example
|
|
2025
2060
|
* ```typescript
|
|
2026
|
-
* const
|
|
2027
|
-
*
|
|
2061
|
+
* const opportunities = await sdk.getAggressiveOpportunities(8453);
|
|
2062
|
+
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
2028
2063
|
* ```
|
|
2029
2064
|
*/
|
|
2030
|
-
async
|
|
2065
|
+
async getAggressiveOpportunities(chainId) {
|
|
2031
2066
|
try {
|
|
2032
2067
|
const response = await this.httpClient.dataGet(
|
|
2033
2068
|
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "TypeScript SDK for Zyfai Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|